PubGuru Header Bidding Publisher API

PubGuru
Last updated: July 11, 2019 | by David Loschiavo

This post was most recently updated on July 11th, 2019

PubGuru Header Bidding exposes interfaces publicly to adops and the publisher’s dev team for debugging and per-pageview customizations.

To use any of the following API tools on page, make sure you include the following code first. Then include the settings you want. Then embed your header bidding config file.

window.m2hb = window.m2hb || {};

This only needs to be included once, above the rest of our code.

Enable Debugging in the Console

The GET parameter m2debug=true is the most frequently used debugging tool. This flag will dump a significant amount of debugging information into the javascript console, and shortly after the page and ads have loaded, will execute the MonetizeMore configuration test and display the testing results in the footer of the page.

Disable (Blacklist) Ad Units for the Pageview

For debugging purposes, the GET parameter disabledUnits can be used to disable units for the immediate pageview. To disable more than one unit at a time, comma separate the values. Each ad unit name is the full DFP ad unit code (e.g. /1234567/DfpAdUnitCode). Here’s an example:

http://www.pubsite.com/page/id/article.html?disabledUnits=/1234567/DfpAdUnitCode1,/1234567/DfpAdUnitCode2

Publishers can also disable units in javascript on page. Publishers using PubGuru Header Bidding offpage should find the <script> tag that loads your PubGuru Header Bidding (m2hb) config file, and before that script tag, include the following code (change the ad units to your ad unit names that you want to exclude):

window.m2hb = window.m2hb || {};
window.m2hb.disabledUnits = window.m2hb.disabledUnits || [];
window.m2hb.disabledUnits.push(‘/1234567/DfpAdUnitCode1’);
window.m2hb.disabledUnits.push(‘/1234567/DfpAdUnitCode2’);

Publishers using PubGuru Header Bidding onpage should include this between when window.m2hb is instantiated and when m2hb.loadJS() loads your config file.

Enable (Whitelist) Ad Units for the Pageview

Some publishers have very complicated pages that can load a variable number of ad units, but the publisher doesn’t know how many or what units will be loaded until runtime. This is most common where the publisher has some short articles and some long articles, and a page can have dynamically between 3 and 8 ad units based on the content length. In this case, the HB config includes all units. Then the publisher should include the following code before the m2hb.m2.ai script:

window.m2hb = window.m2hb || {};
window.m2hb.customUnits = window.m2hb.customUnits || [];
window.m2hb.customUnits.push(‘/1234567/DfpAdUnitCode1’);
window.m2hb.customUnits.push(‘/1234567/DfpAdUnitCode2’);

In this case, only these two units will load regardless of what else is in the configuration.

Disable One or More Bidders for the Pageview

For debugging purposes, the GET parameter disabledBidders can be used to disable units for the immediate pageview. To disable more than one bidder at a time, comma separate the values. Here’s an example:

http://www.pubsite.com/page/id/article.html?disabledBidders=sovrn,pulsepoint

Publishers can also disable bidders in javascript on page. Publishers using PubGuru Header Bidding offpage should find the script tag that loads your PubGuru Header Bidding (m2hb) config file, and before that script tag, include the following code (change the bidders that you want to exclude):

window.m2hb = window.m2hb || {};
window.m2hb.disabledBidders = window.m2hb.disabledBidders || [] window.m2hb.disabledBidders.push(‘sovrn’);
window.m2hb.disabledBidders.push(‘pulsepoint’);

Publishers using PubGuru Header Bidding onpage should include this between when window.m2hb is instantiated and when m2hb.loadJS() loads your config file.

If you specify bidders to be disabled in the URL for diagnostic purposes, it will override anything set on the page.

Setting Custom KVPs and Tracking Imps & Revenue by Article ID

Publishers using PubGuru Header Bidding offpage should find the script tag that loads your PubGuru Header Bidding (m2hb) config file, and before that script tag, include the following code example:

window.m2hb = window.m2hb || {};
window.m2hb.kvps = window.m2hb.kvps || {};
window.m2hb.kvps.someKey = ‘someValue’;

Publishers using PubGuru Header Bidding onpage should find the first line in their onpage code, and add the second line after it. The publisher can pass any value they want, including articleID.

Scripted Ad Unit Names

Some publishers have extensively complicated ad unit names for reporting that gets around KVP limitations. If you’d like to script your ad unit names, use the following code:

window.m2hb = window.m2hb || {};
m2hb.unitVariables = m2hb.unitVariables || {}
m2hb.unitVariables.section = “culture”;

When the unit is configured for HB, all instances of “{section}” in our unit names will be dynamically changed to “culture”, allowing the same HB PIDs to be used for multiple units.

Chainloading Configs

Since early versions of PubGuru Header Bidding, we’ve supported chainloading configs. This is so we can load an entirely different config in a prod environment without relying on the publisher changing the code. To do this, add the m2hb= GET parameter. For security reasons, the chainloaded target MUST be on the MonetizeMore cloudfront CDN.

Chainloading will also intelligently import ad units and ad bidders, enabling chain loading to be used by both dev and ops. If chain loaded config does not have these configured, the chain loaded config will inherit them from the parent config.

Here’s an example: http://www.pubsite.com/page/id/article.html?m2hb=m2hb.pubsite-otherconfig.min.js

Recommended Reading

how-to-generate-tags-for-multiple-ad-units
Blog
November 22, 2024

How to generate tags for multiple ad units?

Read More
A target with a bullseye.
AdSense Ad Optimization
November 20, 2024

How to Find Your Target Audience to Increase Your AdSense Revenue

Read More
Ad Optimization
November 18, 2024

Top 5 Ad Viewability Strategies that will Boost Revenue

Read More

Trusted by 1,500+ publishers worldwide

10X your ad revenue with our award-winning solutions.

Let's Talk

Close

Ready to 10X your ad revenue with the #1 ad management partner?

Start Now