SHARE
TWEET

Untitled

a guest Jul 17th, 2017 46 in 2 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!--
  2. this part to install to the main page
  3. don't forget to remove console.log function if all works correctly
  4. -->
  5. <script type="text/javascript">
  6.   //cookie framework
  7.   const docCookies = {
  8.     getItem: function(sKey) {
  9.       if (!sKey) {
  10.         return null;
  11.       }
  12.       return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
  13.     },
  14.     setItem: function(sKey, sValue, vEnd, sPath, sDomain, bSecure) {
  15.       if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
  16.         return false;
  17.       }
  18.       var sExpires = "";
  19.       if (vEnd) {
  20.         switch (vEnd.constructor) {
  21.           case Number:
  22.             sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
  23.             break;
  24.           case String:
  25.             sExpires = "; expires=" + vEnd;
  26.             break;
  27.           case Date:
  28.             sExpires = "; expires=" + vEnd.toUTCString();
  29.             break;
  30.         }
  31.       }
  32.       document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
  33.       return true;
  34.     },
  35.     hasItem: function(sKey) {
  36.       if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
  37.         return false;
  38.       }
  39.       return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
  40.     }
  41.   };
  42.  
  43.   // cookie life time 30 days
  44.   const time = 60 * 60 * 24 * 30
  45.  
  46.   //get utm params from url
  47.   const url = new URL(location.href)
  48.   const utm = {
  49.     utm_source: url.searchParams.get('utm_source'),
  50.     utm_medium: url.searchParams.get('utm_medium'),
  51.     utm_campaign: url.searchParams.get('utm_campaign'),
  52.     utm_content: url.searchParams.get('utm_content'),
  53.     utm_term: url.searchParams.get('utm_term'),
  54.     http_referrer: document.referrer
  55.   }
  56.  
  57.   //check for old data
  58.   if (docCookies.hasItem('utm') && utm.http_referrer.includes('bettercaring.com.au')) {
  59.    const oldutm = JSON.parse(docCookies.getItem('utm'))
  60.    utm.http_referrer = oldutm.http_referrer
  61.  }
  62.  
  63.  //set cookie
  64.  docCookies.setItem('utm', JSON.stringify(utm), time, '/', '.bettercaring.com.au')
  65.  console.log(utm);
  66. </script>
  67.  
  68. <!--
  69. this part installs to login form
  70. don't forget to remove console.log function if all works correctly
  71. -->
  72. <script type="text/javascript">
  73.   //cookie framework
  74.   const docCookies = {
  75.     getItem: function(sKey) {
  76.       if (!sKey) {
  77.         return null;
  78.       }
  79.       return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
  80.     },
  81.     setItem: function(sKey, sValue, vEnd, sPath, sDomain, bSecure) {
  82.       if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
  83.         return false;
  84.       }
  85.       var sExpires = "";
  86.       if (vEnd) {
  87.         switch (vEnd.constructor) {
  88.           case Number:
  89.             sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
  90.             break;
  91.           case String:
  92.             sExpires = "; expires=" + vEnd;
  93.             break;
  94.           case Date:
  95.             sExpires = "; expires=" + vEnd.toUTCString();
  96.             break;
  97.         }
  98.       }
  99.       document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
  100.       return true;
  101.     },
  102.     hasItem: function(sKey) {
  103.       if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
  104.         return false;
  105.       }
  106.       return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
  107.     }
  108.   };
  109.  
  110.   //get cookie function start
  111.   addCookieToForm()
  112.  
  113.   function addCookieToForm() {
  114.     //is cookie here?
  115.     if (!docCookies.hasItem('utm')) return
  116.  
  117.     //get cookie
  118.     const utm = JSON.parse(docCookies.getItem('utm'))
  119.     console.log(utm)
  120.  
  121.     //get form
  122.     let form = document.getElementById('new_user')
  123.     //add hidden fiels to the form
  124.     form.innerHTML +=
  125.       `
  126.     <input type="text" name="utm_source" value="${utm.utm_source}" hidden />
  127.     <input type="text" name="utm_medium" value="${utm.utm_medium}" hidden />
  128.     <input type="text" name="utm_campaign" value="${utm.utm_campaign}" hidden />
  129.     <input type="text" name="utm_content" value="${utm.utm_content}" hidden />
  130.     <input type="text" name="utm_term" value="${utm.utm_term}" hidden />
  131.     <input type="text" name="http_referrer" value="${utm.http_referrer}" hidden />
  132.   `
  133.   }
  134. </script>
RAW Paste Data
Pastebin PRO Summer Special!
Get 60% OFF on Pastebin PRO accounts!
Top