Managed Mode callbacks are JavaScript functions that run when your creatives load and render.
Each of your Managed Mode layouts has its own JavaScript code for each callback. This lets you write any layout-specific JavaScript code that you need.
The callback functions are:
- Custom Injection Location
ManagedMode.Callbacks.customInjection- Fill
ManagedMode.Callbacks.onFill- Render
ManagedMode.Callbacks.onRender- Error
ManagedMode.Callbacks.onError
Type Definitions
-
Advertiser
-
An Advertiser object.
Type:
- Object
Properties:
Name Type Description namestring The advertiser's name.
verticalManagedMode.Callbacks.Vertical The advertiser's vertical.
-
Author
-
An Author object.
Type:
- Object
Properties:
Name Type Description namestring The name of the author.
-
Campaign
-
A Campaign object.
Type:
- Object
Properties:
Name Type Description advertiserManagedMode.Callbacks.Advertiser The campaign's advertiser.
namestring The campaign's name.
teamManagedMode.Callbacks.Team The team that owns this campaign.
-
Channel
-
The channel tells us whether we are running inside a normal web page, an AMP page, a mobile app, etc.
Type:
- Object
Properties:
Name Type Description name"amp" | "applenews" | "instant-article" | "mobileapp" | "web" The name of the channel.
-
Conditions
-
A Conditions object is a set of predicates that are matched against how the creative was served.
Type:
- Object
Properties:
Name Type Argument Description adUnitstring <optional>
Ad unit condition. The format depends on the ad server. For example:
/hello/world/12345iframesizestring <optional>
Iframe size condition. For example:
1x2pagestring <optional>
A page condition is a regular expression that matches against the page URL.
placementKeystring <optional>
The "placement key" value that was used in the ad request.
-
Creative
-
A MediaVoice creative.
Type:
- Object
-
"article" - Hosted Content
-
"deck" - Lightbox
-
"facebook-post" - Facebook Content
-
"inbound" - Web Content
-
"instagram-media" - Instagram Content
-
"outbound" - External Content
-
"tweet" - Twitter Content
Properties:
Name Type Argument Description authorManagedMode.Callbacks.Author <optional>
The creative's author.
campaignsArray.<ManagedMode.Callbacks.Campaign> Array of campaigns to which this creative belongs.
contentstring <optional>
The HTML content of the creative. This is relevant to a Hosted Content creative. (The
typevalue for Hosted Content is"article".)ctaArray.<ManagedMode.Callbacks.CTA> <optional>
An array of the creative's CTA (call-to-action) objects.
customObject <optional>
The creative's custom fields.
embedsArray.<ManagedMode.Callbacks.Embed> <optional>
The creative's embedded content, for example, social media posts.
This property is set only on the
creativeargument toManagedMode.Callbacks.onFill, not the creatives in thecontextargument.experienceHashstring The unique identifier for the creative's "experience". This will differ between different variants of the same creative, when optimization is being used.
idstring The unique identifier for the creative's "instance".
imageManagedMode.Callbacks.Thumbnail <optional>
The creative's main thumbnail image.
layoutType"single_creative" | "collection" <optional>
The layout type.
This property is set only on the
creativeargument toManagedMode.Callbacks.onFill, not the creatives in thecontextargument.linkstring <optional>
The creative's destination URL.
pubDatestring <optional>
The creative's publication date. The format is:
YYYY-MM-DD"T"HH:mm:ss"Z"For example:
"2017-05-27T18:00:48Z"renderManagedMode.Callbacks.LayoutRenderOptions <optional>
Options that affect how the layout is rendered.
This property is set only on the
creativeargument toManagedMode.Callbacks.onFill, not the creatives in thecontextargument.ruleManagedMode.Callbacks.Rule <optional>
The rule whose conditions were matched.
This property is set only on the
creativeargument toManagedMode.Callbacks.onFill, not the creatives in thecontextargument.sponsorManagedMode.Callbacks.Sponsor <optional>
The sponsor.
This property is set only on the
creativeargument toManagedMode.Callbacks.onFill, not the creatives in thecontextargument.summarystring <optional>
The creative's summary.
teamManagedMode.Callbacks.Team The team that owns this creative.
titlestring <optional>
The creative's title.
type"article" | "deck" | "facebook-post" | "inbound" | "instagram-media" | "outbound" | "tweet" The creative's experience type.
-
CTA
-
A CTA (call-to-action) object.
Type:
- Object
Properties:
Name Type Argument Description destUrlstring The destination URL.
idstring Unique identifier for the CTA.
imageManagedMode.Callbacks.Logo <optional>
The CTA image. Usually this is the sponsor's logo.
sponsorNamestring <optional>
The CTA sponsor's name.
type"sponsorlogolink" | "sponsornamelink" The CTA type. It may be a sponsor's logo (image) or a sponsor's name (text).
-
customInjection(templateContext) → {InjectionStrategy}
-
This callback is executed immediately before the rendered template is injected onto the page.
This callback should return an object with two optional properties: "injectionTarget" and "injectionBehavior".
These properties can be modified to control the template's injection location.
Parameters:
Name Type Description templateContextManagedMode.Callbacks.TemplateContext The jQuery-wrapped, fully-rendered, template element.
Returns:
An
InjectionStrategyobject which specifies the template's injection target and the injection behavior.- Type
- InjectionStrategy
Example
(function(templateContext) { // Inject the template after the specified // element's (id="river") children. return { "injectionTarget": window.top.document.getElementById("river"), "injectionBehavior": "append", }; }) -
Embed
-
An Embed object represents embedded content such as social media posts.
Type:
- Object
Properties:
Name Type Description typeObject Information about the embedded content type.
Properties
Name Type Argument Description tweetboolean <optional>
True if the embed is a post from Twitter.
instagram-mediaboolean <optional>
True if the embed is a post from Instagram.
Ensure that you access this property with quotes; for example:
if (embed.type["instagram-media"]) {}facebook-postboolean <optional>
True is the embed is a post from Facebook.
Ensure that you access this property with quotes; for example:
if (embed.type["facebook-post"]) {} -
FillContext
-
The FillContext object is passed to your
ManagedMode.Callbacks.onFillcallback function.Type:
- Object
Properties:
Name Type Argument Description channelManagedMode.Callbacks.Channel The channel tells us whether we are running inside a normal web page, an AMP page, a mobile app, etc.
creativesArray.<ManagedMode.Callbacks.Creative> Array of creatives. Only a Multi-Creative layout will be able to render more than one.
exitOnDefaultRuleboolean <optional>
True if the default placement will not be rendered when no conditions match.
placementManagedMode.Callbacks.Placement The placement whose layout will be rendered.
-
InjectionStrategy
-
This is the object returned from the
ManagedMode.Callbacks.customInjectioncallback.Its properties are used to modify the template's injection location.
Type:
- Object
-
"append" - The template will be placed inside of the DOM element identified by "injectionTarget", but after any existing content within "injectionTarget".
-
"prepend" - The template will be placed inside of the DOM element identified by "injectionTarget", but before any existing content within "injectionTarget".
-
"before" - The template will be placed outside of and in front of the DOM element identified by "injectionTarget".
-
"after" - The template will be placed outside of and after the DOM element identified by "injectionTarget".
Properties:
Name Type Argument Description injectionTargetObject <optional>
This should be a DOM element. If not specified, this will default to "Window.frameElement".
injectionBehavior"append" | "prepend" | "before" | "after" <optional>
This controls how the template is injected, relative to the "injectionTarget". If not specified, this will default to "before", but can be any of the values listed below:
-
LayoutRenderOptions
-
Options that affect how a layout is rendered.
Type:
- Object
Properties:
Name Type Argument Description adjustHeightstring <optional>
"automatic"if the layout uses the "Automatically adjust iframe height" option.adjustWidthstring <optional>
"automatic"if the layout uses the "Automatically adjust iframe width" option.bustIframeboolean <optional>
True if the layout uses the "Render outside of the iframe" option.
-
Logo
-
A Logo object.
This represents a sponsor's logo image.
Type:
- Object
Properties:
Name Type Argument Description captionstring <optional>
The logo's caption.
creditsstring <optional>
The logo's credits.
sourceHeightnumber The height, in pixels, of the original source image file.
sourceWidthnumber The width, in pixels, of the original source image file.
-
onError(errorContext)
-
The Error function is called when a creative fails to render.
Failures can occur due to a promo feed being empty, or JavaScript errors during rendering.
This will NOT be called in other more common situations such as the creative failing to load.
Parameters:
Name Type Description errorContextObject Properties
Name Type Argument Description $JQueryStatic A jQuery API object. This is the global jQuery object, not an instance.
Note: your callback function may be running in an iframe document, which may not be the same document where your layout is rendered. Therefore, you may need to specify the document when making a query, for example:
errorContext.$(".myElement", window.top.document);errstring <optional>
An error code, if available.
-
"NO_CREATIVES_IN_PROMOFEED" - A promo feed had no creatives, so rendering cannot continue.
Example
(function(errorContext) { errorContext.$(".placeholder").remove(); }) -
-
onFill(fillContext, creative, jQuery)
-
The Fill function is called after the creative data has loaded, but before the layout is rendered.
Parameters:
Name Type Description fillContextManagedMode.Callbacks.FillContext An object that tells you which creatives were loaded, which layout will be used to render them, and other useful information.
creativeManagedMode.Callbacks.Creative This creative object will be used for rendering. If you make changes to this object, then those changes will persist.
jQueryJQueryStatic A jQuery API object. This is the global jQuery object, not an instance.
Note: your callback function may be running in an iframe document, which may not be the same document where your layout is rendered. Therefore, you may need to specify the document when making a query, for example:
jQuery(".myElement", window.top.document);Example
(function(fillContext, creative, jQuery) { // Change the title that will be rendered // on an AMP page. try { if (fillContext.channel.name === "amp") { creative.title = "New Title"; } } catch (error) {} }) -
onRender(renderContext)
-
The Render function is called after the creative has been rendered.
At this point, your layout's template has been filled, parsed as HTML, and inserted into the document.
Parameters:
Name Type Description renderContextManagedMode.Callbacks.RenderContext The rendered layout and related information.
Example
(function(renderContext) { renderContext.$template.find(".myClass").hide(); }) -
Organization
-
An Organization object.
An Organization owns one or more teams; each team owns one or more campaigns.
Type:
- Object
Properties:
Name Type Description idstring Unique identifier for the organization.
namestring Organization name.
-
Placement
-
A Placement object represents a layout and how it was chosen.
Type:
- Object
Properties:
Name Type Description idstring Unique identifier of the placement.
layoutType"single_creative" | "collection" The layout type.
namestring The layout name.
renderManagedMode.Callbacks.LayoutRenderOptions Options that affect how the layout is rendered.
ruleManagedMode.Callbacks.Rule The rule whose conditions were matched. This rule's layout will be used for rendering.
-
RenderContext
-
A RenderContext object contains a rendered layout and related information.
This is the argument to the
ManagedMode.Callbacks.onRendercallback.Type:
- Object
Properties:
Name Type Description $JQueryStatic A jQuery API object. This is the global jQuery object, not an instance.
Note: your callback function may be running in an iframe document, which may not be the same document where your layout is rendered. Therefore, you may need to specify the document when making a query, for example:
renderContext.$(".myElement", window.top.document);$templatejQuery A jQuery object that represents the rendered template.
If your layout renders outside of the iframe, then the DOM elements may belong to a different document than
window.document.analyticsObject An object with methods for manual analytics event tracking.
Properties
Name Type Description trackPrimaryClickfunction Call this function to emit a click event. This should only be used in special cases. For example, your layout might have a "tap to expand" button that you wish to count as a click, when it would not happen automatically.
attachInteractionWatcherfunction Creates a function that watches an element for user interaction. This is for tracking clicks or taps of embedded content. When you call attachInteractionWatcher, it will attach a "watcher" function to the given object. After your embedded content has loaded, you can call the watcher function to start tracking user interactions. You should only call the watcher function one time.
fillManagedMode.Callbacks.FillContext Information about how the creative was loaded.
This is the same object passed to the
ManagedMode.Callbacks.onFillcallback.placementDataManagedMode.Callbacks.Placement Information about the placement whose layout was used to render the template.
renderingObject An object with helper functions for rendering
Properties
Name Type Description resizeFrameToFitContentfunction Call this function to resize the frame containing the creative to the proper size for the creative.
-
Rule
-
A Rule object determines which layout to render based on a set of conditions.
Type:
- Object
Properties:
Name Type Argument Description conditionsManagedMode.Callbacks.Conditions The conditions that will be matched for this rule to take effect.
idstring The unique identifier of this rule.
isDefaultboolean <optional>
True if this rule is used by default when no other rules have matching conditions.
namestring The rule name.
placementstring The unique identifier of the placement whose layout will be rendered when this rule has matching conditions.
-
Sponsor
-
A Sponsor object.
Type:
- Object
Properties:
Name Type Argument Description linkstring <optional>
A URL for the sponsor.
logoManagedMode.Callbacks.Logo <optional>
The sponsor's logo.
namestring The sponsor's name.
-
Team
-
A Team object. Each Team belongs to an Organization.
Type:
- Object
Properties:
Name Type Description idstring Unique identifier for the team.
namestring Team name.
organizationManagedMode.Callbacks.Organization The organization that owns this team.
-
TemplateContext
-
A TemplateContext object contains the jQuery-wrapped template as well as a jQuery API object.
This is the argument to the
ManagedMode.Callbacks.customInjectioncallback.Type:
- Object
Properties:
Name Type Description $JQueryStatic A jQuery API object. This is the global jQuery object, not an instance.
Note: your callback function may be running in an iframe document, which may not be the same document where your layout is rendered. Therefore, you may need to specify the document when making a query, for example:
templateContext.$(".myElement", window.top.document);$templatejQuery A jQuery object that represents the jQuery-wrapped template.
If your layout renders outside of the iframe, then the DOM elements may belong to a different document than
window.document. -
Thumbnail
-
A Thumbnail object represents the main thumbnail image for a creative.
Type:
- Object
Properties:
Name Type Argument Description captionstring <optional>
The image caption.
creditsstring <optional>
The image credits.
instancesArray.<ManagedMode.Callbacks.ThumbnailInstance> <optional>
Array of instances. Each instance is intended to represent the same image, but cropped to different aspect ratios. Your layout's Handlebars template will choose which instance to use.
-
ThumbnailInstance
-
A ThumbnailInstance object represents one aspect ratio of a thumbnail image.
Thumbnail images can have multiple "instances" that represent the same image cropped to different aspect ratios.
Type:
- Object
Properties:
Name Type Description sourceHeightnumber The height, in pixels, of the original image file.
sourceWidthnumber The width, in pixels, of the original image file.
-
Vertical
-
A Vertical object.
Type:
- Object
Properties:
Name Type Description vertical.codestring The vertical code (MSCI/S&P GICS Industry Group).
vertical.namestring The vertical name.
Example
{ "code": "1010", "name": "Energy", }