This is the snippet to insert the Studio enabler into your document.
<script src="https://s0.2mdn.net/ads/studio/Enabler.js">
</script>
The enabler has an asyncronous setup process so please wait for the INIT event before starting your ad.
<script>
if (!Enabler.isInitialized()) {
Enabler.addEventListener(
studio.events.StudioEvent.INIT,
enablerInitialized);
} else {
enablerInitialized();
}
function enablerInitialized() {
// Enabler initialized.
// In App ads are rendered offscreen so animation should wait for
// the visible event. These are simulated with delays in the local
// environment.
if (!Enabler.isVisible()) {
Enabler.addEventListener(
studio.events.StudioEvent.VISIBLE,
adVisible);
} else {
adVisible();
}
}
function adVisible() {
// Ad visible, start ad/animation.
}
</script>
Basic metric reporting for Exits, Counters, and Timers.
<script>
// Exits.
Enabler.exit("Click on BG");
// Exits; overriding exit.
Enabler.exitOverride("Click on BG", "http://www.google.com");
// Counters.
Enabler.counter("Clicked on tab 1");
// Timers
Enabler.startTimer("Spinning car");
Enabler.stopTimer("Spinning car");
</script>
For Expanding Ads, we can set various parameters and flags for the expansion using setExpandingPixelOffsets, setStartExpanded, and setIsMultiDirectional.
The following example is a multi directional expanding ad that is 300x250 when collapsed and expands to 500x350 when expanded. The entire size is 700x450 to accommodate for the direction it expands in.
<head>
<script type="text/javascript">
// Can be called before INIT event.
Enabler.setExpandingPixelOffsets(
200, // left offset of expanded ad
100, // top offset of expanded ad
700, // expanded width of ad
450); // expanded height of ad
Enabler.setStartExpanded(false);
// whether to start in expanded state (defaults to false)
Enabler.setIsMultiDirectional(true);
// multidirectional ads expand in the "best available" direction
// (default false)
// Listen for INIT/VISIBLE of Enabler here.
</script>
...
</head>
Expanding ads need to adhere to a specific asyncronous lifecycle. Below is a list of methods, events, with explanations of the expanding and collapsing flows, as well as a complete example.
studio.events.StudioEvent.EXPAND_START
studio.events.StudioEvent.EXPAND_FINISH
studio.events.StudioEvent.COLLAPSE_START
studio.events.StudioEvent.COLLAPSE_FINISH
Enabler.requestExpand()
Enabler.finishExpand()
Enabler.requestCollapse()
Enabler.finishCollapse()
Enabler.requestExpand()
.studio.events.StudioEvent.EXPAND_START
is dispatched.Enabler.finishExpand()
to complete
expansion. This makes sure pushdowns are syncronized.Enabler.requestCollapse()
.
studio.events.StudioEvent.COLLAPSE_START
is dispatched. This
can get dispatched independently of Enabler.requestCollapse()
as sometimes the environment provides a close button outside of the
creative.Enabler.finishCollapse()
to complete
collapse and close div.<head>
<script type="text/javascript">
var isExpanded = false;
function expandStartHandler() {
// Perform expand animation.
// Optionally, should you want the direction to expand in call:
// Enabler.getExpandDirection(); //
// When animation finished must call
Enabler.finishExpand();
}
function expandFinishHandler() {
// Convenience callback for setting
// final state when expanded.
isExpanded = true;
}
function collapseStartHandler() {
// Perform collapse animation.
// When animation finished must call
Enabler.finishCollapse();
}
function collapseFinishHandler() {
// Convenience callback for setting
// final state when collapsed.
isExpanded = false;
}
function actionClickHandler() {
isExpanded ? Enabler.requestCollapse() : Enabler.requestExpand();
}
Enabler.addEventListener(
studio.events.StudioEvent.EXPAND_START,
expandStartHandler);
Enabler.addEventListener(
studio.events.StudioEvent.EXPAND_FINISH,
expandFinishHandler);
Enabler.addEventListener(
studio.events.StudioEvent.COLLAPSE_START,
collapseStartHandler);
Enabler.addEventListener(
studio.events.StudioEvent.COLLAPSE_FINISH,
collapseFinishHandler);
actionBtn.addEventListener(
'click',
actionClickHandler,
false);
</script>
...
</head>
Fullscreen ads have a lifecycle that is similar to expanding ads. Differences are noted below.
studio.events.StudioEvent.FULLSCREEN_SUPPORT
studio.events.StudioEvent.FULLSCREEN_DIMENSIONS
studio.events.StudioEvent.FULLSCREEN_EXPAND_START
studio.events.StudioEvent.FULLSCREEN_EXPAND_FINISH
studio.events.StudioEvent.FULLSCREEN_COLLAPSE_START
studio.events.StudioEvent.FULLSCREEN_COLLAPSE_FINISH
Enabler.queryFullscreenSupport()
Enabler.queryFullscreenDimensions()
Enabler.requestFullscreenExpand(opt_width, opt_height)
Enabler.finishFullscreenExpand()
Enabler.requestFullscreenCollapse()
Enabler.finishFullscreenCollapse()
Enabler.queryFullscreenSupport()
.Enabler.queryFullscreenDimensions()
.Enabler.requestFullscreenExpand()
. You can pass a
set of dimensions to expand to, or omit the dimensions to
expand to the maximum possible size.Collapse flow is exactly analogous to the collapse flow for normal expanding ads.
studio.Enabler |
useSingletonGetter
: number
Use
studio.Enabler.getInstance() or alias Enabler
to get enabler instance. |
addEventListener(type, , opt_capture, opt_handlerScope)
Adds an event listener to the event target. The same handler can only be
added once per the type. Even if you add the same handler multiple times
using the same type then it will only be called once when the event is
dispatched.
Arguments:
|
|||||||
addMessageHandler(messageName, handler)
Adds a new handler for an otherwise unknown message.
|
|||||||
callAfterInitialized(callback)
Calls the callback when the enabler is initialized or after.
Arguments:
|
|||||||
close()
Closes floating and popup creative types. If it is an expanding creative,
close acts as a proxy to collapse.
|
|||||||
closeCompanion()
Closes the companion asset for floating, reminder, and pop-up creative
types.
|
|||||||
collapse()
Use requestCollapse() instead.
Clips the container of the html asset from the expanded dimensions
to the collapsed dimensions. Please use event listeners to invoke the
collapse action as it may be called by the environment independently
of calling
studio.Enabler#collapse() .
This function is only applicable for expandable ad formats.
|
|||||||
counter(eventId, opt_isCumulative)
Tracks a counter event.
Arguments:
|
|||||||
displayCompanion()
Triggers the display of the companion asset for floating, reminder, and
pop-up advert types.
|
|||||||
exit(id, opt_url)
Opens a new window with the URL as identified by the given exit ID.
Arguments:
|
|||||||
exitOverride(id, url)
Opens a new window with the URL as identified by the given exit ID.
This differs from normal exit() as the url value will always override
the value modified in Studio or elsewhere.
|
|||||||
exitQueryString(id, opt_queryString)
Opens a new window with the URL as identified by the given exit ID with
an optional queryString appended.
Arguments:
|
|||||||
expand(opt_disableTracking, opt_expandProperties)
Use
studio.Enabler#requestExpand() .
Unclips the container of the html asset from the collapsed dimensions
to the expanded dimensions.
This function is only applicable for expandable ad formats.
Arguments:
|
|||||||
finishCollapse()
Clips the container of the html asset from the expanded dimensions
to the collapsed dimensions.
Please use event listeners to invoke the collapsed state of the ad as the
collapse event may be dispatched by the environment independently of calling
studio.Enabler#requestCollapse() .
This function is only applicable for expandable ad formats.
|
|||||||
finishExpand()
Finalizes the expand call via the rendering code.
|
|||||||
finishFullscreenCollapse()
Finishes fullscreen collapse.
|
|||||||
finishFullscreenExpand()
Finishes fullscreen expand.
|
|||||||
getContainerState()
⇒ studio.sdk.ContainerState
Returns the current state of the container.
Returns: studio.sdk.ContainerState
The container state.
|
|||||||
Returns the DART ad ID.
Returns: ?number
Integer value of the ID number (generated by DART) that
identifies the ad.
|
|||||||
Returns the DART asset ID.
Returns: ?string
The ID (generated by DART) that identifies the
creative.
|
|||||||
Returns the DART creative ID.
Returns: ?number
The ID number (generated by DART) that identifies the
creative.
|
|||||||
Returns the DART page ID.
Returns: ?number
The ID number (generated by DART) that
identifies the zone where the creative is served.
|
|||||||
Returns the DART rendering ID.
Returns: ?string
The ID (generated by DART) that identifies the
rendering version of the creative.
|
|||||||
Returns the DART site ID.
Returns: ?number
Integer value of the ID number that identifies the site
where the creative is served, as defined in DART.
|
|||||||
Returns the DART site name.
Returns: ?string
The name of the site where the creative is served, as
defined in DART.
|
|||||||
getExpandDirection()
⇒ studio.common.mde.Direction
Returns the expand direction.
Returns: studio.common.mde.Direction
The direction to expand in.
|
|||||||
getFilename(originalFilename)
⇒ string
Use getUrl(filename).
Returns the runtime file name given the original compile-time file name. The
original file name may have been mapped to a newer file name.
|
|||||||
getOrientation()
⇒ studio.common.Orientation
Returns an object representing the orientation of the device.
Returns: studio.common.Orientation
An object representing the orientation of
the device.
|
|||||||
getParameter(variableName)
⇒ *
Retrieves a creative parameter that the user can pass via queryString
URL. This is also used internally to access ad configuration data.
Arguments:
Returns: *
Value of the parameter.
|
|||||||
Retrieves a creative parameter as an integer.
|
|||||||
Retrieves a creative parameter as a nullable string.
|
|||||||
getProfileId()
⇒ number
Get the dynamic creative profile id.
Returns: number
Returns the dynamic creative profile id.
|
|||||||
getUrl(filepath)
⇒ string
Gets the runtime URL given the original compile-time filename.
|
|||||||
Retrieving a user's area code will soon be unavailable.
Returns the user's area code.
Returns: ?string
The user's area code.
|
|||||||
getUserBandwidth()
⇒ number
Returns the user's bandwidth according to DART bandwidth codes.
Only supported for personalized ads.
Returns: number
An integer representing the user's bandwidth. Bandwidth
values are:
|
|||||||
Returns the two-letter string representation of the user's country.
Only supported for personalized ads.
Returns: ?string
Two-letter string representation of the user's country. Null is returned if country data is unavailable.
|
|||||||
Deprecated Returns the DART representation of the user's Nielsen Designated Market Area.
Returns: ?number
A DART representation of the user's Nielson Designated
Market Area.
|
|||||||
Returns the two-letter string representation of the user's state or
province.
Only supported for personalized ads.
Returns: ?string
Two-letter string representation of the user's state or
province. Null is returned if state/province is unavailable.
|
|||||||
Returns the user's zip code (for users in the United States, U.S.
territories, and Canada). Only supported for personalized ads.
Returns: ?string
The user's zip code as supplied by the ad server. Null value is returned if zip code is unavailable.
|
|||||||
hasUserInteracted()
⇒ boolean
Checks if a user has interacted with the document.
Returns: boolean
Whether the user has interacted with the document.
|
|||||||
invokeExternalJsFunction(functionName)
Invoke a function in the parent container. This could be the top
frame if served via a adj (script) tag, the serving iframe if served via
and adi (iframe) tag.
Arguments:
|
|||||||
invokeMraidMethod(methodName, opt_args, opt_callback)
Invoke a function on the mraid api. This is different from
invokeExternalJsFunction as you are given the results of the function in a
callback.
Arguments:
|
|||||||
isInitialized()
⇒ boolean
Returns whether the Enabler is intialized.
Returns: boolean
Whether the Enabler is intialized.
|
|||||||
isPageLoaded()
⇒ boolean
Returns whether the parent page has loaded. The iframe is notified when the
page has loaded and dispatches the
StudioEvent.PAGE_LOADED
event.
Returns: boolean
Whether the parent page has loaded or not.
|
|||||||
isServingInLiveEnvironment()
⇒ boolean
Returns whether the ad is serving in the live environment or not.
Returns: boolean
Whether the ad is serving in the live environment or not.
|
|||||||
isVisible()
⇒ boolean
Returns whether the ad is visible. The iframe is notified when the ad is
visible and the enabler dispatches the
StudioEvent.VISIBLE
event.
Returns: boolean
Whether the ad is visible or not.
|
|||||||
loadModule(moduleName, opt_loadedCallback)
Loads an additional module.
Arguments:
|
|||||||
loadScript(scriptUrl, opt_loadedCallback)
Loads an additional script file.
Arguments:
|
|||||||
queryFullscreenDimensions()
Initiates a query for the maximum allowable fullscreen dimensions. A
studio.event.StudioEvent.FULLSCREEN_DIMENSIONS event will
be dispatched with the maximum allowed width and height as properties.
Some publishers may pad the fullscreen window for a lightbox-like
experience. Because of this the maximum allowable dimensions may not
take up the entire browser window or screen.
|
|||||||
queryFullscreenSupport()
Initiates a query to find out whether mock fullscreen expansion mode is
supported. Please listen for the
studio.event.StudioEvent.FULLSCREEN_SUPPORT event. This
event will contain the support status.
|
|||||||
registerChargeableEventName(eventName)
Provide a method that allows the creative to define a chargeable event.
Arguments:
|
|||||||
removeEventListener(type, , opt_capture, opt_handlerScope)
Removes an event listener from the event target. The handler must be the
same object as the one added. If the handler has not been added then
nothing is done.
Arguments:
|
|||||||
removeMessageHandler(messageName)
Removes a new handler for an otherwise unknown message.
Arguments:
|
|||||||
reportCustomClickVariable(postString)
Use
studio.Enabler#reportCustomVariableCount1(custom) .
Deprecated This tracks a click against the string parameter. The string must meet the following criteria:
Arguments:
|
|||||||
reportCustomImpressionVariable(postString)
Use
studio.Enabler#reportCustomVariableCount1(custom) .
Deprecated Tracks an impression against the string parameter. The string must meet the following criteria:
Arguments:
|
|||||||
reportCustomVariableCount1(customString)
Counts instances of the string parameter, aggregated as
Custom Variable Count 1 in reports.
The string must meet the following criteria:
Arguments:
|
|||||||
reportCustomVariableCount2(customString)
Counts instances of the string parameter, aggregated as
Custom Variable Count 2 in reports.
The string must meet the following criteria:
Arguments:
|
|||||||
reportManualClose()
Records a manual closing of a floating, pop-up, expanding, in-page with
pop-up, or in-page with floating ad.
|
|||||||
requestCollapse()
Initiates the collapse lifecycle. This begins by calling requestCollapse(),
waiting for the COLLAPSE_START event, animating your collapse, then calling
finishCollapse() when the creative has fully collapsed.
Please use event listeners to invoke the collapsed state of the ad as the
collapse event may be dispatched by the environment independently of calling
studio.Enabler#requestCollapse() .
This function is only applicable for expandable ad formats.
|
|||||||
requestExpand()
Initiates the expand lifecycle. This begins by calling requestExpand(),
waiting for the EXPAND_START event, animating your expand, then calling
finishExpand() when the creative has fully expanded.
Please use event listeners to invoke the expanded state of the ad as the
expand may be dispatched by the environment independently of calling
studio.Enabler#requestExpand() . This is especially true on networks
such as the Google Display Network that display a hover timer before allowing
the ad to expand. Typical usage will look like:
This function is only applicable for expandable ad formats.
|
|||||||
requestFullscreenCollapse()
Requests fullscreen collapse. Please listen for the
studio.event.StudioEvent.FULLSCREEN_COLLAPSE_START event to
start collapse.
|
|||||||
requestFullscreenExpand(opt_width, opt_height)
Requests fullscreen expand. If width and height are provided, expands to a
rectangle of that width and height centered in the middle of the display (or
browser window, if the browser is not fullscreen). Otherwise expands to the
full size of the browser window/display. Note that on mobile devices the
browser window typically takes up the entire display.
Arguments:
|
|||||||
setDevDynamicContent(value)
Set the dynamic content development values.
Arguments:
|
|||||||
setExpandingPixelOffsets(left, top, opt_expandedWidth, opt_expandedHeight, opt_startExpanded, opt_isMultiDirectional)
Sets the pixel offsets for the collapsed portion of the ad. This does not
affect the local testing environment but when the ad is live the collapsed
portion will be shown at 0x0. This method works by setting the marginLeft
and marginTop of the body element which is set to relative positioning.
Arguments:
|
|||||||
setFloatingPixelDimensions(width, height)
Prepopulates the width and height of a floating or peeldown creative.
|
|||||||
setHint(name, value)
⇒ studio.Enabler
Adds a Hint to this creative
Arguments:
Returns: studio.Enabler
this.
|
|||||||
setIsMultiDirectional(isMultiDirectional)
Sets the isMultiDirectional flag.
Arguments:
|
|||||||
setProfileId(value)
Set the dynamic creative profile id.
Arguments:
|
|||||||
setStartExpanded(startExpanded)
Sets the startExpanded flag, which controls whether the asset starts in
the expanded state or not. If true, then when the initial requestExpand
call will not be tracked or logged and will not trigger an expansion timer.
Arguments:
|
|||||||
setUseCustomClose(useCustomClose)
Sets useCustomClose. This is primarily of use in mobile environments using
MRAID. When this flag is set, it means that the creative will provide its
own close button, so MRAID doesn't have to provide one.
Arguments:
|
|||||||
startTimer(timerId)
Starts an event timer.
Arguments:
|
|||||||
stopTimer(timerId)
Stops an event timer.
Arguments:
|