Skip to content

Instantly share code, notes, and snippets.

@girvan
Created December 7, 2016 05:30
Show Gist options
  • Save girvan/30afe7578a78d8cc8317a1e390139e7a to your computer and use it in GitHub Desktop.
Save girvan/30afe7578a78d8cc8317a1e390139e7a to your computer and use it in GitHub Desktop.
Fix Google Analytics tracking
/*
setup: paste before ga('send', 'pageview');
features:
- fix *.search.yahoo.com to Organic
- fix Line and WeChat Apps to Social
*/
(function(r, M, S){
if(r.match(/^https?:\/\/\w+\.search\.yahoo\.com\//))
{ga('set',M,'Organic');ga('set',S,'Yahoo!');return}
if(r)return;var m=navigator.userAgent.match(/\W(MicroMessenger|Line)\W/);
if(!m)return;ga('set',M,'Social');ga('set',S,m[1].replace(/M.*/,'WeChat'))
})(document.referrer,'campaignMedium','campaignSource');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment