1/** 2 * Create file for Pubmatic Ad Codes for desktop. 3 * 4 * @package Express_Ad_code_Manager 5 */ 6 7//load the apstag.js library 8if ( '1' === ad_code_params.enable_amz_ads_bids ) { 9 !function(a9,a,p,s,t,A,g){if(a[a9])return;function q(c,r){a[a9]._Q.push([c,r])}a[a9]={init:function(){q("i",arguments)},fetchBids:function(){q("f",arguments)},setDisplayBids:function(){},targetingKeys:function(){return[]},_Q:[]};A=p.createElement(s);A.async=!0;A.src=t;g=p.getElementsByTagName(s)[0];g.parentNode.insertBefore(A,g)}("apstag",window,document,"script","//c.amazon-adsystem.com/aax2/apstag.js"); 10} 11 12var PWT = {}; 13var googletag = googletag || {}; 14googletag.cmd = googletag.cmd || []; 15var gptRan = false; 16PWT.jsLoaded = function() { 17 loadGpt(); 18}; 19 20 21if ( '1' === ad_code_params.enable_amz_ads_bids ) { 22 apstag.init({ 23 pubID: 'ea69f535-72ee-47bc-ad42-cec60377d1ec', 24 adServer: 'googletag' 25 }); 26} 27 28if ( 'undefined' !== typeof ad_code_params.ie_enable_bidcliq && '1' === ad_code_params.ie_enable_bidcliq ) { 29 // Load Bidcliq for selected IE articles. 30 ( function(){ 31 var bidcliqScript = document.createElement('script'); 32 bidcliqScript.async = true; 33 bidcliqScript.type = 'text/javascript'; 34 bidcliqScript.src = 'https://8a95f4.clients.bidcliq.com/sites/0e221939-a339-41f8-86ee-0e1292d7c9ba/0e221939-a339-41f8-86ee-0e1292d7c9ba.js'; 35 var node = document.getElementsByTagName('script')[0]; 36 node.parentNode.insertBefore(bidcliqScript, node); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.insertBefore 37 })(); 38} else { 39 ( function() { 40 var purl = location.href; 41 var url = '//ads.pubmatic.com/AdServer/js/pwt/156021/7083'; 42 var profileVersionId = ''; 43 if ( purl.indexOf( 'pwtv=' ) > 0 ) { 44 var regexp = /pwtv=(.*?)(&|$)/g; 45 var matches = regexp.exec( purl ); 46 if ( matches.length >= 2 && matches[1].length > 0 ) { 47 profileVersionId = '/' + matches[1]; 48 } 49 } 50 51 var wtads = document.createElement( 'script' ); 52 wtads.async = true; 53 wtads.type = 'text/javascript'; 54 wtads.src = url + profileVersionId + '/pwt.js'; 55 var node = document.getElementsByTagName( 'script' )[0]; 56 node.parentNode.insertBefore( wtads, node ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.insertBefore 57 } )(); 58} 59var loadGpt = function() { 60 // Check the gptRan flag. 61 if ( ! gptRan ) { 62 gptRan = true; 63 var gads = document.createElement( 'script' ); 64 var useSSL = 'https:' == document.location.protocol; 65 gads.src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js'; 66 var node = document.getElementsByTagName( 'script' )[0]; 67 node.parentNode.insertBefore( gads, node ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.insertBefore 68 } 69} 70// Failsafe to call gpt. 71setTimeout( loadGpt, 500 ); 72 73// this function will act as a lock and will call the GPT API. 74function initAdserver( forced ) { 75 var bidcliqReady = ( 'undefined' !== typeof ad_code_params.ie_enable_bidcliq && '1' === ad_code_params.ie_enable_bidcliq ) ? PWT.bq_BidsReceived : PWT.ow_BidsReceived; 76 if ( ( forced === true && window.initAdserverFlag !== true ) || ( PWT.a9_BidsReceived && bidcliqReady ) ) { 77 window.initAdserverFlag = true; 78 PWT.a9_BidsReceived = PWT.ow_BidsReceived = PWT.bq_BidsReceived = false; 79 googletag.pubads().refresh(); 80 } 81} 82 83var ad_units_slots = ad_code_params.ad_units; 84var pubAdslots = []; 85if ( 0 !== ad_units_slots.length ) { 86 ad_units_slots.forEach( 87 function ( ad_element ) { 88 pubAdslots.push( 89 { 90 slotID: ad_element.slot_id, 91 sizes: ad_element.slot_size 92 } 93 ); 94 } 95 ); 96} 97 98let amz_slots = []; 99if ( '1' === ad_code_params.enable_amz_ads_bids ) { 100 101 ad_units_slots.forEach( ad => { 102 103 let sizes = ad.slot_size; 104 105 if ( ! sizes || ( Array.isArray( sizes ) && 0 === sizes.length ) ) { 106 console.warn( "Skipping slot due to missing or empty sizes:", ad.slot_id ); 107 return; 108 } 109 110 if ( Array.isArray( sizes ) && ! Array.isArray( sizes[0] ) ) { 111 sizes = [sizes]; 112 } 113 114 amz_slots.push({ 115 slotID: ad.slot_id, 116 slotName: ad.slot_name, 117 sizes: sizes, 118 }); 119 }); 120} 121 122window.googletag = window.googletag || { cmd: [] }; 123setTimeout( () => { 124 googletag.cmd.push( 125 function() { 126 127 var displayAdslots = []; 128 var gutterAdMapping = googletag.sizeMapping() 129 // Desktop: Show large ad 130 .addSize([1350, 0], [[160, 600]]) 131 // Tablet: Show smaller ad 132 .addSize([1280, 0], [[120, 600]]) 133 // Mobile: No ad 134 .addSize([0, 0], []) 135 .build(); 136 137 var largeAdMapping = googletag.sizeMapping() 138 // Large desktop (width ⥠1280px) â Show 970x250 or 970x90 139 .addSize([1024, 0], [[970, 250], [970, 90], [970, 200],[728, 90]]) 140 // Medium desktop/tablet (width ⥠768px) â Show 728x90 141 .addSize([768, 0], [[728, 90]])
142 // Mobile (width < 768px) â No ad 143 .addSize([0, 0], []) 144 .build(); 145 146 if ( 'undefined' !== typeof ad_code_params ) { 147 var ad_units = ad_code_params.ad_units; 148 } 149 150 var pageAction = ad_code_params.page_action; 151 152 if ( 0 !== ad_units.length ) { 153 154 var userType = getUserType(); 155 156 if ( undefined !== userType && 'Premium' === userType ) { 157 var notRemoveAdsSingle = [ 'gpt_ad_IE_ROS_ATF_728X90', 'gpt_ad_IE_ROS_ROTATE_1_300X250' ]; 158 if ( 159 'undefined' !== typeof ieInfiniteScrollDetails 160 && ( 161 undefined !== ieInfiniteScrollDetails.section 162 || undefined !== ieInfiniteScrollDetails.political_details 163 ) 164 && ( 165 'opinion' === ieInfiniteScrollDetails.section 166 || 'columns' === ieInfiniteScrollDetails.section 167 || 'editorials' === ieInfiniteScrollDetails.section 168 || '1' === ieInfiniteScrollDetails.political_details 169 ) 170 ) { 171 notRemoveAdsSingle = [ 'gpt_ad_IE_ROS_ATF_728X90', 'gpt_ad_IE_ROS_ATF_300X250' ]; 172 } 173 } 174 175 176 var pub_ad_slot = 0; 177 var pub_ad_count = 0; 178 var pub_target_id = 0; 179 ad_units.forEach( 180 function (ad_element) { 181 182 if ( Array.isArray( notRemoveAdsSingle ) ) { 183 if ( 184 ! notRemoveAdsSingle.includes( ad_element.slot_id ) 185 && ( 0 < jQuery( '#' + ad_element.slot_id ).length || 0 < jQuery('[data-id="' + ad_element.slot_id + '"]').length ) 186 && ( 'single' === pageAction ) 187 ) { 188 if ( 0 < jQuery( '#' + ad_element.slot_id ).closest( '.adsbox970x90' ).length ) { 189 jQuery( '#' + ad_element.slot_id ).closest( '.adsbox970x90' ).remove(); 190 if ( jQuery( '.breaking-news' ).length ) { 191 jQuery( '.breaking-news' ).addClass( 'loggedin-gap-ev-user' ); 192 } 193 console.log( 'adsbox970x90' ); 194 } else if ( 0 < jQuery( '#' + ad_element.slot_id ).closest( '.add-first' ).length ) { 195 jQuery( '#' + ad_element.slot_id ).closest( '.add-first' ).remove(); 196 console.log( 'add-first' ); 197 } else if ( 0 < jQuery( '#' + ad_element.slot_id ).closest( '.ie-int-campign-ad' ).length ) { 198 jQuery( '#' + ad_element.slot_id ).closest( '.ie-int-campign-ad' ).remove(); 199 } else { 200 if ( 'Advertisement' === jQuery( '#' + ad_element.slot_id ).prev('.ie-adtext').html() || 'Story continues below this ad' === jQuery( '#' + ad_element.slot_id ).prev('.ie-adtext').html() ) { 201 jQuery( '#' + ad_element.slot_id ).parent('.adboxtop').css('padding-bottom',0); 202 jQuery( '#' + ad_element.slot_id ).parent('.adboxtop').css( 'min-height',0 ); 203 jQuery( '#' + ad_element.slot_id ).prev('.ie-adtext').remove(); 204 } 205 206 if ( ! notRemoveAdsSingle.includes( 'gpt_ad_IE_ROS_ATF_1X1' ) ) { 207 if ( 0 < jQuery('.osv-ad-class').length ) { 208 jQuery('.osv-ad-class').remove(); 209 } 210 } 211 212 jQuery( '#' + ad_element.slot_id ).remove(); 213 console.log( 'direct' ); 214 } 215 return; 216 } 217 } 218 219 // Replace "Story continues below this ad" with the new hyperlink message and color 220 if ( 'Story continues below this ad' === jQuery( '#' + ad_element.slot_id ).prev('.ie-adtext').html() && 'Premium' !== getUserType() ) { 221 var adtextElems = jQuery('.ie-adtext'); 222 var ourElem = jQuery( '#' + ad_element.slot_id ).prev('.ie-adtext')[0]; 223 var ad_pos_n = 0; 224 adtextElems.each(function(idx) { 225 if (this === ourElem) { 226 ad_pos_n = idx; 227 return false; 228 } 229 } ); 230 var AdUrl = 'https://indianexpress.com/express-plus/subscription-plan/?pageCode=15&ref=ad_pos_' + ad_pos_n; // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.insertBefore 231 var htmlStr = '<span style="color:rgb(107,107,107);">Story continues below. </span><a href="' + AdUrl + '" style="color:#006298;text-decoration:underline;">Subscribe to see fewer ads.</a>'; // phpcs:ignoreWordPressVIPMinimum.JS.StringConcat.Found 232 jQuery( '#' + ad_element.slot_id ).prev('.ie-adtext').html(htmlStr); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html 233 } 234 235 if ( ad_element.slot_id && 0 < jQuery( '#' + ad_element.slot_id ).length ) { 236 displayAdslots.push( ad_element.slot_id ); 237 if ( 'gpt_ad_IE_ROS_OOP_INNOV1' === ad_element.slot_id || 'gpt_ad_IE_ROS_OOP_INNOV2' === ad_element.slot_id ) { 238 googletag.defineOutOfPageSlot( ad_element.slot_name, ad_element.slot_id ).addService( googletag.pubads() ); 239 }
239 else if ( '' !== ad_element.slot_size ) { 240 if ( 'gpt_ad_IE_ROS_LEFT_GUTTER' === ad_element.slot_id || 'gpt_ad_IE_ROS_RIGHT_GUTTER' === ad_element.slot_id ) { 241 googletag.defineSlot( ad_element.slot_name, ad_element.slot_size, ad_element.slot_id ).defineSizeMapping(gutterAdMapping).addService( googletag.pubads() ); 242 } else { 243 googletag.defineSlot( ad_element.slot_name, ad_element.slot_size, ad_element.slot_id ).addService( googletag.pubads() ); 244 } 245 } else { 246 googletag.defineSlot( ad_element.slot_name, ad_element.slot_id ).addService( googletag.pubads() ); 247 } 248 } 249 } 250 ); 251 } 252 jQuery( '.top-ads-mobile' ).css( 'background-color', '#efefef' ); 253 jQuery( '.ie-adtext' ).css( 'color', '#6b6b6b' ); 254 255 if ( ad_code_params.articleId ) { 256 var articleid = ad_code_params.articleId; 257 var target_article_id = articleid.toString(); 258 googletag.pubads().setTargeting( 'HDFCIE', target_article_id ); 259 } 260 if ( 'undefined' !== typeof ad_code_params.sponsor_tagId && ad_code_params.sponsor_tagId ) { 261 var sponsor_tag_id = ad_code_params.sponsor_tagId; 262 var target_tag_id = sponsor_tag_id.toString(); 263 googletag.pubads().setTargeting( 'PROTECTSPRAY', target_tag_id ); 264 } 265 266 if ( 'undefined' !== typeof ad_code_params.tag_slug && ad_code_params.tag_slug ) { 267 var tagSlug = ad_code_params.tag_slug; 268 googletag.pubads().setTargeting( 'Tag', tagSlug ); 269 } 270 271 googletag.pubads().collapseEmptyDivs(); 272 googletag.pubads().setTargeting( 'v', 'classifieds' ); 273 if ( ad_code_params.pubarticleId ) { 274 var pubarticleid = ad_code_params.pubarticleId; 275 var pub_target_article_id = pubarticleid.toString(); 276 googletag.pubads().setTargeting( 'article-id', pub_target_article_id ); 277 } 278 279 if ( typeof getUserType === "function" ) { 280 var userType = getUserType(); 281 if ( undefined !== userType ) { 282 var subscriberStatus = 'NONSUB_USER'; 283 if ( 'Premium' === userType ) { 284 subscriberStatus = 'SUB_USER'; 285 } 286 googletag.pubads().setTargeting( 'subscriber', subscriberStatus ); 287 } 288 } 289 290 (()=>{var e,o,n,t;window.ieCDPGAM=(e="ie_cdp",o=function(e){var o=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return o?decodeURIComponent(o[2]):null},n=function(o,n){var t="https://ua.indianexpress.com/persona/adserve/attr?uuid="+n+"&channel="+o,a=new XMLHttpRequest;a.open("GET",t),a.timeout=700,a.responseType="json",a.onload=function(){var o=a.response;o&&(function(e,o){try{localStorage.setItem(e,JSON.stringify({v:o,exp:Date.now()+864e5}))}catch(e){}}(e,JSON.stringify(o)),window.googletag&&"function"==typeof window.googletag.pubads&&window.googletag.pubads().setTargeting("IEG_CDP_ATTRIBUTES",o))},a.onerror=function(){},a.send(null)},t=function(t){var a=o("pluuid")||o("fpuuid");if(a&&t){var i=function(e){try{var o=JSON.parse(localStorage.getItem(e));return o?Date.now()>o.exp?(localStorage.removeItem(e),null):o.v:null}catch(o){return localStorage.removeItem(e),null}}(e);window.googletag=window.googletag||{cmd:[]},window.googletag.cmd.push(function(){i?window.googletag.pubads().setTargeting("IEG_CDP_ATTRIBUTES",JSON.parse(i)):n(t,a)})}},{init:function(e){t(e)}})})(); 291 ieCDPGAM.init(window.myExpressData && window.myExpressData.apiData ? window.myExpressData.apiData.channelId : 2); //personalisation channel id 292 293 googletag.pubads().enableSingleRequest(); 294 googletag.pubads().disableInitialLoad(); 295 googletag.enableServices(); 296 297 displayAdslots.forEach( 298 function( element ) { 299 if ( element && 0 < jQuery( '#' + element ).length ) { 300 googletag.display( element ); 301 } 302 } 303 ); 304 305 if ( '1' === ad_code_params.enable_amz_ads_bids ) { 306 const apsSlots = amz_slots.filter( slotObj => displayAdslots.includes( slotObj.slotID ) ); 307 308 // 1. APS (Amazon) header bidding. 309 apstag.fetchBids({ 310 slots: apsSlots, 311 timeout: 1000 312 }, function( bids ) { 313 apstag.setDisplayBids(); 314 PWT.a9_BidsReceived = true; 315 initAdserver( false ); 316 }); 317 } 318 319 // OpenWrap code START here. 320 if ( 'undefined' !== typeof ad_code_params.ie_enable_bidcliq && '1' !== ad_code_params.ie_enable_bidcliq && typeof PWT.requestBids === 'function' ) { 321 PWT.requestBids( 322 PWT.generateConfForGPT( googletag.pubads().getSlots() ), 323 function( displayAdslots ) { 324 PWT.addKeyValuePairsToGPTSlots( displayAdslots ); 325 PWT.ow_BidsReceived = true; 326 initAdserver( false ); 327 } 328 ); 329 } 330 if ( 'undefined' !== typeof ad_code_params.ie_enable_bidcliq && '1' === ad_code_params.ie_enable_bidcliq ) { 331 window.bqjs = window.bqjs || { que: [] }; 332 bqjs.que.push(function () { 333 bqjs.requestBids().then(function () { 334 PWT.bq_BidsReceived = true; 335 initAdserver( false ); 336 }); 337 }); 338 } 339 // No need to handle "else" part as we have A9 wrapper on page. 340 // OpenWrap code END here. 341 342 var FAILSAFE_TIMEOUT = 1000; // this timeout should be more than OpenWrap and A9 timeout. 343 setTimeout( 344 function() { 345 initAdserver( true ); // calling this function with forced mode set to true so that GPT API is always executed. 346 }, 347 FAILSAFE_TIMEOUT 348 ); 349 350 } 351 ); 352 }, 353 1000 354); 355 356 357 358jQuery.fn.isOnScreen = function() { 359 try { 360 var elementTop = jQuery( this ).offset().top; 361 var elementBottom = elementTop + jQuery( this ).outerHeight(); 362 var viewportTop = jQuery( window ).scrollTop(); 363 var viewportBottom = viewportTop + jQuery( window ).height(); 364 return elementBottom > viewportTop && elementTop < viewportBottom + 300; 365 } catch (err) { 366 } 367}; 368function ie_dfp_ads() 369{ 370 jQuery( '.dfp_ads' ).each( 371 function() 372 { 373 var cur_obj = jQuery( this ); 374 if (cur_obj.isOnScreen() && cur_obj.attr( 'data-id' )) { 375 var ids = cur_obj.attr( 'data-id' ); 376 cur_obj.attr( 'id', cur_obj.attr( 'data-id' ) ); 377 cur_obj.removeAttr( 'data-id' ); 378 ie_show_ads( ids ); 379 } 380 } 381 ); 382} 383jQuery( window ).scroll( 384 function() 385 { 386 ie_dfp_ads(); 387 } 388); 389function ie_show_ads( showid ) 390{ 391 var para = document.createElement( 'script' ); 392 var divbx = document.createElement( 'div' ); 393 divbx.id = showid; 394 var a = 'googletag.cmd.push(function() { googletag.display("' + divbx.id + '"); });'; 395 var t = document.createTextNode( a ); 396 para.appendChild( t ); 397 divbx.appendChild( para ); 398 document.getElementById( showid ).appendChild( divbx ); 399} 400 401/** 402 * Get cookie for the subscription details. 403 * 404 * @param string cookieName Name of the cookie to get details. 405 */ 406function getUserSubscriptionCookie( cookieName ) { 407 408 var nameEQ = cookieName + '='; 409 var ca = document.cookie.split( ';' ); 410 var newCa = ca.length; 411 var i = 0; 412 var c; 413 414 for ( i = 0; i < newCa; i++ ) { 415 416 c = ca[i]; 417 while ( ' ' === c.charAt( 0 ) ) { 418 c = c.substring( 1, c.length ); 419 } 420 421 if ( 0 === c.indexOf( nameEQ ) ) { 422 return c.substring( nameEQ.length, c.length ); 423 } 424 } 425 return null; 426} 427 428/** 429 * Get User Type whether Premium, Registered or Anonymous. 430 */ 431function getUserType() { 432 433 let anonymusuer = getUserSubscriptionCookie('oauth_user'); 434 let userType = 'Anonymous' 435 436 if ( anonymusuer ) { 437 let storedUserCookie = getUserSubscriptionCookie( 'ie_userdata' ); 438 439 if ( null !== storedUserCookie ) { 440 storedUserCookie = JSON.parse( storedUserCookie ); 441 } 442 443 if ( storedUserCookie instanceof Object && storedUserCookie.hasOwnProperty( 'subscription_plan' ) && storedUserCookie.subscription_plan.includes( 'Digital Subscriber' ) ) { 444 userType = 'Premium'; 445 } else { 446 userType = 'Registered'; 447 } 448 449 } 450 return userType; 451}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.