Run custom Key Value Pairs properly by placing them before the PubGuru header bidding script

This post was most recently updated on mayo 30th, 2022

If you want to send custom Key-Value Pairs to GAM, all you need to do is set up some javascript on your pages. This needs to be set before the MonetizeMore’s PubGuru header bidding script is loaded.

The following script tag can be expanded to include more custom key-value pairs, using the same format:

<script>
window.pg = window.pg || {};
window.pg.kvps = window.pg.kvps || {};
window.pg.kvps[«customKVP»] = «value»;

</script>

Note that: if the publisher wants to add more key-values in the future, they should not redefine window.pg.kvps object.

Instead, they should add more values with bracket- or dot-notation to add new values:

<script>
  window.pg = window.pg || {};
  window.pg.kvps = window.pg.kvps || {};
  window.pg.kvps["customKVP"] = "value";
  window.pg.kvps["anotherValue"] = "secondValue"; 
</script>
--- also valid (dot-notation) ---
<script>
  window.pg = window.pg || {};
  window.pg.kvps = window.pg.kvps || {};
  window.pg.kvps.customKVP = "value";
  window.pg.kvps.anotherValue = "secondValue";     
</script>
While this setup will allow you to add KVPs in multiple script tags, as long as they are above the MonetizeMore script in the HTML, it is strongly recommended that you keep them together (for ease of editing). Also note that the last option (dot-notation), has some limitations, as you can’t start keys with a number. The square bracket style is recommended.

Key with Multiple Values

To create a key with multiple values, the value field in the code should be a javascript array, for example:

<script>
  window.pg = window.pg || {};
  window.pg.kvps = window.pg.kvps || {};
  window.pg.kvps["multiKey"] = ["value1", "value2", "value3"];
</script>

Sample header tag for pages where we’d like Google demand blocked:

<script>
  window.pg = window.pg || {};
  window.pg.kvps = window.pg.kvps || {};
  window.pg.kvps["google"] = ["0", "no", "off"];
</script>

<script type = «text/javascript» src = «//m2d.m2.ai/pg.mydomain.js» async></script>

Need more help? Send us an email at support@monetizemore.com or log in to PubGuru App and use the Chat widget for immediate support.

Stop letting RPM drops stress you out

Let our AdOps Experts do the hard work. Sign up today and unlock your revenue potential.

Maximize my Ad Revenue

It’s your turn to take the ad monetization game to the next level

  • No credit card required
  • No DNS transfer
  • Cancel any time

Get started