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.getInstance()
or alias Enabler
to get enabler instance.| type
: string
The type of the event to listen for.
|
|---|
|
: function(*):*
|
{handleEvent:function(*):*
No description.
|
| opt_capture
: boolean=
In DOM-compliant browsers, this determines
whether the listener is fired during the capture or bubble phase
of the event.
|
| opt_handlerScope
: Object=
Object in whose scope to call the listener.
|
studio.Enabler#collapse()
. Enabler.addEventListener(
studio.events.StudioEvent.COLLAPSE,
function() {
// collapse action
});
This function is only applicable for expandable ad formats.| eventId
: string
The string ID of the event to count.
|
|---|
| opt_isCumulative
: boolean=
Optional parameter that indicates
whether or not the counter event should be counted cumulatively.
|
| id
: string
The exit ID.
|
|---|
| opt_url
: string=
The url to navigate to. This URL can still be modified in Studio and DCM. If you want this URL to be uneditable Studio and DCM, use the
exitOverride
method instead. |
| id
: string
String ID of exit.
|
|---|
| opt_queryString
: string=
Desired query string value(s) to append to
the end of the exit URL.
|
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.| opt_disableTracking
: boolean=
Whether or not this expand causes an
event to be logged. This is useful for creatives that start out
expanded and don't want to log the first expand.
|
|---|
| opt_expandProperties
: Object=
The properties to expand with. This
is used in mobile environments supporting MRAID. The object will
look like the following:
. |
studio.Enabler#requestCollapse()
. Enabler.addEventListener(
studio.events.StudioEvent.COLLAPSE_START,
function() {
// collapse action
Enabler.finishCollapse();
});
Enabler.requestCollapse();
This function is only applicable for expandable ad formats.| methodName
: studio.sdk.MraidMethod
The method name to invoke on the
mraid object. You can also use dot accessors to access subobjects if
they are ever introduced. For instance, 'package.method', would call
window.mraid.package.method().
|
|---|
| opt_args
: Array=
The arguments to invoke the method with.
|
| opt_callback
: function(?Object)=
A callback that gets invoked with
the results of the function call.
|
| scriptUrl
: string
The url of the script to load.
|
|---|
| opt_loadedCallback
: Function=
The callback to invoke when the script
is loaded.
|
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. Enabler.registerChargeableEventName("SWIPE");
| type
: string
The type of the event to listen for.
|
|---|
|
: function(*):*
|
{handleEvent:function(*):*
No description.
|
| opt_capture
: boolean=
In DOM-compliant browsers, this determines
whether the listener is fired during the capture or bubble phase
of the event.
|
| opt_handlerScope
: Object=
Object in whose scope to call the listener.
|
studio.Enabler#reportCustomVariableCount1(custom)
.
Deprecated
This tracks a click against the string parameter. The string must meet the following criteria:studio.Enabler#reportCustomVariableCount1(custom)
.
Deprecated
Tracks an impression against the string parameter. The string must meet the following criteria:studio.Enabler#requestCollapse()
. Enabler.addEventListener(
studio.events.StudioEvent.COLLAPSE_START,
function() {
// Do collapse action then...
Enabler.finishCollapse();
});
Enabler.requestCollapse();
This function is only applicable for expandable ad formats.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: Enabler.addEventListener(
studio.events.StudioEvent.EXPAND_START,
function(event) {
// For multi directional expands, direction to expand in can be
// obtained by calling Enabler.getExpandingDirection() (or
// from event.direction).
// Do expand action then...
Enabler.finishExpand();
});
Enabler.requestExpand();
This function is only applicable for expandable ad formats.| opt_width
: number=
Width we would like to expand to in pixels.
|
|---|
| opt_height
: number=
Height we would like to expand to in pixels.
|
| left
: number
The left offset to the collapsed portion of the ad.
|
|---|
| top
: number
The top offset to the collapsed portion of the ad.
|
| opt_expandedWidth
: number=
The expanded width of this asset.
|
| opt_expandedHeight
: number=
The expanded height of this asset.
|
| opt_startExpanded
: boolean=
Whether this asset starts expanded,
this will disable tracking, expansion timer, not log an interactive
impression when the initial requestExpand is called. Note: this
parameter is deprecated
.
|
| opt_isMultiDirectional
: boolean=
Whether this the ad supports
multidirectional expands. Note: this parameter is deprecated.
|
| name
: studio.sdk.hint.Hint
The name of the hint we want
to add.
|
|---|
| value
: string
The value of the hint we want to add.
|