Skip to content

Instantly share code, notes, and snippets.

@fraszczakszymon
Last active December 2, 2016 20:03
Show Gist options
  • Save fraszczakszymon/e47c13875c0b6d5ab9a3651ff1353115 to your computer and use it in GitHub Desktop.
Save fraszczakszymon/e47c13875c0b6d5ab9a3651ff1353115 to your computer and use it in GitHub Desktop.
<style>
.hidden {
display: none;
}
#image, #player {
background: #000;
width: %%WIDTH%%px;
height: %%HEIGHT%%px;
}
/* REMOVE ME */
img {
margin-top: 57px;
}
</style>
<div id="player" class="hidden"></div>
<div id="image">
<a href="%%CLICK_URL_UNESC%%%%DEST_URL%%" target="_blank"><img src="%%FILE:JPG1%%" /></a>
</div>
<script>
function isDebugEnabled() {
return '%%PATTERN:s1%%' === '_adtest' || top.location.href.indexOf('wikia_debug_mode=1') !== -1;
}
function debug() {
if (isDebugEnabled()) {
console.info.apply(this, arguments);
}
}
debug('Porvata template 0.9.17');
if (isDebugEnabled()) {
top.ads.runtime.disableBtf = true;
top.ads.runtime.unblockHighlyViewableSlots = true;
}
function getVulcanResponse() {
var bestResponse,
slots = (top.rubiconVulcan && top.rubiconVulcan.getAllSlots()) || [];
slots.forEach(function (slot) {
if (slot.id === '%%PATTERN:pos%%') {
bestResponse = slot.getBestCpm();
}
});
return bestResponse || {};
}
function logGA(eventName) {
debug('Porvata event: ' + eventName);
top.window.guaTrackAdEvent('ad/porvata/event/' + eventName, 'pos=%%PATTERN:pos%%', '', 0, true);
}
function logGAads() {
debug.apply(this, arguments);
var event = 'unknown';
if (arguments && arguments.length && arguments.length === 2 && arguments[1].hasOwnProperty('type') ) {
event = arguments[1].type;
event = 'ima_' + event;
}
var advertiser = 'unknown',
network = 'unknown',
errorCode = '',
errorMessage = '',
label = 'unknown/unknown';
if (response && response.advertiser) {
advertiser = response.advertiser;
}
if (response && response.network) {
network = response.network;
}
label = network + '/' + advertiser;
if (event === 'ima_adError') {
errorCode = arguments[1].getError && arguments[1].getError().getErrorCode();
errorMessage = arguments[1].getError() && arguments[1].getError().getMessage();
label = label + '/' + errorCode + ':' + errorMessage;
}
debug('Porvata ad event: ' + event + ', ' + label);
top.window.guaTrackAdEvent('ad/porvata/event/' + event, 'pos=%%PATTERN:pos%%', label, 0, true);
}
var container = document.getElementById('player'),
response = getVulcanResponse();
logGA('porvataInit');
// force spotx vast:
// response.depot_url = 'https://search.spotxchange.com/vast/2.0/85394?vpaid=js&content_page_url=&cb=a6e35fcb88&player_width=640&player_height=480';
AdEngine_adType = 'forced_success';
top.loadCustomAd && top.loadCustomAd({
type: 'porvata',
vastUrl: response.depot_url,
container: container,
slotName: '%%PATTERN:pos%%',
src: '%%PATTERN:src%%',
width: %%WIDTH%%,
height: %%HEIGHT%%,
onReady: function (video) {
logGA('porvataOnReady');
top.window.ga('set', 'dimension33', 'VIDEO_B/970x365/porvata');
top.window.ga('special.set', 'dimension33', 'VIDEO_B/970x365/porvata');
top.window.guaTrackEvent('ads-UAT', 'impression', 'VIDEO_B/970x365/porvata', 0, true);
video.addEventListener('loaded', function (ima, event) {
setTimeout(function () {
ima.adsManager.setVolume(0);
}, 0);
container.addEventListener('mouseenter', function () {
ima.adsManager.setVolume(1);
});
container.addEventListener('mouseleave', function () {
ima.adsManager.setVolume(0);
});
});
video.addEventListener('start', function (ima, event) {
setTimeout(function () {
ima.adsManager.setVolume(0);
}, 0);
ima.container.classList.remove('hidden');
container.classList.remove('hidden');
});
video.addEventListener('complete', function (ima, event) {
ima.adsManager.pause();
ima.container.classList.add('hidden');
container.classList.add('hidden');
});
video.addEventListener('loaded', logGAads);
video.addEventListener('start', logGAads);
video.addEventListener('complete', logGAads);
video.ima.adsLoader.addEventListener('adError', function (event) {
logGAads('adError', event);
});
video.play();
logGA('porvataPlay');
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment