Skip to content

Tip: Maintaining Proper Session Attribution in GA when using OAuth providers with Google Tag Manager

David Vallejo

If you using Facebook, Twitter, Github or any other service to autenticate your users, you may have noticed that they end showing up as referral traffic from the oauth service.

User lands from CPC -> Logs in -> Respawns a new visit as referral

We could think on adding those domains to the ignored referrals within our view configuration, but this will and hidding the real referal traffic from those networks.


The screenshot above is an example for the referral paths for the domain We only want to avoid the ones that comes from certain paths and not the whole domain.

Simo posted above How to implement the referral exlusiong using GTM some days ago, and it’s kinda similar to what I did some time ago in one implementation to get ride of fake referrals traffic from Facebook Login.


For doing this we’ll only need to take a look to the referrals paths for the domain note the ones we want to ignore, and then use create a new variable on Google Tag Manager.


Note that we’ll need to enable the built-in Variable in Google Tag Manager, configure the fixFBarr array with our paths. This variable will return “null” as the referrer when the paths match the ones we want to ignore, and will continue returning the original referrer is there is not match.


  var fixFBarr = ['/dialog/oauth',

    for (var i = 0; i < fixFBarr.length; i++) { 
        if (document.referrer.indexOf(fixFBarr[i]) > -1)
            return null;
  return {{Referrer}};

It will be a good idea instead of checking the path to check a combination of domain + paths array. If someone if interested on it, drop a message in the post and I’ll publish a full script covering this option.

Now, we just need to set the referrer value for our pageview tag as follows:


Ok, we’re ready right after publishing all the traffic from Facebook/Twitter/Github or any other oAuth provider will start to dissapear slowly but relentlessly.