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.

oauth_post_01

The screenshot above is an example for the referral paths for the domain facebook.com. 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.

oauth_post_02

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.

oauth_post_03


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.

CODE

function(){
  var fixFBarr = ['/dialog/oauth',
        '/v2.1/dialog/oauth',
        '/login.php',
        '/v2.1/dialog/oauth/read'
    ];

    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:

oauth_post_04

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.

Comments

6 responses to “Tip: Maintaining Proper Session Attribution in GA when using OAuth providers with Google Tag Manager”

  1. Paulo Teixeira Avatar
    Paulo Teixeira

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

    1. Ryan Angilly Avatar

      ^ What he said 🙂

  2. Radu Stoian Avatar
    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.

    Thanks

  3. Rodrigo Avatar
    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,

    Rodrigo

  4. shashi Avatar
    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 Avatar
    shashi

    Hi David,

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

    Thanks,
    Shashi

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.