(function() { function bawzGetUrlParameter( name ) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec( location.search ); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }; function bawzGetTopLevelDomain(){ var i,h, test_cookie='_dpm_test=cookie', hostname = document.location.hostname.split( '.' ); for ( i = hostname.length - 1; i >= 0; i-- ) { h = hostname.slice( i ).join( '.' ); document.cookie = test_cookie + ';domain=.' + h + '; path=/; secure; samesite=none;'; if ( document.cookie.indexOf( test_cookie ) > -1 ) { /* We were able to store a cookie! This must be it. */ document.cookie = test_cookie.split( '=' )[0] + '=; domain=.' + h + '; path=/; secure; samesite=none; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 GMT;'; return h; } } } var ad_id = false; if ( 'URLSearchParams' in window ) { var urlParams = new URLSearchParams( window.location.search ); if ( urlParams.has( 'dpm' ) ) { ad_id = urlParams.get( 'dpm' ); } } else { if ( '' !== bawzGetUrlParameter( 'dpm' ) ) { ad_id = bawzGetUrlParameter( 'dpm' ); } } /* Get the TLD so we can set and access cookies across subdomains. */ var domain = bawzGetTopLevelDomain(); /* If we find an Ad ID in the URL. */ if ( false !== ad_id ) { var month_in_milliseconds = 60 * 60 * 24 * 30 * 1000; /* Expire the cookie 30 days from now. */ var expiration = new Date( Date.now() + month_in_milliseconds ).toUTCString(); /* Store the cookie for 30 days. */ document.cookie = 'dpm=' + ad_id + '; domain=' + domain + ' ;path=/; secure; samesite=none; max-age=' + ( month_in_milliseconds / 1000 ) + '; expires=' + expiration; console.log( 'The Ad ID ' + ad_id + ' was stored as a cookie in the browser.' ); } else { console.log( 'No Ad ID was detected, so no value was stored.' ); } })();