Setting Key Values

449 views
Skip to first unread message

Davis Wuolle

unread,
Jun 16, 2017, 10:14:36 PM6/16/17
to Google's DoubleClick for Publishers API Forum
I am trying to set a key-value pair for a post category across all ad positions on the page so we can target that specific category.

Example: https://www.sporttechie.com/what-to-expect-from-mercedes-benz-stadium-technologically/
Category is NFL

The value is being set dynamically in WordPress and I can verify that is happening correctly:

<script type='text/javascript'>
/* <![CDATA[ */
var dfp_vars = {"category":"NFL"};
/* ]]> */
</script>

And the key-value should be fed in with the ad tags on the page:


googletag.cmd.push(function() { googletag.defineSlot('/105597557/rcol-300x250-lower-ros', [300, 250], 'div-gpt-ad-1493060351984-0').addService(googletag.pubads()).setTargeting("cat", dfp_vars.category); googletag.pubads().setTargeting("cat", dfp_vars.category); googletag.pubads().enableSingleRequest(); googletag.pubads().collapseEmptyDivs(); googletag.enableServices(); });

view-source:https://www.sporttechie.com/wp-content/themes/dw-focus/dfp.js?ver=1.0.0

The key-value is setup in DFP but it seems that no impressions are being recorded to category=NFL or any other category. Can anyone lend me some insight here?

Vincent Racaza (DFP API Team)

unread,
Jun 18, 2017, 11:37:14 PM6/18/17
to Google's DoubleClick for Publishers API Forum
Hi Davis,

This seems to be a DFP product related concern. Our team only handles DFP API related issues/concerns. Please post this in the DFP product forums as their team can assist you on this.

Thanks,
Vincent Racaza, DFP API Team

Paul Ehrman

unread,
Dec 21, 2017, 11:12:47 AM12/21/17
to Google's DoubleClick for Publishers API Forum
Here is my solution. Hope it helps somebody.

<!-- THIS GOES IN THE HEAD -->
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
  var googletag = googletag || {};
  googletag.cmd = googletag.cmd || [];
</script>

<script>
<?php $cat = get_category( get_query_var( 'cat' ) ); $cat_slug = $cat->slug; ?>
  googletag.cmd.push(function() {
    googletag.defineSlot('/xxxxxxxx/Leaderboard1', [728, 90], 'div-gpt-ad-XXXXXXXXXXXX-0').setTargeting("category", [<?php echo '"'.$cat_slug.'"'; ?>]).addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
  });
</script>

<!-- THIS IS JUST THE CODE FOR THE WIDGET AREA THAT DFP SPITS OUT -->
<!-- /43436267/PN-Home-Leaderboard-3 -->
<div id='div-gpt-ad-XXXXXXXXXXXX-0' style='height:90px; width:728px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-XXXXXXXXXXXX-0'); });
</script>
</div>

Jc Muller

unread,
Oct 11, 2018, 5:29:33 AM10/11/18
to Google Ad Manager API Forum
Hi Paul THANK YOU!!!! I am going to give that a try.

Just one question I have, will that work for multiple categories let's say it is in the NEWS and SPORT category, will it then pass .setTargeting for all categories or just the first/1?

Thanks again for the solution!

Sreelakshmi Sasidharan (DFP API Team)

unread,
Oct 11, 2018, 1:50:45 PM10/11/18
to Google Ad Manager API Forum
Hello Davis,

As this is not an Ad Manager API specific question, kindly post this in the Ad Manager product forums as their team is better equipped to assist with this. If you have any questions about the Ad Manager API, please feel free to post here.

Thanks,
Sreelakshmi Sasidharan, Ad Manager API Team
Reply all
Reply to author
Forward
0 new messages