Excluding Facebook and Google social sign-in from your referrals with Google Analytics

When we launched the new version of Fat Lama’s web app at the end of 2016, analytics was one of our top priorities. However, we noticed an odd pattern in our data in our Google Analytics (GA).

Alongside the traffic from sources that we expected (google/organic, google/cpc, direct, etc.) there were a suspiciously large number of sessions coming to us from facebook.com/referral and accounts.google.com/referral. Even more suspicious, the conversion rate for these visitors was off the charts compared to other sources.

Ridiculous conversion rates for google and facebook

We quickly realised that when our users opted to authenticate via Google or Facebook’s social sign-in, they were temporarily leaving fatlama.com to go to the respective site to give Fat Lama permission to authenticate. When they came back to fatlama.com, GA was treating them as new visitors with new sessions, overriding the original referrer with either facebook.com/referral or accounts.google.com/referral.

The culprit.

One way to solve this problem is to open the authentication link in a new tab. But this can be interfered with by a user’s ad-blocker, and we preferred the pattern we had, where the user stays in one window throughout.

After scouring Stackoverflow and some obscure Google forums, we came up with two options.

Referral Exclusions

Add facebook.com and accounts.google.com to your exclusion list on Google Analytics — find out how to do this here. This works well for accounts.google.com because no one is referred from this url EXCEPT when authenticating via Google.

However, we didn’t want to put facebook.com on our exclusion list because it would mean we wouldn’t be able to track organic traffic coming to us through facebook. Annoyingly, visitors who came from Facebook appear as facebook.com regardless of whether they clicked on a link or came via the authentication page.

Override Referrer

The other option was to manually override the GA referrer property when the user returned from authenticating. We did this by placing some javascript on the page that the user is redirected to after authenticating.

Since we use React and the react-ga module, our code looked like this:

ReactGA.set({ referrer: 'https://fatlama.com' })

Setting the referrer as our own domain prevents GA from triggering a new session. It also maintains the session from before the user navigated away so that any further actions they take on the site will be attributed to their original referrer.

If you’re not using React, you can achieve the same effect using the normal analytics.js code like this:

ga('set', 'referrer', 'https://yoursitehere.com');

Since implementing this fix, our data has started behaving itself. The ridiculous conversion rates we were getting on referrals from facebook and google have dropped. accounts.google.com has completely dropped off our analytics tables, and the referrals we still get from facebook are only organic traffic from blog posts and facebook shares.

I hope this saves someone else some time and pain in getting their data straight! If it helped you, do give it a favourite by giving it a clap (or two).

Check out our solution in action at https://fatlama.com. If you like what you see and want to get involved, get in touch at info@fatlama.com.

References / More info: