-
-
Save TylerTemp/d2bd6aa5d21d4e992cc47c04fd3956f5 to your computer and use it in GitHub Desktop.
get more precise Chinese browser information in google analytics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var browserName = "Other"; | |
var ua = window.navigator.userAgent; | |
browserRegExp = { | |
Sogou : /SE\s2\.X|SogouMobileBrowser/, | |
Explorer2345 : /2345Explorer|2345chrome|Mb2345Browser/, | |
Liebao : /LBBROWSER/, | |
Wechat : /MicroMessenger/, | |
QQBrowser : /QQBrowser/, | |
Baidu : /BIDUBrowser|baidubrowser|BaiduHD/, | |
UC : /UBrowser|UCBrowser|UCWEB/, | |
MiuiBrowser : /MiuiBrowser/, | |
MobileQQ : /Mobile\/\w{5,}\sQQ\/(\d+[\.\d]+)/, | |
Shoujibaidu : /baiduboxapp/, | |
SamsungBrowser: /samsungbrowser/, | |
Firefox : /Firefox/, | |
Maxthon : /Maxthon/, | |
Se360 : /360SE/, | |
Ee360 : /360EE/, | |
TheWorld : /TheWorld/, | |
Weibo : /__weibo__/, | |
NokiaBrowser : /NokiaBrowser/, | |
Opera : /Opera|OPR\/(\d+[\.\d]+)/, | |
Edge : /Edge/, | |
QQLive : /QQLive(HD)?Browser/, | |
Letv : /LetvClient/, | |
Youku : /Youku/, | |
AndroidBrowser : /Android.*Mobile\sSafari|Android\/(\d[\.\d]+)\sRelease\/(\d[\.\d]+)\sBrowser\/AppleWebKit(\d[\.\d]+)/i, | |
IE : /Trident|MSIE/, | |
toutiao : /NewsArticle/, | |
Chrome : /Chrome|CriOS/, | |
Safari : /Version[|\/]([\w.]+)(\s\w.+)?\s?Safari|like\sGecko\)\sMobile\/\w{3,}$/, | |
}; | |
for (var i in browserRegExp) { | |
if (browserRegExp[i].exec(ua)) { | |
browserName = i; | |
break; | |
} | |
} | |
ga('set', 'dimension1', browserName); | |
if (browserName === "Other" || browserName === "Chrome") { | |
ga('set', 'dimension2', browserName + "-" + ua); | |
} | |
ga('send', 'event', 'function_test', 'browser_detection', {'nonInteraction': 1}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment