Tracking social login with GA/GTM
Following up on yesterday's article, this article describes a technique for tracking social logins in a single session using Google Analytics (GA) and Google Tag Manager (GTM).
In crafting this technique I mainly referenced a since deleted post from "advertisercommunity.com". I also used some info from this arcticle on simoahava.com but not the exact technique described.
During a social login (that is, allowing a user to use their Facebook or Google login to log into your site) the user's browser is moved for a split second to Facebook or Google domains to verify the login before being redirected back. In the process of this redirection the user lands back on your site, and GA decides that a new "session" has started and that the referrer is Facebook or Google. This causes the user's activity from before to not be connected to what they do after they log in.
As my friend Nick, founder of Mad Leads pointed out during our joint strategy work on a customer project, you can't just exclude the facebook.com
or m.facebook.com
domains from within GA without wrecking other real referrer information from FB, so that's not an option for correcting the breakage.
Ideally we want to skip creating this new session all together and roll with the original utm source/medium data from the original session. It turns out that, on the page where the user lands back from Facebook or Google, if you manually set the "referrer" value on the GA Page View tag to your site's own domain, then GA doesn't consider any new referrer and continues on with the old session. A strange workaround, but one that consistently worked in my testing.
#
Step 1Create a new Custom Event trigger. The "Event Name" of this trigger will be used later.
#
Step 2Create a new Google Analytics Page View tag, setting the "referrer" value to the built-in variable {{Page Hostname}}
. Configure the tag's Firing Trigger to be the custom event from Step 1. This will cause the referrer information to be wiped out when we fire our custom event.
#
Step 3We want to make sure that this new Page View tag is the only Page View tag that fires on the social login return pages. To do that, we create an exception so that, if the Custom Event fires on a particular page, we exclude our main GA Page View tag and only fire the new one. So, in our main GA Page View tag configuration, create an Exception for our custom event.
#
Step 4On ONLY the social login landing pages back from Google or Facebook, we need to add some additional javascript to trigger our custom event. So just below the GTM tag in the header of those landing pages, I added the following code snippet to fire the Custom Event—
Of course, in the code above, the Event name set up in Step 1 should be plugged into those single quotes accordingly.
Note that this code should only be added to the pages you want to blow up the referrer information for. Adding it site-wide would of course destroy all of the referrer information for the entire site, which is probably not desired.