Created
January 23, 2017 15:47
-
-
Save fraszczakszymon/dea82ce615731c392eceb99d18a018b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
#playerContainer { | |
background: #000; | |
height: 100%; | |
width: 100%; | |
} | |
.hidden { | |
display: none; | |
} | |
</style> | |
<div id="playerContainer" class="hidden"></div> | |
[%Additionalcreativecode%] | |
<script type="text/javascript"> | |
AdEngine_adType = 'forced_success'; | |
var vulcanResponse = {}, | |
player = '[%Player%]'.toLowerCase(), | |
playerContainer = document.getElementById('playerContainer'), | |
skin = '%%PATTERN:skin%%'; | |
function collapse() { | |
playerContainer.className = 'hidden'; | |
if ('[%Layout%]' !== 'dynamic') { | |
return; | |
} | |
top.postMessage('{"AdEngine":{"action":"collapse","slotName":"%%PATTERN:pos%%"}}', '*'); | |
} | |
function expand() { | |
playerContainer.className = ''; | |
if ('[%Layout%]' !== 'dynamic') { | |
return; | |
} | |
top.postMessage('{"AdEngine":{"action":"expand","slotName":"%%PATTERN:pos%%"}}', '*'); | |
} | |
function makeResponsive(aspectRatio) { | |
top.postMessage('{"AdEngine":{"action":"make-responsive","slotName":"%%PATTERN:pos%%","aspectRatio":' + aspectRatio + '}}', '*'); | |
} | |
function isDebugEnabled() { | |
return ['_adtest', '_project43'].indexOf('%%PATTERN:s1%%') !== -1 || top.location.href.indexOf('wikia_debug_mode=1') !== -1; | |
} | |
function debug() { | |
if (isDebugEnabled()) { | |
console.info.apply(this, arguments); | |
} | |
} | |
function trackUAT() { | |
if (!'[%UATdimension%]' || !'[%UATpayload%]') { | |
return; | |
} | |
var dimension = '[%UATdimension%]', | |
payload = '[%UATpayload%]'; | |
debug('trackUAT', dimension, payload, skin); | |
switch (skin) { | |
case 'oasis': | |
top.ga('set', 'dimension' + dimension, payload); | |
top.ga('special.set', 'dimension' + dimension, payload); | |
top.guaTrackEvent('ads-UAT', 'impression', payload, 0, true); | |
break; | |
case 'mercury': | |
top.M.tracker.UniversalAnalytics.setDimension(dimension, payload); | |
top.M.tracker.UniversalAnalytics.track('ads-UAT', 'impression', payload, 0, true); | |
break; | |
default: | |
debug('unknown skin'); | |
break; | |
} | |
} | |
function trackGAEvent(eventName, label) { | |
if ('[%GA%]' !== 'enabled') { | |
return; | |
} | |
label = label || ''; | |
debug('GA event', eventName, label); | |
switch (skin) { | |
case 'oasis': | |
top.guaTrackAdEvent('ad/' + player + '/event/' + eventName, 'pos=%%PATTERN:pos%%', label, 0, true); | |
break; | |
case 'mercury': | |
top.Mercury.Modules.Ads.gaTrackAdEvent('ad/' + player + '/event/' + eventName, 'pos=%%PATTERN:pos%%', label, 0, true); | |
break; | |
} | |
} | |
function trackPlaywireEvent(Bolt, playerId, eventName) { | |
debug('Playwire event', eventName); | |
var advertiser = vulcanResponse.advertiser || 'unknown', | |
network = vulcanResponse.network || 'unknown', | |
label = network + '/' + advertiser; | |
eventName = eventName || 'unknown'; | |
debug(eventName, label); | |
trackGAEvent(eventName, label); | |
} | |
function trackPorvataEvent(event) { | |
debug('Porvata event', event); | |
var eventName = 'unknown', | |
advertiser = vulcanResponse.advertiser || 'unknown', | |
network = vulcanResponse.network || 'unknown', | |
label = network + '/' + advertiser, | |
errorCode = ''; | |
if (event && event.type) { | |
eventName = 'ima_' + event.type; | |
} | |
if (eventName === 'ima_adError') { | |
errorCode = event.getError && event.getError().getErrorCode(); | |
label = label + '/' + errorCode; | |
} | |
debug(eventName, label); | |
trackGAEvent(eventName, label); | |
} | |
function getVulcanResponse() { | |
var bestResponse, | |
slots = (top.rubiconVulcan && top.rubiconVulcan.getAllSlots()) || []; | |
slots.forEach(function (slot) { | |
if (slot.id === '%%PATTERN:pos%%') { | |
bestResponse = slot.getBestCpm(); | |
} | |
}); | |
bestResponse = bestResponse || {}; | |
if (top.location.href.indexOf('wikia_debug_vast=1') !== -1) { | |
bestResponse.depot_url = 'https://loopme.me/api/vast/ads?appId=e18c19fa43&vast=2&uid=1234&ip=8.8.8.8&bundleid=com.loopme&appname=my_talking_pet&sdk=16.2&exchange=admarvel'; | |
} | |
debug('Vulcan response', bestResponse); | |
return bestResponse; | |
} | |
if ('[%Responsive%]' === 'true') { | |
makeResponsive(1.77777777778); | |
} | |
vulcanResponse = getVulcanResponse(); | |
collapse(); | |
debug('Player template 1.1.3', player); | |
trackGAEvent('init'); | |
if (player === 'playwire') { | |
// Playwire player | |
playerContainer.className = ''; | |
top.loadCustomAd && top.loadCustomAd({ | |
type: 'playwire', | |
adProduct: 'vulcan', | |
autoPlay: true, | |
publisherId: '[%Playwirepublisherid%]', | |
videoId: '[%Playwirevideoid%]', | |
vastUrl: vulcanResponse.depot_url, | |
container: playerContainer, | |
slotName: '%%PATTERN:pos%%', | |
src: '%%PATTERN:src%%', | |
width: %%WIDTH%%, | |
height: %%HEIGHT%%, | |
lineItemId: '%eaid!', | |
creativeId: '%ecid!', | |
trackingDisabled: false, | |
onReady: function (Bolt, playerId) { | |
trackGAEvent('ready'); | |
trackUAT(); | |
container.addEventListener('mouseenter', function () { | |
Bolt.unmuteMedia(playerId); | |
}); | |
container.addEventListener('mouseleave', function () { | |
Bolt.muteMedia(playerId); | |
}); | |
Bolt.on(playerId, Bolt.BOLT_CONTENT_STARTED, function () { | |
Bolt.pauseMedia(playerId); | |
if ('[%Layout%]' === 'dynamic') { | |
Bolt.removeVideo(playerId , false); | |
collapse(); | |
} | |
}); | |
Bolt.on(playerId, Bolt.BOLT_AD_STARTED, function () { | |
Bolt.muteMedia(playerId); | |
if ('[%Layout%]' === 'dynamic') { | |
expand(); | |
Bolt.resizeVideo(document.body.scrollWidth, document.body.scrollHeight); | |
} | |
}); | |
if ('[%Responsive%]' === 'true') { | |
Bolt.resizeVideo(window.innerWidth, window.innerHeight); | |
makeResponsive(1.77777777778); | |
} | |
Bolt.on(playerId, Bolt.BOLT_AD_REQUEST_START, trackPlaywireEvent); | |
Bolt.on(playerId, Bolt.BOLT_AD_STARTED, trackPlaywireEvent); | |
Bolt.on(playerId, Bolt.BOLT_AD_ERROR, trackPlaywireEvent); | |
Bolt.on(playerId, Bolt.BOLT_AD_COMPLETE, trackPlaywireEvent); | |
Bolt.on(playerId, Bolt.BOLT_CONTENT_STARTED, trackPlaywireEvent); | |
Bolt.on(playerId, Bolt.BOLT_CONTENT_COMPLETE, trackPlaywireEvent); | |
Bolt.muteMedia(playerId); | |
Bolt.playMedia(playerId); | |
trackGAEvent('play'); | |
} | |
}); | |
} else { | |
// Porvata player | |
top.loadCustomAd && top.loadCustomAd({ | |
type: 'porvata', | |
adProduct: 'vulcan', | |
autoPlay: true, | |
vastUrl: vulcanResponse.depot_url, | |
container: playerContainer, | |
width: %%WIDTH%%, | |
height: %%HEIGHT%%, | |
slotName: '%%PATTERN:pos%%', | |
src: '%%PATTERN:src%%', | |
lineItemId: '%eaid!', | |
creativeId: '%ecid!', | |
trackingDisabled: false, | |
onReady: function (video) { | |
trackGAEvent('ready'); | |
trackUAT(); | |
video.addEventListener('loaded', function () { | |
var adsManager = video.ima.getAdsManager(), | |
videoContainer = video.container || video.ima.container; | |
setTimeout(function () { | |
adsManager.setVolume(0); | |
}); | |
videoContainer.classList.remove('hidden'); | |
playerContainer.addEventListener('mouseenter', function () { | |
adsManager.setVolume(1); | |
}); | |
playerContainer.addEventListener('mouseleave', function () { | |
adsManager.setVolume(0); | |
}); | |
}); | |
video.addEventListener('start', function () { | |
var adsManager = video.ima.adsManager || video.ima.getAdsManager(); | |
setTimeout(function () { | |
adsManager.setVolume(0); | |
}); | |
expand(); | |
if ('[%Responsive%]' === 'true') { | |
video.resize(document.body.scrollWidth, document.body.scrollHeight); | |
} | |
}); | |
video.addEventListener('allAdsCompleted', function () { | |
video.ima.getAdsManager().pause(); | |
collapse(); | |
}); | |
if ('[%Responsive%]' === 'true') { | |
top.window.addEventListener('resize', function () { | |
video.resize(window.innerWidth, window.innerHeight); | |
makeResponsive(1.77777777778); | |
}); | |
} | |
video.addEventListener('loaded', trackPorvataEvent); | |
video.addEventListener('start', trackPorvataEvent); | |
video.addEventListener('complete', trackPorvataEvent); | |
video.addEventListener('adError', trackPorvataEvent); | |
trackGAEvent('play'); | |
} | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment