0% found this document useful (0 votes)
16K views

Ad Js Injection - Js

The document defines helper functions for handling interactions with Vungle ads. It includes functions for setting SK presentation events, dismissing SK overlays, handling click/touch events, and sending messages between windows to report events and pass data. On page load, it will send an "ad-event-loaded" message. It also defines how messages from the parent window will be received and processed.

Uploaded by

Walison Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16K views

Ad Js Injection - Js

The document defines helper functions for handling interactions with Vungle ads. It includes functions for setting SK presentation events, dismissing SK overlays, handling click/touch events, and sending messages between windows to report events and pass data. On page load, it will send an "ad-event-loaded" message. It also defines how messages from the parent window will be received and processed.

Uploaded by

Walison Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Storage for tokens

var VungleHelper = {};

VungleHelper.setSKPresentation = function(eventType, presentationType,


presentationOptions = null) {

var creativeEventTypes = { skPresentationASOIInteraction: 'asoi-interaction',


skPresentationASOIComplete: 'asoi-complete',
skPresentationCTAClick: 'cta-click'};

//Check if creative event matches supported events


var objectKey = Object.keys(creativeEventTypes).find(key =>
creativeEventTypes[key] === eventType);

if (objectKey) {
var skPresentationSettings = {};
skPresentationSettings[objectKey] = {presentationType: presentationType,
presentationOptions: presentationOptions};
window.sendMessage('ad-event-sk-presentation', skPresentationSettings);
}
};

VungleHelper.dismissSKOverlay = function() {
window.sendMessage('ad-event-sk-dismiss');
};

var clickEvent = (function() {


if ('ontouchstart' in document.documentElement === true)
return 'touchstart';
else
return 'click';
})();

// Legacy IEC v1 Event


window.callSDK = function(action) {
parent.postMessage(action, '*');
};

// Legacy IEC v2 Event


window.actionClicked = function(action) {
parent.postMessage(action, '*');
};

// Adwords Open Event


window.open = function() {
//Open should always redirect to CTA Download
parent.postMessage('download', '*');
};

window.addEventListener(clickEvent, function() {
parent.postMessage('interacted', "*");
});

document.addEventListener('DOMContentLoaded', function() {
window.sendMessage('ad-event-loaded')
})

function sendEvent(name, obj) {


if(typeof obj === 'undefined'){obj = {}}
var event = new CustomEvent(name, { 'detail': obj });
window.dispatchEvent(event);
}

// Disable Event Propagation for touchstart event listeners


Event.prototype.stopPropagation = function() {}

window.sendMessage = function(title, obj) {


// Make sure you are sending a string, and to stringify JSON
var data = {
title: title,
content: obj
}

window.parent.postMessage(data, '*');
};

window.receiveMessage = function(e) {
if (e.data.length === 0 || typeof e.data.title === 'undefined')
return

window.processMessage(e.data.title, e.data.content || {})


sendEvent(e.data.title, e.data.content || {})
}

window.processMessage = function(title, content) {


switch (title) {
case 'ad-event-init':
VungleHelper.tokens = content.tokens;
VungleHelper.closeDelay = content.closeDelay;
VungleHelper.rewardedAd = content.rewardedAd;
break;
}
}

window.addEventListener('message', window.receiveMessage);

window.sendInstructions = function() {
window.sendMessage('ad-event-child-instructions', window.vungleSettings)
}

if (typeof window.vungleSettings !== 'undefined')


window.sendInstructions()

You might also like