NikolayBezay

Pelephone GTM teg for dynamic user data.

Dec 8th, 2020 (edited)
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.93 KB | None | 0 0
  1. <script>
  2.     (function() {
  3.         function getCookieParam(cname) {
  4.             var name = cname + "=";
  5.             var decodedCookie = decodeURIComponent(document.cookie);
  6.             var ca = decodedCookie.split(";");
  7.             for (var i = 0; i < ca.length; i++) {
  8.                var c = ca[i];
  9.                while (c.charAt(0) == " ") {
  10.                    c = c.substring(1);
  11.                }
  12.                if (c.indexOf(name) == 0) {
  13.                    return c.substring(name.length, c.length);
  14.                }
  15.            }
  16.            return false;
  17.        }
  18.        function getDynamicData(adoricCampaigId) {
  19.            var userToken = getCookieParam('com.silverpop.iMAWebCookie');
  20.            if (userToken) {
  21.                var URL = 'https://www.pelephone.co.il/digitalsite/handlers/service.ashx?action=GetPersonalInfo&lcid=1037&visitorKey=';
  22.                URL += userToken;
  23.                URL += '&id=' + adoricCampaigId;
  24.  
  25.                var data = null;
  26.                var xhr = new XMLHttpRequest();
  27.                xhr.addEventListener('readystatechange', function() {
  28.                    if (this.readyState === 4) {
  29.                        var response = JSON.parse(this.responseText);
  30.                        if (response.IsExists) {
  31.                            sessionStorage.setItem(adoricCampaigId, this.responseText)
  32.                        }
  33.                    }
  34.                });
  35.                xhr.open('GET', URL);
  36.                xhr.setRequestHeader('cache-control', 'no-cache');
  37.                xhr.send(data);
  38.            }            
  39.        }
  40.         setTimeout(function() {
  41.             window.adoric &&
  42.        adoric.lightboxes &&
  43.        adoric.lightboxes.forEach(function(item) {
  44.            if (!window.sessionStorage.getItem(item.options.campaignId)) {
  45.                getDynamicData(item.options.campaignId);  
  46.            }
  47.        });
  48.  
  49.         }, 2000);
  50.  
  51.    })();
  52. </script>
  53.  
Add Comment
Please, Sign In to add comment