Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get more precise Chinese browser information in google analytics
<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>
@tjefferson
Copy link
Author

tjefferson commented Jul 21, 2016

添加NewsArticle的识别

@areschen2015
Copy link

areschen2015 commented Apr 27, 2022

window.navigator.userAgent.toLowerCase()
'mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/100.0.4896.127 safari/537.36 edg/100.0.1185.44'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment