简体   繁体   English

如何将变量动态传递到Google DFP广告管理系统广告代码

[英]How do I pass variables to Google DFP ad tag dinamically

I'm trying to add google ads on my website. 我正在尝试在我的网站上添加google广告。 What I'm trying to do is to pass article name to DFP so it shows ads matched to article name. 我想做的是将商品名称传递给DFP,以便它显示与商品名称匹配的广告。 For example, if I publish a new article with the name "abcdefghi", the value "abcdefghi" should be dynamically passed in the DFP ad tag. 例如,如果我发布一个名称为“ abcdefghi”的新文章,则应在DFP广告管理系统广告代码中动态传递值“ abcdefghi”。

How can I do that? 我怎样才能做到这一点? Any help appriciated! 任何帮助!

You can use setTargeting: 您可以使用setTargeting:

<script>
    var article = 'abcdefghi';

    googletag.cmd.push(function () {
        googletag.pubads().setTargeting('article', article);
    });
</script>

It is a page-level customized targeting, so you can use this to set custom attributes across all ad slots on your page. 这是页面级的自定义定位,因此您可以使用它在页面上所有广告位上设置自定义属性。 This must be execute before googletag.enableServices(). 必须在googletag.enableServices()之前执行。

Don't forget to add the key in the DFP in the inventory Tab. 不要忘记在广告资源标签中的DFP广告管理系统中添加密钥。

More information about key-values: https://support.google.com/dfp_premium/answer/188092 有关键值的更多信息: https : //support.google.com/dfp_premium/answer/188092

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

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