简体   繁体   English

Google DFP:使用javascript将UTM_Source传递给DFP(无需访问DFP管理员)

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

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. 我正在寻找一种使用javascript从URL中获取utm_source值并将其传递给Google DFP的方法,该方法不涉及在DFP管理员中配置任何内容(例如键值定位),因为我们无权访问转到我们正在使用的特定站点的管理面板。

Would appreciate any tips / javascript code. 将不胜感激任何提示/ JavaScript代码。

Use setTargetting. 使用setTargetting。 You will need to access the Inventory tab in DFP's dashboard to create the utm code keys ( Key-values link ) 您将需要访问DFP广告管理系统仪表板中的“广告资源”标签,以创建utm代码键( 键值链接

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM