JavaScript API
window.pubber: the modules running, single-page apps, and when the tag is ready.
The tag defines window.pubber as soon as it loads. It works the same in both tags; what a call does depends on the modules running.
pubber.ready(callback)
Calls callback with the names of the modules that started (["analytics", "ads"], ["analytics"], or []), once the tag has the site's settings and has started them, or at once if it already has.
window.pubber && window.pubber.ready(function (modules) {
if (modules.indexOf("ads") < 0) console.log("No ads on this page");
});The tag loads asynchronously, so window.pubber may not exist yet when your own script runs. Check for it first, or call it from your own code after the page has loaded.
pubber.modules
The modules running, as an array. It is empty until they start; use ready to wait for them.
pubber.pageview()
For single-page apps: counts a new page view after a client-side navigation. The view before it reports how long and how far it was read, and the new one has the previous address as its referrer. It does nothing without the analytics module, and nothing if the address hasn't changed.
pubber.refill()
For single-page apps with Pubber Ads: removes the offers placed for the previous page and asks for the page now showing. Returns a promise that settles when the request is done. Without the ads module it does nothing.
// after your router shows a new article
router.afterEach(function () {
if (!window.pubber) return;
window.pubber.pageview();
window.pubber.refill();
});pubber.version
The SDK's version, as a string.
Passing what you know: window.pubberLead
With Pubber Ads, a site that knows a reader's ZIP code or state (from a quote form, say) can set window.pubberLead = { zip: "30301", state: "GA" } before the tag loads, or add data-lead-zip and data-lead-state to the tag, so offers can match the reader's area.
Tag attributes
data-site: your site key. Required.data-modules: the modules the tag may run on this page; see Analytics, ads or both.data-debug="1": logs what the tag does to the browser console.