Skip to content

Instantly share code, notes, and snippets.

@arturmamedov
Created January 30, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturmamedov/14154eb142720c547c4a58e5d44e4cad to your computer and use it in GitHub Desktop.
Save arturmamedov/14154eb142720c547c4a58e5d44e4cad to your computer and use it in GitHub Desktop.
Google Analytics (analytics.js) get referral `ga_referrer`
ga(function(tracker) {
var ga_refferer = tracker.get('referrer'); // this get the referral from google analytics.js
if (typeof wCookies != 'undefined' && typeof wCookies().get('ga_refferer') == 'undefined') {
if (typeof ga_refferer != 'undefined') {
wCookies().set('ga_refferer', ga_refferer, {expires: 30});
} else {
wCookies().set('ga_refferer', 'direct', {expires: 30});
}
}
});
// useed with
// https://github.com/arturmamedov/withFront/blob/master/js/core/w-core.js // for clog() function that can be removed
//
// https://github.com/js-cookie/js-cookie
// https://github.com/arturmamedov/withFront/blob/master/js/core/w-cookie.js // for wCookies() function wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment