Skip to content

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


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.

Published inweb analytics


  1. Paulo Teixeira Paulo Teixeira

    Hey David, do you know if there is a way to do something similiar without GTM?

  2. Radu Stoian Radu Stoian

    Hi David,

    Are you still up for publishing the option that covers both the domain and path?

    I am interested in trying this.


  3. Rodrigo Rodrigo

    Hi David,

    Please tell me if I set up GTM the way you just showed, how will the “fake referrals” be attributed to the right referral traffic.

    Best regards,


  4. shashi shashi

    Hello Rodrigo,

    Please guide how to do the 2nd step, i.e. how to set the refer value of the pageview tag?
    Is Pageview a built-in variable?

  5. shashi shashi

    Hi David,

    How to do the 2nd step, i.e. How to set the refer value for the pageview tag?


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.