Google DFP: Pass UTM_Source to DFP with javascript (without accessing the DFP Admin)

后端 未结 1 400
有刺的猬
有刺的猬 2020-12-22 11:43

I\'m looking for a way to grab the utm_source value from a URL with javascript and pass it to Google DFP, which doesn\'t involve configuring anything in the DFP Admin (such

相关标签:
1条回答
  • 2020-12-22 12:05

    Use setTargetting. You will need to access the Inventory tab in DFP's dashboard to create the utm code keys (Key-values link)

    <script>
    
        function getParameterByName(name, url) {
            if (!url) url = window.location.href;
            name = name.replace(/[\[\]]/g, "\\$&");
            var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
                results = regex.exec(url);
            if (!results) return null;
            if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\+/g, " "));
        }
    
        googletag.cmd.push(function () {
            googletag.pubads().setTargeting('utm_source', getParameterByName('utm_source'));
        });
    
    </script>
    
    0 讨论(0)
提交回复
热议问题