Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(w) {
- // initialize Ad Manager globals
- w.googletag = w.googletag || {};
- w.googletag.cmd = w.googletag.cmd || [];
- w.adsbygoogle = w.adsbygoogle || [];
- var pauseAdSenseAds = true;
- // Consent tool logic ready queue
- w.consentCallbackQueue = (function(undefined) {
- let timeoutCallInSeconds = 5; // false to disable
- let queue = [];
- let startImmediately = false;
- let consentCallbackCalled = false;
- let addFunction = function (callback) {
- if (startImmediately) {
- callback();
- } else {
- queue.push(callback);
- }
- };
- let runQueue = function () {
- startImmediately = true;
- queue.map(function(callback, i){
- if (callback !== undefined) {
- callback();
- queue[i] = undefined;
- }
- });
- };
- // callback which is executed by CCT code upon consent state determination
- (w.__lxG__consent__ = w.__lxG__consent__ || {}).consentCallback = function(consentState){
- consentCallbackCalled = true;
- if (consentState === null) {
- // consent not applicable, non-eu user, executing queue right away
- runQueue();
- } else if (consentState === -1) {
- // eu user, consent interface shown, cmp loaded, user has not decided yet
- } else if (consentState === 0) {
- // eu user, consent rejected, for custom advertisements systems be sure to turn on anonymous ads here
- runQueue();
- } else if (consentState === 1) {
- // eu user, consent accepted, executing the queue
- runQueue();
- }
- };
- // in case of network problems in loading consent.js
- if (timeoutCallInSeconds) {
- setTimeout(function () {
- if (!consentCallbackCalled) {
- // notify code there is no consent
- if (console && console.log) {
- // debug message
- console.log('consentCallbackQueue timeout call');
- }
- // force-disable personalized ads, if not implemented in __lxG__consent__.consentCallback
- if (w.googletag.pubads) {
- w.googletag.pubads().setRequestNonPersonalizedAds(1);
- } else {
- w.googletag.cmd.unshift(function () {
- w.googletag.pubads().setRequestNonPersonalizedAds(1);
- });
- }
- // calling function to trigger logic
- w.__lxG__consent__.consentCallback(0);
- }
- }, timeoutCallInSeconds*1000);
- }
- return {
- push: addFunction
- };
- })();
- // function to display AdManager slot by it`s div ID
- // it supports automatic slot refresh if disableInitialLoad was called before
- w.displayAndRefreshSlotById = function (slotId) {
- consentCallbackQueue.push(function () {
- googletag.cmd.push(function () {
- if (w.pubads().isInitialLoadDisabled()) {
- googletag.pubads().getSlots().forEach(function (slot) {
- if (slot.getSlotElementId() == slotId) {
- googletag.display(slotId);
- googletag.pubads().refresh([slot]);
- }
- });
- } else {
- googletag.display(slotId);
- }
- });
- });
- }
- // function for AdSense slots
- w.displayAdSenseSlots = function () {
- consentCallbackQueue.push(function () {
- var adSenseSlots = document.querySelectorAll('ins.adsbygoogle');
- adSenseSlots.forEach(function(item){
- if(item.innerHTML.trim() === "")
- {
- (adsbygoogle = window.adsbygoogle || []).push({});
- }
- });
- });
- }
- })(window);
- window.displayAdSenseSlots();
- // for AdManager slots you should replace
- // googletag.cmd.push(function () {
- // googletag.display('div-id-1');
- // });
- // with
- // displayAndRefreshSlotById('div-id-1');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement