The creative API contains methods that you can use in your ad code. The API methods are exposed to the ad on two objects, AdKit and EB, depending on the loader script used to initialize the API. The loader script determines accessibility:
-
When using AdKit, both AdKit and EB are accessible.
-
When using EBLoader, only the EB object is accessible.
For more information, see Load and Initialize the API.
Tracks default and custom click-through interactions. Click-through interactions measure events that click-through to the default URL or the specified URL (in the system or the code).
Note
Note: This method is equivalent to EB.clickthrough()
.
function checkIfAdKitReady(event) { adkit.onReady(function() { document.getElementById('szk-click-btn').addEventListener('click', handleClick); } } function handleClick() { // Default clickthrough with url defined in platform adkit.clickthrough(); // Custom clickthrough named "Customized-Click-1" with url defined in platform adkit.clickthrough('Customized-Click-1'); // Custom clickthrough named "Customized-Click-2" with url defined in code adkit.clickthrough('Customized-Click-2', "https://www.sizmek.com"); } window.addEventListener('load', checkIfAdKitReady);
Important
Important: This method is still being tested and is not exposed externally.
Tracks a user action and opens a URL, if defined. This type of interaction will not affect the CTR Rate since it is not tracked as a user click-through.
Note
Note: This method is equivalent to EB.userActionCounter()
.
function checkIfAdKitReady(event) { adkit.onReady(function() { document.getElementById('szk-user-btn').addEventListener('click', handleClick); } } function handleClick() { // Custom clickthrough named "Customized-User-Action-1" with no url or url defined in platform adkit.customInteraction('Customized-User-Action-1'); // Custom clickthrough named "Customized-User-Action-2" with url defined in code adkit.customInteraction('Customized-User-Action-2', 'https://www.sizmek.com'); } window.addEventListener('load', checkIfAdKitReady);
Reports a user swipe event.
Note
Note: This method is equivalent to EB.userSwipe()
.
// This example uses jQuery to simplify the creation of the swipe event as there is no native event for it in javascript function checkIfAdKitReady(event) { adkit.onReady(function() { $(window).on('swipe', handleSwipe); } } function handleSwipe() { adkit.userSwipe(); } window.addEventListener('load', checkIfAdKitReady);
Requests the expansion of an ad panel.
Note
Note: This method is equivalent to EB.expand()
.
Name |
Type |
Required |
Description |
---|---|---|---|
|
Object |
Optional |
Contains the Expand properties. If not defined, and the Show single panel at a time is set to false, all panels will expand. Otherwise, only the default panel will expand. |
Parameters of the expansion_properties_object
:
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Optional |
Name of the panel to expand. |
|
String |
Optional |
Action initiator type. The options include:
|
|
Boolean |
Optional |
When using In-App serving, you can determine whether to use the standard MRAID close button or a custom button. The default value is false and shows the standard MRAID close button. |
|
Object |
Optional |
Sets the animation for the expand action. |
Parameters of the animate
object:
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Required |
Sets the clip as a string in the CSS.
For example: |
|
Integer |
Required |
Sets the opacity in the CSS as an integer. |
|
Integer |
Required |
Sets the animation duration in milliseconds. |
|
Integer |
Required |
Sets the animation motion type. The options include:
|
|
Object |
Required |
Defines the animation initial state. |
Parameters of the init
object:
function checkIfAdKitReady(event) { adkit.onReady(function() { document.getElementById('szk-expand-btn').addEventListener('click', handleExpand); } } function handleExpand() { adkit.expand({ panelName: "panel_1", useCustomClose: false, animate: { clip: "rect(0, 100%, 100%, 0)", duration: 2000, easing: adkit.Animation.Easing.EASE_IN, opacity: 1, init: { clip: "rect(0, 100%, 0, 100%)", opacity: 0 } } }); } window.addEventListener('load', checkIfAdKitReady);
Requests the collapse of an ad panel.
Note
Note: This method is equivalent to EB.collapse()
.
Name |
Type |
Required |
Description |
---|---|---|---|
|
Object |
Optional |
Contains the Collapse properties. If not defined, and the Show single panel at a time is set to false, all panels will collapse. |
Parameters of the collapse_properties_object
:
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Optional |
Name of the panel to collapse. |
|
String |
Optional |
Action initiator type. The options include:
|
|
Object |
Optional |
Sets the animation for the collapse action. |
Parameters of the animate
object:
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Required |
Sets the clip as a string in the CSS.
For example: |
|
Integer |
Required |
Sets the opacity in the CSS as an integer. |
|
Integer |
Required |
Sets the animation duration in milliseconds. |
|
Integer |
Required |
Sets the animation motion type. The options include:
|
|
Object |
Required |
Defines the animation initial state. |
function checkIfAdKitReady(event) { adkit.onReady(function() { document.getElementById('szk-collapse-btn').addEventListener('click', handleCollapse); } } function handleCollapse() { adkit.collapse({ panelName: "panel_1", animate: { clip: "rect(0, 100%, 0, 100%)", duration: 2000, easing: adkit.Animation.Easing.EASE_IN, opacity: 0, init: { clip: "rect(0, 100%, 100%, 0)", opacity: 1 } } }); } window.addEventListener('load', checkIfAdKitReady);
Runs any time a panel is expanded in our ad. It can include a callback function as a parameter. which receives an object with the expansion information.
function checkIfAdKitReady(event) { adkit.onReady(startAnimation); } function startAnimation() { adkit.onExpand(panelExpanded); } function panelExpanded(expandInfo){ // The expandInfo parameter contains the expanded panel name var panelExpandedName = expandInfo.data.panelName; } window.addEventListener('load', checkIfAdKitReady);
Runs any time a panel is collapsed in our ad. It can include a callback function as a parameter. which receives an object with the expansion information.
function checkIfAdKitReady(event) { adkit.onReady(startAnimation); } function startAnimation() { adkit.onCollapse(panelCollapsed); } function panelCollapsed(collapseInfo){ // The collapseInfoparameter contains the collapsed panel name var panelCollapsedName = collapseInfo.data.panelName; } window.addEventListener('load', checkIfAdKitReady);
Shows the ad banner (contracted unit) after being hidden using the adkit.hideBanner()
method.
Hides the ad banner (contracted unit). The banner resides in the HTML page, but will not be visible.
Shows the ad panel after being hidden using the adkit.hidePanel
method.
function checkIfAdKitReady(event) { adkit.onReady(startAnimation); } function startAnimation() { // By default, a panel unit is visible after the expansion, this assumes the panel was hidden using the method adkit.hidePanel adkit.showPanel("Panel1"); } window.addEventListener('load', checkIfAdKitReady);
Hides the ad panel. The panel resides in the HTML page, but will not be visible.
Calls another function once the creative API is initialized and ready to be used.
Used to call another function when the ad dimensions change. This will only be triggered for ad resize, not for browser resize.
Used to call another function when the ad visibility state changes. The visibility will be applied to the unit that calls this function. If you use it in a panel, the visibility will apply to that panel.
function checkIfAdKitReady(event) { adkit.onReady(startAnimation); } function startAnimation() { adkit.onVisibilityChanged(handleVisibilityChanged); } function handleVisibilityChanged(visibilityInfo){ // Here you can do something depending on the visible percentage if (visibilityInfo.percentage > 75) { // Do something, e.g. play video, start animation,... } } window.addEventListener('load', checkIfAdKitReady);
Retrieves a component by ID. The component needs to be previously defined in the AdKit configuration file (config.js
) or in Ad Builder.
Retrieves all components of a specified type within an array.
var components; function checkIfAdKitReady(event) { adkit.onReady(startAnimation); } function startAnimation() { components = adkit.getComponentsByType('adkit-media'); components.forEach(function(comp) { // This example will pause all the adkit-media components in the creative. comp.pause(); }); } window.addEventListener('load', checkIfAdKitReady);
Returns the content of a dynamic field when working on a DCO ad. Dynamic elements are defined within the config.js
file of the template. For more information, see Add Dynamic Elements to Your HTML Ads Using a Code Editor.
Triggers a click-through and associates it with a specific catalog version/product in catalog ads.
Returns the requested catalog versions/products either as an argument of the callback function or null if the catalog versions/products cannot be acquired.
Name |
Type |
Required |
Description |
---|---|---|---|
|
Integer |
Required |
Index of the first catalog version/product to acquire. |
|
Integer |
Required |
Index of the last catalog version/product to acquire. |
|
Function |
Required |
Function executed when all the requested catalog versions/products are ready. |
Parameters of the callback_function
object:
Name |
Type |
Required |
Description |
---|---|---|---|
|
Integer |
Required |
Index of the first catalog version/product to acquire. |
|
Integer |
Required |
Index of the last catalog version/product to acquire. If not specified, catalog versions/products count will be used. |
|
Function |
Required |
Function executed when all the requested catalog versions/products are ready. |
function checkIfAdKitReady(event) { adkit.onReady(handleVersions); } function handleVersions(){ adkit.getVersions(1, 5, function(versions){ if (versions) { for (var i = versions.startVersionNum; i <= versions.endVersionNum; i++) { var version = versions.versionData[i]; var value = version['logo'].value; } } }); } window.addEventListener('load', checkIfAdKitReady);
Returns the number of viable catalog versions/products returned by the ad server.
Returns the value defined for minimum versions to load.
Returns the smart item object for catalog version/product index and smart item key combination (null if not defined) as an argument of the callback function.
This can be used to retrieve specific smart item data from a specific catalog version/product, rather than the entire catalog version/product.
Tracks default and custom click-through interactions. Click-through interactions measure events that click-through to the default URL or the specified URL (in the system or the code).
Note
Note: This method is equivalent to adkit.clickthrough()
and adkit.clickThrough()
.
function checkIfAdKitReady(event) { adkit.onReady(function() { document.getElementById('szk-click-btn').addEventListener('click', handleClick); } } function handleClick() { // Default clickthrough with url defined in platform EB.clickthrough(); // Custom clickthrough named "Customized-Click-1" with url defined in platform EB.clickthrough('Customized-Click-1'); // Custom clickthrough named "Customized-Click-2" with url defined in code EB.clickthrough('Customized-Click-2', "https://www.sizmek.com"); } window.addEventListener('load', checkIfAdKitReady);
Tracks an user action and opens a URL if defined. This type of interaction will not affect the CTR rate, since it will not be tracked as a user click-through.
Note
Note: This method is equivalent to adkit.customInteraction()
.
function checkIfAdKitReady(event) { adkit.onReady(function() { document.getElementById('szk-user-btn').addEventListener('click', handleClick); } } function handleClick() { // Custom clickthrough named "Customized-User-Action-1" with no url or url defined in platform EB.userActionCounter('Customized-User-Action-1'); // Custom clickthrough named "Customized-User-Action-2" with url defined in code EB.userActionCounter('Customized-User-Action-2', 'https://www.sizmek.com'); } window.addEventListener('load', checkIfAdKitReady);
Tracks an automatic event counter custom interaction. Automatic event counter interactions measure ad events that are not triggered by user interactions, like progress points in a video. The method receives the name of the interaction to be tracked.
Reports a user swipe event.
Note
Note: This method is equivalent to adkit.userSwipe()
.
// This example uses jQuery to simplify the creation of the swipe event as there is no native event for it in javascript function checkIfAdKitReady(event) { adkit.onReady(function() { $(window).on('swipe', handleSwipe); } } function handleSwipe() { EB.userSwipe(); } window.addEventListener('load', checkIfAdKitReady);
Collapses all expanded panels that belong to the ad.
// This example uses jQuery to simplify the creation of the swipe event as there is no native event for it in javascript function checkIfAdKitReady(event) { adkit.onReady(function() { // This example will close all panels when this funcion is executed EB.closeAd(); } } window.addEventListener('load', checkIfAdKitReady);
Request the expansion of an ad panel according to the parameters that were specified in initExpansionParams()
/setExpansionParams()
, or according to the optional specified expansionParams
.
Note
Note: This method is equivalent to adkit.expand()
.
Name |
Type |
Required |
Description |
---|---|---|---|
|
Object |
Optional |
Relative path to the video asset that stopped playing. |
Parameters of the expansion_properties_object
object:
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Optional |
Name of the panel to expand. If not defined, and the Show single panel at a time is set to false, all panels will expand. Otherwise, only the default panel will expand. |
|
String |
Optional |
Action initiator type. The options include:
|
|
Number |
Optional |
Indicates (in milliseconds) when the panel should collapse automatically after expanding. It only works for Expandable Banner and not Single Expandable ad formats. |
|
Number |
Optional |
The left offset (x-coordinate) of the collapsed-state rectangle relative to the expanded-state rectangle. |
|
Number |
Optional |
The top offset (y-coordinate) of the collapsed-state rectangle relative to the expanded-state rectangle. |
|
Number |
Optional |
Width of the expanded state rectangle. |
|
Number |
Optional |
Height of the expanded state rectangle. |
function checkIfAdKitReady(event) { adkit.onReady(function() { document.getElementById('szk-expand-btn').addEventListener('click', handleExpand); } } function handleExpand() { // This example will expand the panel called 'panel_1' as user initiated and will auto collapse after 10 seconds EB.expand({ panelName: "panel_1", actionType: EBG.ActionType.USER, autoCollapse: 10000 }); } window.addEventListener('load', checkIfAdKitReady);
Sends a request to collapse the creative. If the ad format is Expandable Banner, this request removes a panel from the page. If the ad format is Single Expandable, the creative is resized according to the parameters specified in a prior call to initExpansionParams()/setExpansionParams().
Note
Note: This method is equivalent to adkit.collapse()
.
Allows hiding ad elements by setting visibility to hidden. If no options are passed, the target element is the banner.
Name |
Type |
Required |
Description |
---|---|---|---|
|
Object |
Optional |
Object with properties
|
Expose an ad part (by setting visibility to visible) after EB.hideAdPart()
was called. If no options are passed, the target element is the banner.
Name |
Type |
Required |
Description |
---|---|---|---|
|
Object |
Optional |
Object with properties
|
Returns a Boolean value that indicates whether the expandable ad was configured (in AAS) to auto-expand. In local mode, there is no configuration information from AAS, so this method will always return true.
Sets or resets a timer to auto-collapse a panel after a specified number of milliseconds. Normally, you would define an auto-collapse by using one of the options given in the parameters to the EB.expand({...})
command, but you can also use resetCollapseTimer
to do it. This method can be called from the panel which will be auto-collapsed, from any other panel, or from the banner.
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Optional |
Name of the panel for which the auto-collapse timer will be modified. If not supplied, undefined, or empty, and if the command came from a panel, that will be the panel chosen for the auto-collapse. If the command came from the banner, the default panel will be chosen. |
|
Number |
Mandatory |
Number of milliseconds to reset the collapse timer. |
Cancels an auto-collapse timer for a panel that was previous set by the EB.resetCollpaseTimer
or EB.expand
methods. This method can be called from the panel which will be auto-collapsed, from any other panel, or even from the banner.
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Optional |
Name of the panel for which the auto-collapse timer will be modified. If not supplied, undefined, or empty, and if the command came from a panel, that will be the panel chosen for the auto-collapse. If the command came from the banner, the default panel will be chosen. |
Initializes the expansion parameters prior to using expand()
and collapse()
. If used, this must be called in the main HTML file of the Workspace and not in any external JavaScript.
Note
Notes:
-
This function does not actually have any effect during runtime, but it is mandatory to call it from the ad’s main HTML file since it is scanned by AAS for the initial positioning of the ad.
-
This applies to Single Expandable and related ad formats only; it does not affect Expandable Banner and related formats.
Name |
Type |
Required |
Description |
---|---|---|---|
|
Number |
Required |
The left offset (x-coordinate) of the collapsed-state rectangle relative to the expanded-state rectangle. |
|
Number |
Required |
The top offset (y-coordinate) of the collapsed-state rectangle relative to the expanded-state rectangle. |
|
Number |
Required |
Width of the expanded state rectangle. |
|
Number |
Required |
Height of the expanded state rectangle. |
function onInit() { EB.initExpansionParams(0, 0, 300, 350); }
By default, the banner expands downwards. You can change the expansion direction as shown in these examples:
For a 728x90 pixel banner expanding to a 728x200 pixel panel:
-
Expand Down:
EB.initExpansionParams(0,0,728,200);
-
Expand Up:
EB.initExpansionParams(0,110,728,200);
Changes the expansion parameters at runtime. The parameters take effect the next time expand()
and collapse()
are used.
Name |
Type |
Required |
Description |
---|---|---|---|
|
Number |
Required |
The left offset (x-coordinate) of the collapsed-state rectangle relative to the expanded-state rectangle. |
|
Number |
Required |
The top offset (y-coordinate) of the collapsed-state rectangle relative to the expanded-state rectangle. |
|
Number |
Required |
Width of the expanded state rectangle. |
|
Number |
Required |
Height of the expanded state rectangle. |
Adds a listener for an event and specifies a callback handler.
Name |
Type |
Required |
Description |
---|---|---|---|
|
Integer |
Required |
Name of the event for which the method is listening. Accepts different arguments depending on which additional modules are loaded. To view a list of events, see Events. |
|
Function |
Required |
Function called when the event is dispatched. |
|
Object |
Optional |
Object that will be bound to object |
The getSDKData
method returns an object with all of the SDK data. Only available when serving in an MRAID-compliant application; otherwise, the value will be null.
Verifies if the browser supports the specified HTML feature using Modernizr. The function will return true or false depending on the browser support for the feature requested.
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Required |
Identifies the feature that is being checked. For more information about Modernizr, see Modernizr Documentation. |
Returns information about a file in your Workspace. In local mode (before uploading), it will return null.
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Required |
Path of the file relative to your ad's main |
|
Number |
Optional |
Ordinal number of the file, if it is defined as an additional asset. |
Response Parameters:
Name |
Type |
Required |
Description |
---|---|---|---|
|
Number |
Appears if not null |
Unique ID for the asset on AAS servers. |
|
Number |
Will be -1 where |
|
|
String |
Relative path to the asset on AAS display servers (CDN). This is normally all you would need to use for the URL to load the asset. To get a full absolute URL, you should prepend the base URL from theEB.resourcePath [string] property. |
|
|
Number |
Indicates whether full-screen should be enabled for the asset. Only relevant for Flash Video. (Deprecated) |
|
|
Number |
Height of the asset, in pixels, if relevant. |
|
|
Null |
Deprecated. |
|
|
Number |
Index number of the file in the Additional Assets list. Usually zero for ordinary workspace assets. |
|
|
Number |
Returns a number to represent the file type of the asset. The possible return values include:
|
|
|
Number |
Width of the asset, in pixels, if relevant. |
//returns information about index.html file: var assetProps = EB.getAssetProps("index.html"); // returns information about additional asset 1. // note: if trying to retrieve information about an additional asset it will override the localpath property. // In which case one should enter an empty string when trying to get information about additional assets: var assetProps = EB.getAssetProps("",1); //Get the width and height of the asset: var assetWidth = assetProps.width; var assetHeight = assetProps.height;
Returns the URL of a valid asset file. Returns "" if the asset was not located. When using a path to refer to assets using EB.getAssetUrl
, the path is always relative to the main (root) folder. This means that if EB.getAssetUrl
is invoked from the banner or from one of the panels, the path for assets is relative to the root folder, not the folder where the current HTML file resides.
For example: If there is a folder named assets under the root folder, with a video named myVideo.ogg in it, that asset is always accessed using EB.getAssetUrl('assets/myVideo.ogg', 1);
Returns the original dimensions of the banner, as designed. In the case of an In-Stream, adaptive, or responsive ad, this may not match the current dimensions if the creative has been resized. When this function is called from within an expandable panel, it returns the dimensions of the banner, not the panel.
Returns information about the viewability status of the ad (or panel if called from a panel in an expandable ad). The object returned will always have an available
property. If viewability data is not available, this property will be false and the object will have no other properties. If the collection of viewability data is enabled for the ad, this property will be true.
If viewability is enabled and the initial scan of viewability has completed, the object will also contain additional properties that describe the viewability status. If you get {available: true}
and no other properties, you need to wait (a few milliseconds) before trying again, so the viewability scan has time to complete.
Name |
Type |
Required |
Description |
---|---|---|---|
|
Boolean |
Always present |
Determines whether viewability data is being scanned or collected for this asset. |
|
String |
Optional |
Unique ID for the asset (banner or panel) on the page. |
|
Object |
Optional |
Miscellaneous data, usually only used by custom formats. |
|
Number |
Optional |
Percentage of the asset that is within the veiwport. |
|
Object |
Optional |
Object with |
|
Object |
Optional |
An object with the same structure as a DOMRect, describing a rectangle that is the portion of the asset that is within the viewport. Positioning coordinates are relative to the top left corner of the viewport. Contains the following properties:
|
// Check the visibility percentage of the ad when the window is resized or scrolled. //If the ad is 80% visible or higher play the video. // If the ad is below 80% visible then pause the video. window.addEventListener("resize", checkVisibilityState); window.addEventListener("scroll", checkVisibilityState); function checkVisibilityState(event) { var visibility = EB.getVisibilityData(); var video = document.getElementBy("video"); if (visibility.percentage >= 80) { video.play(); } else { video.pause(); } };
This method sends arbitrary data to the EBG object outside the creative iFrame. This function is useful for custom formats, or other ads that have a custom script attached, that listen for such messages.
Uses a user-agent to determine if the client is a mobile device.
Translates a relative URL into an absolute URL. The Base URL that is used will be the ad Workspace's address on the AAS CDN. This function is useful for referring to Workspace assets when served in an environment that does not support relative URLs.
myImage.src = EB.relativeToAbsolute("images/background.jpg"); /*This will return the absolute URL path. (An absolute or full path points to the same location in a file system, regardless of the current working directory.) For example: http://ds.serving-sys.com/resources/PROD/html5/45884/20180214/1074179787/34915138550104464/panels/default/images/background.jpg */
Remove the specified listener (subscription) from the specified event.
myImage.src = EB.relativeToAbsolute("images/background.jpg"); /*This will return the absolute URL path. (An absolute or full path points to the same location in a file system, regardless of the current working directory.) For example: http://ds.serving-sys.com/resources/PROD/html5/45884/20180214/1074179787/34915138550104464/panels/default/images/background.jpg */
Makes a request to show the default image defined for the ad, instead of the displayed rich banner.
Checks whether the EB object is fully initialized and available for API calls. The function will return TRUE or FALSE depending on the load status of the EB object.
Starts a timer to measure the duration of a custom interaction.
Stops a timer to measure the duration of a custom interaction.
Starts a video timer for the specified asset.
// This example assumes you have a video element with id 'video01' var videoElement; function checkIfAdKitReady(event) { adkit.onReady(function() { videoElement= document.getElementById("video01"); videoElement.addEventListener('play',function(){ EB.startVideoTimer('videos/video01.mp4'); } } } window.addEventListener('load', checkIfAdKitReady);
Stops a video timer for the specified asset.
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Required |
Relative path to the video asset that stopped playing. |
// This example assumes you have a video element with id 'video01' var videoElement; function checkIfAdKitReady(event) { adkit.onReady(function() { videoElement= document.getElementById("video01"); videoElement.addEventListener('pause',function(){ EB.stopVideoTimer('videos/video01.mp4'); } } } window.addEventListener('load', checkIfAdKitReady);
Tracks a video interaction for a specified asset.
Name |
Type |
Required |
Description |
---|---|---|---|
|
String |
Required |
Name of the video interaction. |
|
String |
Required |
Relative path to the video asset that stopped playing. |
|
Boolean |
Optional |
Default is false. |
// This example assumes you have a video element with id 'video01' var videoElement; function checkIfAdKitReady(event) { adkit.onReady(function() { videoElement= document.getElementById("video01"); videoElement.addEventListener('play',function(){ EB.videoInteraction(EBG.VideoInteraction.USER_INITIATED_VIDEO, "videos/video01.mp4"); } } } window.addEventListener('load', checkIfAdKitReady);
Comments