简体   繁体   中英

How do I pass variables to Google DFP ad tag dinamically

I'm trying to add google ads on my website. What I'm trying to do is to pass article name to DFP so it shows ads matched to article name. For example, if I publish a new article with the name "abcdefghi", the value "abcdefghi" should be dynamically passed in the DFP ad tag.

How can I do that? Any help appriciated!

You can use 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().

Don't forget to add the key in the DFP in the inventory Tab.

More information about key-values: https://support.google.com/dfp_premium/answer/188092

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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