Created
April 12, 2017 00:39
-
-
Save patrick-mcdougle/b5c537c8df2e7596c0f1a1c307bd3563 to your computer and use it in GitHub Desktop.
Gallery Page Ads Code
This file contains 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
//Setup Amazon | |
var amznads = amznads || {}; | |
amznads.asyncParams = { | |
'id': '3217', | |
'callbackFn': function() { | |
try { | |
amznads.setTargetingForGPTAsync('amznslots'); | |
} catch (e) {} | |
}, | |
'timeout': 2000 | |
}; | |
(function() { | |
var a, s = document.getElementsByTagName('script')[0]; | |
a = document.createElement('script'); | |
a.type = 'text/javascript'; | |
a.async = true; | |
a.src = '//c.amazon-adsystem.com/aax2/amzn_ads.js'; | |
s.parentNode.insertBefore(a, s); | |
})(); | |
var googletag = window.googletag = {}; | |
googletag.cmd = []; | |
var initGPT = function() { | |
var gads = document.createElement("script"); | |
gads.async = true; | |
gads.type = "text/javascript"; | |
var useSSL = "https:" == document.location.protocol; | |
gads.src = (useSSL ? "https:" : "http:") + "//www.googletagservices.com/tag/js/gpt.js"; | |
var node = document.getElementsByTagName("script")[0]; | |
node.parentNode.insertBefore(gads, node); | |
}; | |
googletag.cmd.push(function() { | |
googletag.pubads().setTargeting('fr', 'timeout'); | |
googletag.pubads().setTargeting('adt', 'timeout'); | |
googletag.pubads().setTargeting('alc', 'timeout'); | |
googletag.pubads().setTargeting('dlm', 'timeout'); | |
googletag.pubads().setTargeting('drg', 'timeout'); | |
googletag.pubads().setTargeting('hat', 'timeout'); | |
googletag.pubads().setTargeting('off', 'timeout'); | |
googletag.pubads().setTargeting('vio', 'timeout'); | |
}); | |
// Defer loading gpt until we're sure IAS has fired. | |
var GPTInitTimeout = setTimeout(initGPT, 1000); | |
var __iasPET = __iasPET || {}; | |
__iasPET.queue = __iasPET.queue || []; | |
// Load IAS PET | |
(function() { | |
var iasTag = document.createElement('script'); | |
iasTag.async = true; | |
iasTag.src = '//cdn.adsafeprotected.com/iasPET.1.js'; | |
var targetNode = document.getElementsByTagName('head')[0]; | |
targetNode.insertBefore(iasTag, targetNode.firstChild); | |
})(); | |
__iasPET.pubId = '8225'; | |
__iasPET.queue.push({ | |
adSlots: [ | |
{adSlotId: 'leaderboard-0', size: [728,90], adUnitPath: '5485/US/popsugar/fashion/gallery/leaderboard'}, | |
{adSlotId: 'native_lower-0', size: [324,492], adUnitPath: '5485/US/popsugar/fashion/gallery/native_lower'}, | |
{adSlotId: 'native_lower-1', size: [324,492], adUnitPath: '5485/US/popsugar/fashion/gallery/native_lower'}, | |
{adSlotId: 'native_lower-2', size: [324,492], adUnitPath: '5485/US/popsugar/fashion/gallery/native_lower'}, | |
{adSlotId: 'native_upper-0', size: [360,100], adUnitPath: '5485/US/popsugar/fashion/gallery/native_upper'}, | |
{adSlotId: 'upper_rec-0', size: [300,250], adUnitPath: '5485/US/popsugar/fashion/gallery/upper_rec'} | |
], | |
dataHandler: function(adSlotData) { | |
window.clearTimeout(GPTInitTimeout); | |
var data = JSON.parse(adSlotData); | |
if (data.fr == 'true') { | |
ONSUGAR.Util.log('IAS Fraudulent Traffic Detected!'); | |
} | |
initGPT(); | |
}, | |
timeout: 1000 | |
}); | |
googletag.cmd.push(function() { | |
var slot_0 = googletag.defineSlot('5485/US/popsugar/fashion/gallery/leaderboard', [[728,90],[970,90]], 'leaderboard-0').addService(googletag.pubads()).setTargeting('pos', 'leaderboard') | |
.setTargeting('interstitial_past', 'false') | |
; | |
SUGAR.gpt.addRotatableAd('leaderboard-0', slot_0); | |
SUGAR.gpt.addCreatedAd('leaderboard-0', slot_0, false); | |
var slot_oop_0 = googletag.defineOutOfPageSlot('5485/US/popsugar/fashion/gallery/outofpage', 'leaderboard-0-oop').addService(googletag.pubads()).setTargeting('pos', 'outofpage') | |
; | |
SUGAR.gpt.addCreatedAd('leaderboard-0-oop', slot_oop_0, false, 1); | |
var slot_1 = googletag.defineSlot('5485/US/popsugar/fashion/gallery/native_lower', [324, 492], 'native_lower-0').addService(googletag.pubads()).setTargeting('pos', 'native_lower') | |
; | |
SUGAR.gpt.addCreatedAd('native_lower-0', slot_1, false); | |
var slot_2 = googletag.defineSlot('5485/US/popsugar/fashion/gallery/native_lower', [324, 492], 'native_lower-1').addService(googletag.pubads()).setTargeting('pos', 'native_lower') | |
; | |
SUGAR.gpt.addCreatedAd('native_lower-1', slot_2, false); | |
var slot_3 = googletag.defineSlot('5485/US/popsugar/fashion/gallery/native_lower', [324, 492], 'native_lower-2').addService(googletag.pubads()).setTargeting('pos', 'native_lower') | |
; | |
SUGAR.gpt.addCreatedAd('native_lower-2', slot_3, false); | |
var slot_4 = googletag.defineSlot('5485/US/popsugar/fashion/gallery/native_upper', [360, 100], 'native_upper-0').addService(googletag.pubads()).setTargeting('pos', 'native_upper') | |
; | |
SUGAR.gpt.addCreatedAd('native_upper-0', slot_4, false); | |
var slot_5 = googletag.defineSlot('5485/US/popsugar/fashion/gallery/upper_rec', [[300,250],[160,600],[300,600],[300,1050]], 'upper_rec-0').addService(googletag.pubads()).setTargeting('pos', 'upper_rec') | |
.setTargeting('use_ad_controller', true) | |
.setTargeting('override_ajax', true) | |
.setTargeting('nid', '43414104') | |
.setTargeting('interstitial_past', 'false') | |
; | |
SUGAR.gpt.addRotatableAd('upper_rec-0', slot_5); | |
SUGAR.gpt.addCreatedAd('upper_rec-0', slot_5, false); | |
var slot_oop_5 = googletag.defineOutOfPageSlot('5485/US/popsugar/fashion/gallery/outofpage', 'upper_rec-0-oop').addService(googletag.pubads()).setTargeting('pos', 'outofpage') | |
.setTargeting('use_ad_controller', true) | |
.setTargeting('override_ajax', true) | |
.setTargeting('nid', '43414104') | |
; | |
SUGAR.gpt.addCreatedAd('upper_rec-0-oop', slot_oop_5, false, 1); | |
if (typeof __iasPET.setTargetingForGPT == 'function') { | |
__iasPET.setTargetingForGPT(); | |
} | |
googletag.pubads().enableSingleRequest(); | |
googletag.pubads().disableInitialLoad(); | |
googletag.pubads().setTargeting('nid', '43414104'); | |
googletag.pubads().setTargeting('ntype', 'gallery'); | |
googletag.pubads().setTargeting('sponsor', 'aerosolesq22017'); | |
googletag.pubads().setTargeting('bot', 'false'); | |
googletag.pubads().setTargeting('channel', 'fashion'); | |
googletag.pubads().setTargeting('page_type', 'gallery'); | |
googletag.pubads().setTargeting('special', 'galleryv2'); | |
if (SUGAR.ads.getPOE()) { | |
googletag.pubads().setTargeting('first_impression', 'true'); | |
} | |
else { | |
googletag.pubads().setTargeting('first_impression', 'false'); | |
} | |
googletag.pubads().setTargeting('tag', ['seo','swimsuits','originalfeature','fashioncarousel','fdhero','syndicate','summerfashion','bikinis','swimwear','summer','trends','shopping']); | |
var view_percentile = (Math.floor(Date.now() / 1000) % 100) + 1; | |
googletag.pubads().setTargeting('SOV_count', view_percentile.toString()); | |
// Make DFP ads centered. | |
googletag.pubads().setCentering(true); | |
if (SUGAR.ads.checkCPC()) { | |
googletag.pubads().setTargeting('cpc', '1'); | |
} | |
if (!!document.getElementById('video-ad-player-container') && !ONSUGAR.Util.getCookie('sugar-video-ad-player')) { | |
googletag.pubads().setCategoryExclusion('Synced'); | |
} | |
googletag.pubads().addEventListener('slotRenderEnded', function(ad) {SUGAR.gpt.slotRenderEnded(ad);}); | |
googletag.pubads().enableAsyncRendering(); | |
googletag.pubads().collapseEmptyDivs(true); | |
SUGAR.gpt.setHierarchy('5485/US/popsugar/fashion/gallery/'); | |
googletag.enableServices(); | |
}); | |
function adPush() { | |
googletag.cmd.push(function() { | |
googletag.display('leaderboard-0'); | |
googletag.pubads().refresh(); | |
}); | |
} | |
if(document.readyState === "complete") { | |
adPush(); | |
} | |
else { | |
if (document.addEventListener) { | |
document.addEventListener('DOMContentLoaded', adPush, false); | |
} | |
else { | |
document.attachEvent('onreadystatechange', function() { | |
if (document.readyState === 'interactive') { | |
adPush(); | |
} | |
}); | |
} | |
} | |
googletag.cmd.push(function(){googletag.pubads().addEventListener('impressionViewable', function(e) { | |
e.slot.getAdUnitName = function() { | |
var slotElementId = e.slot.getSlotElementId(); | |
return slotElementId.split('-')[0];}; | |
document.dispatchEvent(new CustomEvent('adImpressionViewable', {detail: e})); | |
document.dispatchEvent(new CustomEvent('adSlotViewed', {detail : e})); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment