react-gpt icon indicating copy to clipboard operation
react-gpt copied to clipboard

How to set page level key values instead of ad unit level key values?

Open yongzhihuang opened this issue 8 years ago • 9 comments

Hi,

Do you know if there's a way where I can set key values for all ads on a Page level, rather than passing key vals individually to each ad on the page?

from GPT https://support.google.com/dfp_premium/answer/1697712?hl=en:

Slot-level customized targeting: You can set key-value attributes for individual ad slots on your page. Use .setTargeting to utilize slot-level targeting, as in the Google Publisher Tag samples.

Typically, we recommend using slot-level implementation for customized targeting, as it covers all targeting scenarios (both when the key-values is the same throughout the page, and when it varies by individual slots).

Page-level customized targeting: You can use this to set custom attributes across all ad slots on your page. Use googletag.pubads().setTargeting to utilize page-level targeting, as in the Google Publisher Tag samples.

Page-level targeting allows clients to use less code in their tags and ensures that all ad slots have the same set of key-value attributes. For example, clients could set the key-value pair gender=m on all ad slots using page-level customized targeting.

Thanks! Great library!

yongzhihuang avatar Feb 17 '17 18:02 yongzhihuang

@yongzhihuang please see #9

taak77 avatar Feb 17 '17 19:02 taak77

Amazing! Thanks so much @taak77

yongzhihuang avatar Feb 17 '17 19:02 yongzhihuang

Is there a way to set multiple values? GPT.setTargeting(key, value); seems to only set one key,

Should I just loop through a list and calling this over and over? It seems to overwrite previous call at the moment.

yongzhihuang avatar Feb 17 '17 20:02 yongzhihuang

@yongzhihuang It just delegates to the GPT API.

taak77 avatar Feb 17 '17 20:02 taak77

Thanks @taak77 it seems I can't chain it too, but I found a way around it, and that is by invoking the global googletag object:

    _.map(this.pageLevelKeyvals, (value, key) => {
      if (window.googletag) {
        window.googletag.cmd.push(() => {
          window.googletag.pubads().setTargeting(key, '' + String(value)); // note value needs to be string
        });
      }
    });

yongzhihuang avatar Feb 17 '17 21:02 yongzhihuang

@yongzhihuang just fixed a bug where the same pubads API call overrides the previous one, please try v0.2.3. FYI, chaining the API call is still not supported yet, they currently return Promise which resolves with the return value from pubads API.

taak77 avatar Feb 21 '17 02:02 taak77

hi @taak77 thank you so much for the fix.

I'm now seeing the following behavior:

If I have an array with metadata in each element, and I want to render an ad for each element:

var items = [
  { name: 'test1'}
  { name: 'test2'}
  { name: 'test3'}
];

When I render the ad, I want to pass name into custom parameter of the ad call, however, when I render all ads on same page,

it seems like i'm the custom param for ALL ads are being set to the very last value name=test3

can you help me out to see if there may be a hidden bug somewhere?

yongzhihuang avatar Mar 01 '17 23:03 yongzhihuang

I guess that's just how pageLevel Targeting, I was trying to update page level targeting when some ads are in view on a section of website. Need a way to reset page level targeting or override it at will.

yongzhihuang avatar Mar 04 '17 23:03 yongzhihuang

Can you provide a failing test case in the test suite here to highlight your issue? I'm having a little trouble following it. If you're talking about setTargeting then you appear to be overriding the key name which is why it results in test3. You can provide multiple values to a key by using any array GPT.setTargeting("name", ["test1", "test2", "test3"]). https://developers.google.com/doubleclick-gpt/reference#googletag.PassbackSlot_setTargeting

potench avatar Mar 06 '17 17:03 potench