Last active
April 27, 2022 06:13
-
-
Save tjefferson/807106972c71b30ea9c2 to your computer and use it in GitHub Desktop.
get more precise Chinese browser information in google analytics
This file contains 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> |
添加NewsArticle的识别
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
将WeChat的识别添加到QQ Browser之前,避免WeChat识别为QQ Browser