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

拜拜、爱过 提交于 2019-11-28 11:48:59

问题


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 as key-value targeting) as we don't have access to the admin panel for the specific site we are working with.

Would appreciate any tips / javascript code.


回答1:


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>


来源:https://stackoverflow.com/questions/43507594/google-dfp-pass-utm-source-to-dfp-with-javascript-without-accessing-the-dfp-ad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!