NonplayerCharacter

Google Tag Manager | Rewrite referrer for subdomain

Jun 14th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Replace referrer to identify traffic from specific subdomains
  2. // https://www.bounteous.com/insights/2014/06/19/are-you-missing-referral-traffic-universal-analytics/
  3.  
  4.  
  5. function() {
  6.     var theReferrer = document.referrer;
  7.     if (theReferrer) {
  8.         var myProtocol = theReferrer.match(/(https?:\/\/)/);
  9.         var myDomain = theReferrer.match(/\/\/tatooine\.com(.+)/);
  10.         var mySubdomain = theReferrer.match(/\/\/(.+)\.tatooine\.com(.+)/);
  11.         var myPath = "";
  12.         if (mySubdomain) {
  13.             if (mySubdomain[2]) myPath = mySubdomain[2];
  14.         // exclude referrals from the jobs subdomain
  15.         // see referrals from all other subdomains
  16.             if (mySubdomain[1]=="jobs") {
  17.                 return myProtocol[1]+"jobs.tatooine.com"+myPath;
  18.             } else {
  19.                 return myProtocol[1]+mySubdomain[1]+".tatooinetheplanet.com"+myPath;
  20.             }
  21.         }
  22.         // keep the else-if statement to see referrals from the main domain
  23.         // remove it to exclude referrals from the main domain
  24.         else if (myDomain) {
  25.             if (myDomain[1]) myPath = myDomain[1];
  26.             return myProtocol[1]+"tatooinetheplanet.com"+myPath;
  27.         }
  28.     }
  29.     return document.referrer;
  30. }
Add Comment
Please, Sign In to add comment