Social logins can cause havoc with Google Analytics (GA) as visitors are typically directed away from your domain to the domain of the Social login provider. This ‘breaks’ the visitors session on your site, making the resulting return from the social provider appear as if it’s a new session.

There are a couple of approaches but it depends on the social login provider. Google logins are simple enough as they use the domain accounts.google.com. This can simply be excluded out right like you might with a payment processor (PayPal/Stripe etc..) by adding the domain to the excluded list.

Whilst this works for Google, this isn’t as useful for Facebook & Twitter - particularly if you use either as a way to drive traffic (or even care about referrals from them). Excluding the domains facebook.com or twitter.com will block out all referrals - it’s unlikely anyone wants this.

There doesn’t appear to be a way in GA to handle this scenario via configuration, there is only a code workaround. The answer is to have GA ‘blank’ the referrals from these social logins URL’s. You can add the following next to your GA setup:

var refs = [
  'https://www.facebook.com/v2.9/dialog/oauth',
  'https://m.facebook.com/v2.9/dialog/oauth/read',
  'https://m.facebook.com/login/checkpoint',
  'https://api.twitter.com/oauth/authorize',
  'https://api.twitter.com/oauth/authenticate',
];

if(document.referrer) {
  for(var i=0; i < refs.length; i++) {
    if(document.referrer.slice(0, refs[i].length) == refs[i]) {
      ga('set', 'referrer', '');
      break;
    }
  }
}

It should come after the ga('create', ...) call and before the ga('send', 'pageview', ...) call.

This will blank the referral from the social logins and stop new sessions being created.

NOTE: The example only works for a specific version of the Facebook API, if you are using another version (not v2.9) you should change the URLs to suit - or the code could be modified to support multiple versions.