Skip to content

Instantly share code, notes, and snippets.

@burtyish
Last active June 25, 2019 14:05
Show Gist options
  • Save burtyish/1609b57f15285dbd9a352ea14bb3f3ef to your computer and use it in GitHub Desktop.
Save burtyish/1609b57f15285dbd9a352ea14bb3f3ef to your computer and use it in GitHub Desktop.
GTM: override oauth referrals
/*
Based on:
- https://www.simoahava.com/gtm-tips/implement-referral-exclusions-via-gtm/
- https://medium.com/@postman31/dont-let-oauth-fools-your-analytics-88d56523f6b1
- https://www.thyngster.com/tip-maintaining-proper-session-attribution-in-ga-when-using-oauth-providers-with-google-tag-manager/
*/
function() {
/* When the user goes thru oauth, the referrer is FB so the session is restarted
See: https://medium.com/@postman31/dont-let-oauth-fools-your-analytics-88d56523f6b1
*/
var authProviders = [
// Matches FB oauth:
// https://www.facebook.com/dialog/oauth
// https://www.facebook.com/v3.3/dialog/oauth?
// https://www.facebook.com/v2.4/dialog/oauth
/www\.facebook\.com\/(.+)\/oauth\b/,
];
var referrer = {{Referrer}};
if (referrer) {
for (var i = authProviders.length-1; i >= 0; i--) {
if (new RegExp(authProviders[i]).test(referrer)) {
// Set referrer to current location, so this referrer is not counted
return null;
}
}
}
return referrer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment