MediaVoice Plugin public API for Script Mode.
If you are looking for documentation on Managed Mode layouts, please see the
ManagedMode page.
Namespaces
Members
-
<readonly> $
-
The jQuery object that the plugin uses internally.
Methods
-
<static> disableIAS()
-
Disables IAS tracking. Differs from the above in that this applies the confDisabled property to the IAS config, allowing logs from iastracker.js to appear. See NA-8831 for more context.
-
<static> disableMOAT()
-
Disables MOAT tracking. Differs from the above in that this applies the confDisabled property to the MOAT config, allowing logs from moattracker.js to appear. See NA-8831 for more context.
-
configurePrivacy(conf) → {boolean}
-
Configure user privacy measures.
Parameters:
Name Type Description confobject Properties
Name Type Argument Description privacyModestring <optional>
The privacy mode preset to use. Options are:
`gdpr` : GDPR compliant. `gdpr-eu` : When in EU & similar, `gdpr`; `managed` otherwise. `managed` : User consent is externally managed (by site/app operator). `no-track` : No user tracking will be performed.The
gdpr-eusetting is default.When either
gdprorgdpr-euis used, consent signals must be exchanged via IAB CMP JS or manually (viatoggleUserConsent).When in
gdprmode (orgdpr-euwhile in a EU country), consent must be granted before user tracking can be performed.When in
managedmode (orgdpr-euwhile in a non-EU country), user tracking will be performed unless consent is explicitly denied.When in
no-trackmode, user tracking will never be performed.Returns:
Indicates if configuration was applied successfully.
- Type
- boolean
-
configureSecondaryPage(conf)
-
Tell the plugin to track and/or render the page.
Parameters:
Name Type Description confobject Properties
Name Type Argument Description dateFormatAPI.dateFormatterCallback <optional>
A callback that accepts a [Date][1] object and returns a formatted string. This lets you control how dates are rendered. [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
bindingobject <optional>
A map of CSS selectors that determine where on the page to render each piece of content. Known keys:
title,summary,content,author,pubDate,sponsor.name,sponsor.link,sponsor.logo,image.href,image.caption,image.creditsonFillAPI.secondaryPageOnFill <optional>
A callback that runs before the page is rendered to the DOM.
onRenderAPI.secondaryPageOnRender <optional>
A callback that runs after the page is rendered to the DOM.
onErrorAPI.secondaryPageOnError <optional>
A callback that runs if the page cannot be rendered.
trackfunction <optional>
A callback that runs when the plugin cannot determine whether the page should be tracked or not. This happens on inbound page views that were not directly triggered by an ad clickthrough.
To track these inbound pages, return the string
"inbound"from this callback. Ideally, your page’s HTML will contain a Canonical Link Element that will be used for tracking. -
disablePolarTracker()
-
This function is a no-op.
- Deprecated:
- Yes
-
enableIAS(primaryEnabled, callback)
-
Eanble or disable IAS tracking.
Parameters:
Name Type Argument Default Description primaryEnabledboolean <optional>
true trueto enable IAS tracking on primary views,falseto disable it.callbackfunction <optional>
A callback function that returns an object. The object's key-values must comprise all the parameters required in order to inject the IAS tracking tag.
-
enableMOAT(enabled, primaryEnabled, contentDiv)
-
Enable or disable MOAT tracking.
Parameters:
Name Type Argument Default Description enabledboolean <optional>
true trueto enable MOAT,falseto disable it.primaryEnabledboolean <optional>
false Deprecated and ignored; left it here for backwards-compatibility.
contentDivstring <optional>
"document.body" Specifies the ID selector of the content div to be used by MOAT for tracking.
Added in v0.5.46. Previous plugin versions do not send any selector to MOAT, with the assumption that the entire page should be tracked.
-
enableSPAMode(pageOnHashChange)
-
Enable Single-page application (SPA) mode.
Parameters:
Name Type Description pageOnHashChangeboolean An
onhashchangeevent indicates that a new page has been rendered. -
injectCSS(styles, target)
-
Inject CSS styles into the document.
Parameters:
Name Type Argument Default Description stylesstring CSS styles.
targetstring <optional>
head Selector, whose matching elements will have a
styleelement appended. -
insertPreview(options)
-
Request an ad and automatically place it in the page when it succeeds.
Parameters:
Name Type Description optionsobject Properties
Name Type Argument Description labelstring <optional>
Label that will be reported in analytics events.
unitobject Ad unit to request. Note that if the plugin is operating in "preview mode" and the "mvpi" parameter is supplied in the query string, then this unit is ignored by the plugin; instead the plugin always renders the preview with the creative referenced in the "mvpi" parameter.
locationstring CSS selector where the ad should be inserted. It must match exactly one element.
infoTextstring Text that is shown when the info button is clicked.
infoButtonTextstring Text for the info button label.
templateobject | function When an object is provided then the most appropriate template will be picked based on the ad tag. Source ad tags will translate to creative templates, At least one of the following values must be assigned. Possible object values are:
creative,collection, orfnBoth creative and collection must be assigned a handlebars template. fn must be passed a function that takes theadtagandmodeland returns a template function. When a function is provided then the function is assumed to be acreativetemplate. The picked template will be run upon success, and inserted into the DOM where thelocationselector has a match.onRenderAPI.onRenderCallback Callback that runs after the template is executed and inserted into the DOM.
onFillfunction Callback that runs after a native ad is fetched successfully.
onErrorAPI.onErrorCallback Callback that runs upon failure.
dateFormatAPI.dateFormatterCallback Date formatter that will transform the
pubDate. If this parameter is not defined, then the template will render raw [ISO 8601][1] dates. [1]: http://en.wikipedia.org/wiki/ISO_8601sponsorLinkFormatAPI.sponsorLinkFormatterCallback Sponsor Link formatter that will transform the sponsor link and name. If it is not defined, then the template will use the default formatting.
previewsarray The list of ad previews in the collection to use if a collection ad tag is being used.
collectionSizeInteger The number of creatives that the collection template can render.
-
insertPreviewCollection(options)
-
Request a collection of ads and automatically place each in the page when request succeeds.
A collection is a group of ads served from one ad request. To use a collection, you must first create the collection in MediaVoice, then traffic the collection ad tag as a normal 3rd-party unit through your ad server. Then, create a custom collection template that includes templates or logic to render each individual ad spot, which is used in the
optionsargument.Parameters:
Name Type Description optionsobject The collection configuration.
Properties
Name Type Description labelstring A unique name for your collection.
unitobject The ad unit used to request the collection.
locationstring The DOM node where the collection will be inserted.
infoTextstring The text that is displayed when the info button is clicked.
infoButtonTextstring The text displayed on the info button.
templateobject | function When an object is provided then the most appropriate template will be picked based on the ad tag. Source ad tags will translate to creative templates, At least one of the following values must be assigned. Possible object values are:
creative,collection, orfnBoth creative and collection must be assigned a handlebars template. fn must be passed a function that takes theadtagandmodeland returns a template function. When a function is provided then the function is assumed to be acollectiontemplate. The picked template will be run upon success, and inserted into the DOM where thelocationselector has a match.onRenderAPI.onRenderCallback Callback that runs after the template is executed and inserted into the DOM.
onFillfunction A callback that is triggered after the ad request returns.
onErrorfunction A callback that is triggered if a error occurs.
dateFormatAPI.dateFormatterCallback Date formatter that will transform the
pubDate. If this parameter is not defined, then the template will render raw [ISO 8601][1] dates. [1]: http://en.wikipedia.org/wiki/ISO_8601sponsorLinkFormatAPI.sponsorLinkFormatterCallback Sponsor Link formatter that will transform the sponsor link and name. If it is not defined, then the template will use the default formatting.
previewsarray The list of ad previews in the collection to use if a collection ad tag is being used.
collectionSizeInteger The number of creatives that the collection template can render.
-
log()
-
This function records strings, objects, etc. to the JavaScript console.
-
requestAd(options) → {object|null}
-
Request an ad on demand. The DOM’s body element may have a pixel tracker image appended after a successful ad request.
Parameters:
Name Type Description optionsobject Ad request options
Properties
Name Type Argument Description unitobject Ad unit. Will be passed to the ad driver.
Properties
Name Type Description serverstring Ad server, e.g.
"dfp"or"mocean".labelstring Label. Used for the
impressionanalytics event that is automatically tracked when the ad is successfully loaded.previewCountinteger <optional>
Used for collections to tell the API how many creatives to fetch.
onFillAPI.requestAdOnFill Success callback.
onErrorAPI.requestAdOnError Error callback.
htmlElementfunction <optional>
A function that returns the HTML element or jQuery object that contains the ad preview. The function will be called after the
onFillsuccess callback.You must provide this function if MOAT is enabled. Otherwise, MOAT will be unable to track the viewability of the ad preview. The element must be rendered and in the DOM.
Returns:
If the request is started successfully, then an object with a
cancelfunction that you can call to abort the ad request. Otherwise,null.- Type
- object | null
-
requestCreative(options) → {null}
-
Request a creative on demand, given the creative’s instance ID. This is intended to be used when deep linking (i.e., when a page view is not driven directly by an ad-served impression). In this deep link use case, analytics must be manually reported via the
trackfunction, withoptions.kindholding a value ofevent.kind.DEEP_LINK, and values of null for bothoptions.unitandoptions.adtag.Parameters:
Name Type Description optionsobject Request options.
Properties
Name Type Argument Description idstring Creative id.
previewCountstring <optional>
The number of creatives to request from the API. Used for collections.
onFillAPI.requestCreativeOnFill Success callback.
onErrorAPI.requestCreativeOnError Error callback.
Returns:
- Type
- null
-
resetAdServer()
-
Calls reset on all registered ad servers. For single-page applications the ad server may need to be reset between ad requests to ensure a new ad unit is delivered. If using DFP + GPT, this function should be called immediately after
googletag.pubads().refresh(), in order to synchronize the correlator value used by GPT with the value used to request native ad units. -
setPropertyID(id)
-
Set the Property ID for your page or application.
This function must be called exactly once, before any other plugin functions are called.
Parameters:
Name Type Description idstring Property ID supplied by your MediaVoice account manager.
-
setSecondaryPageURL(url)
-
Set the URL path for the secondary page. This is required for the plugin to render the secondary page and generate links to it.
Parameters:
Name Type Description urlstring URL path to the secondary page. For example,
"sponsored.html". -
setWillLinkRedirect(Callback)
-
Set a callback function that tells the plugin whether a given link will be redirected to a different URL when clicked.
When your callback returns false, and the link’s destination is on the same origin as the current page, then the plugin will avoid storing tracking data in the destination URL. It will use HTML5 Web Storage instead.
This is necessary on web sites that do not work correctly when URLs have our tracking data added to the hash.
Parameters:
Name Type Argument Description CallbackAPI.willLinkRedirectCallback <nullable>
function that will be invoked when links are clicked.
-
toggleUserConsent(flag) → {boolean|null}
-
Toggle the user consent flag.
Parameters:
Name Type Description flagboolean | null The consent value to set. If
nullis passed, no change will be made.Returns:
The current consent flag value. If
null, no consent decision has yet been made available.- Type
- boolean | null
Type Definitions
-
dateFormatterCallback(date) → {string}
-
Date formatter function.
Parameters:
Name Type Description dateDate The [Date object][1] to format. [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
Returns:
Formatted date.
- Type
- string
-
onErrorCallback(error, extra)
-
Callback function, triggered when an internal error has occurred. Can be called from
insertPrevieworinsertPreviewCollection.Parameters:
Name Type Description errorstring | object A string or object representation of the error that occurred
extraobject Any extra error information around the error the occurred.
-
onRenderCallback($html, creative)
-
Callback function, triggered immediately after a placement is rendered by
insertPrevieworinsertPreviewCollection.Parameters:
Name Type Description $htmlobject The jQuery object that was rendered from the template.
creativeobject The creative that was rendered. This is the same object provided in the
onFillcallback. -
requestAdOnError(error)
-
Error callback function for the requestAd function.
Parameters:
Name Type Description errorobject The error that occurred while fetching the ad
-
requestAdOnFill(response)
-
Success callback function for the requestAd function.
Parameters:
Name Type Description responseobject The ad response
Properties
Name Type Description modelobject Model representing e.g. an article
adtagobject Creative and tracking info.
-
requestCreativeOnError(error)
-
Error callback function for the requestCreative function.
Parameters:
Name Type Description errorobject The error that occurred while fetching the creative.
-
requestCreativeOnFill(response)
-
Success callback function for the requestCreative function.
Parameters:
Name Type Description responseobject The creative response.
Properties
Name Type Description modelobject Model representing e.g. an article.
-
secondaryPageOnError(error)
-
Callback function, triggered when the secondary page cannot be rendered.
Parameters:
Name Type Description errorobject The error that occurred while fetching the secondary page content.
-
secondaryPageOnFill(model)
-
Callback function, triggered immediately before the secondary page is rendered into the DOM.
Parameters:
Name Type Description modelobject Model representing e.g. an article
-
secondaryPageOnRender()
-
Callback function, triggered immediately after the secondary page is rendered into the DOM.
-
sponsorLinkFormatterCallback(sponsorName, sponsorLink) → {object}
-
Sponsor link formatter function.
Parameters:
Name Type Description sponsorNamestring The name of the sponsor from the sponsornamelink cta.
sponsorLinkstring The link for the sponsor from the sponsornamelink cta.
Returns:
newSponsorName, newSponsorLink
- Type
- object
-
willLinkRedirectCallback(url) → {boolean}
-
Callback that tells the plugin whether a given link will be redirected when clicked.
Parameters:
Name Type Description urlstring The URL of the link.
Returns:
trueif the link will be redirected, otherwisefalse. Returningfalsewill allow the plugin to store tracking data with HTML5 Web Storage instead of altering the destination URL.- Type
- boolean