Javascript API

Connatix Javascript API is an interface that allows clients to receive events on AdUnit loads. It also gives clients control over several behaviors in order to provide a much deeper and more native integration with their websites.

 

The initialization of the AdUnit

Compared to the regular integration with Connatix Javascript, an API type of integration returns an interface linked to the unit that is being initialized. The first part of the integration is the callback function, which is called when our unit is being initialized. The second part occurs after the unit is bound to the needed events, which will then be initialized by calling the init function.

 
e.g.

 

 <script type="text/javascript">
                       window["player_callback"] = function(unit){
                           unit.on('ready',function(){})
                           .on('videoPause', function(){})
                           .on('videoPlay', function(){})
                           .init(config);
                         };
                       (function (cnxwindow, cnxdocument ,container, token, callback) {
                            var s = cnxdocument.createElement('script');
                             s.async = 1;
                             s.src = 'https://cdn.connatix.com/min/connatix.renderer.infeed.min.js';
                             s.setAttribute('data-connatix-token',token);
                             s.setAttribute('ext-interface-callback',callback);
                             container.appendChild(s);
                       })(window, document ,[container],[provided_token],[callback_func]);
        </script>
 

Parameter

1. Container:  DOM Element where the unit will be inserted. If the unit will be inserted in the <head> section, then it will automatically be inserted in the configured position from the Connatix Console
2. Token: AdUnit token provided by your account manager
3. Callback Function: the globally defined function that receives the interface object used to control the AdUnit
 

Functions

Name

Arguments

Returns

Description

init config(optional)- type JSON. The config object is detailed below  - Triggers the initialization of the AdUnit. If this method is not called in the callback function, nothing will happen
play (video) - - Plays the current content video
pause (video) - - Pauses the current content video
stop (video) - - Stops the current content video
getVolume (video) - float Returns the currently set volume of the player 0 -> 1
setVolume (video) float - Sets the current volume of the player with a value between 0 and 1
mute (video) - - Mutes the current content video
unmute (video) - - Unmutes the current content video
getCurrentTime (video) - float The current position of the player in seconds
getDuration (video) - float The total length of the content in seconds
isMuted (video) - bool Returns true if the player is currently muted
destroy - - Destroys the AdUnit by removing all players and the placement container

 

Config Object

A JSON object containing all necessary configuration statements for the player’s initialization. Used in init function. 

This is an optional object

Attributes

Description

Type

mediaItems

array of mediaItems (see definition below)

array of JSON objects

advertising

 will contain all the settings for advertising 

 

JSON Object 

 

MediaItem Object

Attributes

Description

Type

id

 identifier of the media. Will be used in events sent by the player to identify it

String

title

 

String

description

 

String

src

 URL source of the media

Array

subtitlesTrack

 URL to a .vtt file for that media

URL as String

image

 URL of the medias image

 URL as string

 

Advertising Object

Attribute

Description

Type

macros 

 JSON object. Will contain key-value pairs that will be replaced in the Ad Sources URL. Key name will be replaced in the AdSources URL with the value

Ex: {

   name1:value1

}

JSON Object

 

Events

Name

Description

Event Data 

Media Item Availability

no-fill Triggered when the request couldn't be fulfilled   Video
ready Triggered when the AdUnit has been rendered and control is available   Video, Stories, Highlights
videoPlay Triggered when the content video has started playing   Video
videoPause Triggered when the content video paused   Video
videoEnd Triggered when the content video has ended. Depending on the configuration of the AdUnit, after this event, another content video can start and will trigger the videoPlay event again    Video
adStart Triggered when a Video Ad is displayed   Video
adEnd Triggered when a Video Ad is ended.   Video
readMore Triggered once the Read More is clicked and returns the URL associated with the highlights item   Highlights
timeChanged    Triggered when the playback time changed.   Video
AdCompanions

When a video ad will have a companion ad available we will send the event to notify this.

The external listener can implement rendering the companion as they see fit.

Companion Metadata - type JSON object. Will be defined below 

Video

 

Companion Metadata Object

Attribute

Description

Type

companions 

array of companion ads. 

Will be defined below as Companion Ad Metadata

 

array JSON Object

tag

The URL of the ad source that is currently playing

string

 

Companion Ad Metadata Object

Attribute

Description

Type

click URL to link to when clicking the companion. Only available if the type is static String
height The height of the companion in pixels Number
resource The URL to the static/iframe resource, or the raw HTML content String
type The type of the creative: static, iframe, or HTML String
width The width of the companion in pixels Number
creativeview An array of included creativeview event tracking pixels (URL's) Array
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

  • Avatar
    Pragya

     I am trying to get alert when there will be no ad but not able to do so, Please help me how will I accomplish that. And what are the ways to get the alert on 'no-fill' event.

    Note-  'adEnd' event is missed in this documentation, Please add this.

    Edited by Pragya

Please sign in to leave a comment.