Skip to content

Instantly share code, notes, and snippets.

@tsamuel86
Created August 12, 2015 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsamuel86/ea48e37f2d0810e8fb21 to your computer and use it in GitHub Desktop.
Save tsamuel86/ea48e37f2d0810e8fb21 to your computer and use it in GitHub Desktop.
<!-- Yieldbot.com Intent Tag -->
<script type="text/javascript" src="https://cdn.yldbt.com/js/yieldbot.intent.js"></script>
<!-- Yieldbot.com Intent Tag ACTIVATION -->
<script type="text/javascript">
function ybWidth(){
var w = window,
d = document,
e = d.documentElement,
x = Math.max(e.scrollWidth,e.offsetWidth,e.clientWidth);
return x;
}
if(ybWidth()=<481){
yieldbot.pub('464c');//mobile
yieldbot.defineSlot('mobile_LB');
yieldbot.defineSlot('mobrec');
}
yieldbot.go();
</script>
<script type="text/javascript">
var deviceDetection = new DeviceDetection();
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
try {
amznads.setTargetingForGPTAsync('amznslots');
} catch(e) {
console.log('Error on amznads.setTargetingForGPTAsync(..). ', e);
}
try{
googletag.pubads().setTargeting("ybot",yieldbot.getPageCriteria());
}catch(e){/*ignore*/}
(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('category', 'life');
googletag.pubads().setTargeting('subcat', 'diy');
googletag.pubads().setTargeting('publishers', 'dif1');
googletag.pubads().setTargeting('ArticleID', '167246');
});
var setTargeting = function(risk) {
googletag.cmd.push(function() {
if (risk === 'High' || adFactory.isMature()) {
ga('send', 'event', {
'eventCategory': 'ForensiqRisk',
'eventAction': adFactory.isMature() ? 'Mature' : 'High Risk',
'eventLabel': 'different-solutions',
'eventValue': 1,
'nonInteraction': 1
});
googletag.pubads().setTargeting('google', 'no');
} else {
googletag.pubads().setTargeting('google', 'yes');
}
googletag.enableServices();
});
var sessionId = getUserSessionId();
var payload = {
platformId: 1,
articleId: 167246 || -1,
page: 1 == 0 ? 1 : 1,
isFraudulent: risk === "High",
hasAddBlock: isAdBlockActive || false,
UserGuid: sessionId,
UserIp: "67.243.150.42" || "none",
ViewType: "Child/Organic" || "none",
Publication: "1" || "none",
UserAgent: navigator.userAgent || "none",
Type: "ViewMetric"
};
var containerName = "views-in-hub";
var token = "SharedAccessSignature sr=http%3a%2f%2fgoviral-engine-bus.servicebus.windows.net%2f&sig=LJtwxD9j534Y3nVsPUcn6aCzRwkSXiF0Lnf3U85W5xg%3d&se=1439338507&skn=ClientSendAccessPolicy";
var jsonPayload = JSON.stringify(payload);
if (IsJsonString(jsonPayload)) {
$.ajax({
type: "POST",
url: "https://goviral-engine-bus.servicebus.windows.net/" + containerName + "/messages/?timeout=60",
data: jsonPayload,
cache: false,
contentType: "application/json",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", token);
xhr.setRequestHeader("Content-Type", "application/json");
}
});
}
};
var checkAdContent = 0;
var payload = {
PlatformId: 1,
ArticleId: 167246 || -1,
View: "Child/Organic" || "none",
Publication: 1 || -1,
NativeAdId: 499 || -1,
AdType: "None",
Type: "AdMetric"
};
function sendLoadMessage() {
if ($('#nativePlaceholder')
.find("img")
.toArray()
.some(function(elem) { return elem.src.length > 0; })) {
payload.AdType = "Applovin";
if ($('mgline').toArray.length === 6)
payload.AdType = "MGID";
} else if ($('.rc-photo').toArray().length === 6) {
payload.AdType = "RevContent";
} else if (checkAdContent <= 3) {
setTimeout(sendLoadMessage, 2000);
checkAdContent++;
return;
}
var containerName = "loads-in-hub";
var token = "SharedAccessSignature sr=http%3a%2f%2fgoviral-engine-bus.servicebus.windows.net%2f&sig=DSRMKYNlrDndoTQiNC1Ycp7fmgFr2E%2bqGKzEd1dAzGs%3d&se=1439338537&skn=ClientSendAccessPolicy";
var jsonPayload = JSON.stringify(payload);
if (IsJsonString(jsonPayload)) {
$.ajax({
type: "POST",
url: "https://goviral-engine-bus.servicebus.windows.net/" + containerName + "/messages/?timeout=60",
data: jsonPayload,
cache: false,
contentType: "application/json",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", token);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Access-Control-Allow-Credentials", "true");
}
});
}
}
sendLoadMessage();
function IsJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
var pickUsingWeights = function(items, weights) {
var total = 0;
var ranges = weights.slice(0);
for (var i = 0,
len = weights.length; i < len; i++) {
ranges[i] = [total, total += ranges[i]];
}
var randomNumber = parseInt(Math.random() * total);
for (; randomNumber < ranges[--i][0];);
return items[i];
};
var adFactory = {
isMature: function() {
return false;
},
deviceDetector: deviceDetection,
init1x1: function(label) {
googletag.cmd.push(function() {
var slotName = '/28725707/' + label;
googletag.defineSlot(slotName, [1, 1], 'div-da-1x1').addService(googletag.pubads());
googletag.enableServices();
});
},
initHeaderAd1: function() {
googletag.cmd.push(function() {
var mapping1 = googletag.sizeMapping().
addSize([992, 0], [[970, 90], [970, 250], [970, 66], [728, 90]]). //desktop
addSize([768, 0], [[970, 66], [728, 90]]). //tablet
addSize([0, 0], [[320, 50], [320, 100]]). //other
build();
var adSlot1 = googletag.defineSlot('/28725707/Diply_ArticlePage_Header_Ad1', [320, 50], 'div-da-header1');
adSlot1.defineSizeMapping(mapping1);
adSlot1.addService(googletag.pubads());
googletag.enableServices();
});
},
initContentAd1: function() {
googletag.cmd.push(function() {
var mapping2 = googletag.sizeMapping().
addSize([992, 0], [728, 90]). //desktop
addSize([768, 0], [728, 90]). //tablet
addSize([320, 0], [[320, 50], [320, 100], [300, 250]]). //mobile
addSize([0, 0], [[320, 50], [320, 100]]). //other
build();
var adSlot2 = googletag.defineSlot('/28725707/Diply_Cloak_ArticlePage_Content_Ad1', [320, 50], 'div-da-content1');
adSlot2.defineSizeMapping(mapping2);
adSlot2.addService(googletag.pubads());
googletag.enableServices();
});
},
initContentAd2: function() {
googletag.cmd.push(function () {
var mapping3 = googletag.sizeMapping().
addSize([992, 0], [[728, 250], [728, 90], [320, 250], [300, 250]]). //desktop
addSize([768, 0], [[728, 250], [728, 90], [320, 250], [300, 250]]). //tablet
addSize([320, 0], [[320, 250], [320, 100], [320, 50], [300, 250]]). //mobile
addSize([0, 0], [[320, 250], [320, 100], [320, 50]]). //other
build();
var adSlot3 = googletag.defineSlot('/28725707/Diply_Cloak_ArticlePage_Content_Ad2', [320, 50], 'div-da-content2');
adSlot3.defineSizeMapping(mapping3);
adSlot3.addService(googletag.pubads());
googletag.enableServices();
});
},
initContentAd3: function() {
googletag.cmd.push(function() {
var mapping4 = googletag.sizeMapping().
addSize([992, 0], [[728, 250], [728, 90], [320, 250], [300, 250]]). //desktop
addSize([768, 0], [[728, 250], [728, 90], [320, 250], [300, 250]]). //tablet
addSize([320, 0], [[320, 250], [320, 100], [320, 50], [300, 250]]). //mobile
addSize([0, 0], [[320, 250], [320, 100], [320, 50]]). //other
build();
var adSlot4 = googletag.defineSlot('/28725707/Diply_Cloak_ArticlePage_Content_Ad3', [320, 50], 'div-da-content3');
adSlot4.defineSizeMapping(mapping4);
adSlot4.addService(googletag.pubads());
googletag.enableServices();
});
},
initSideAd1: function() {
googletag.cmd.push(function() {
var ad5Mapping = googletag.sizeMapping().
addSize([992, 0], [300, 250]). //desktop
addSize([0, 0], [[320, 50], [320, 100]]). //other
build();
var ad5Slot = googletag.defineSlot('/28725707/Diply_Cloak_ArticlePage_Sidebar_Ad1', [320, 50], 'div-da-side1');
ad5Slot.defineSizeMapping(ad5Mapping);
ad5Slot.addService(googletag.pubads());
googletag.enableServices();
});
},
initSideAd2: function() {
googletag.cmd.push(function() {
var ad5Mapping = googletag.sizeMapping().
addSize([992, 0], [[300, 600], [300, 250], [160, 600]]). //desktop
addSize([0, 0], [[320, 50], [320, 100]]). //other
build();
var ad5Slot = googletag.defineSlot('/28725707/Diply_Cloak_ArticlePage_Sidebar_Ad2', [320, 50], 'div-da-side2');
ad5Slot.defineSizeMapping(ad5Mapping);
ad5Slot.addService(googletag.pubads());
googletag.enableServices();
});
},
initAdService: function() {
$.ajax({
url: '/api/forensiq/score',
timeout: 1000
}).done(function(data) {
if (data.cachedScore) {
setTargeting(data.cachedScore);
} else {
setTargeting("Safe");
}
}).fail(function() {
setTargeting('Safe');
});
}
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}
function getUserSessionId() {
var user = getCookie("userSessionId");
return user;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment