var googletag = googletag || {}; googletag.cmd = googletag.cmd || []; var madops = madops || {}; madops.custom = {}; madops.hasBeenHappened = madops.hasBeenHappened === undefined ? false : madops.hasBeenHappened; madops.loadScript = function(src, opts){ if(opts == undefined) opts = {}; var script = document.createElement('script'); script.src = madops.protocol + src; for(var o in opts) script[o] = opts[o]; document.head.appendChild(script); }; madops.DONE_CONSTANT = 4; madops.getFsa = function(){ // This function changes the global environment. // Because it makes an outside call, it is way easier that way. var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { var fsa = 'no fsa'; // This is for immigrer.com which uses the pace wordpress plugin : https://github.com/HubSpot/pace/issues/261 var DONE_CONSTANT = 4; if (xmlhttp.readyState == madops.DONE_CONSTANT ) { if (xmlhttp.status == 200) try{fsa = JSON.parse(xmlhttp.responseText).postal_code; } catch (e) {} if(fsa == undefined || !fsa) fsa = 'no_fsa'; madops.fsa = fsa; } }; xmlhttp.open("GET", madops.protocol + "//geoip.tcadops.ca/geoip", true); xmlhttp.send(); }; madops.pixel = function(obj){ if(obj instanceof Error){ var tmp = {}; tmp.message = obj.message; tmp.stack = obj.stack; obj = tmp; } var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", madops.protocol + "//pixel.m32.media/madopsv1.png?co=" + madops.getId() + "&fsa=" + madops.fsa + "&stk=" + JSON.stringify(obj)); xmlhttp.send(null); }; madops.getParameterByName = function (name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"); results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); }; madops.cookies = { createCookie:function(name,value,days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + value + expires + "; path=/"; }, readCookie:function(name) { var nameEQ = name + "="; 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,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; }, }; (function(){ if(madops.hasBeenHappened) return; madops.hasBeenHappened = true; if (madops.cookies.readCookie("m32_debug")){ madops.debug = true; } else if (madops.getParameterByName("m32_debug")) { madops.debug = true; madops.cookies.createCookie("m32_debug", "true"); } if (madops.getParameterByName('m32adtest')) { madops.testUnit = madops.getParameterByName('m32adtest'); //0.0007 is the fraction of a day that corresponds to a minute madops.cookies.createCookie("m32adtest", madops.getParameterByName('m32adtest'), 0.0007); } else if (madops.cookies.readCookie("m32adtest")) { madops.testUnit = madops.cookies.readCookie("m32adtest"); } madops.protocol = document.location.protocol == 'https:' ? 'https:' : 'http:'; madops.loadScript('//rdc.m32.media/adops/prebid.js'); if(madops.debug) madops.loadScript('//rdc.m32.media/stg/adops.js'); else madops.loadScript('//rdc.m32.media/adops.min.js'); if(!(window.googletag && googletag.apiReady)) madops.loadScript('//www.googletagservices.com/tag/js/gpt.js'); if (!(window.google && window.google.ima)) madops.loadScript('//imasdk.googleapis.com/js/sdkloader/ima3.js'); //} })();