We now track the IE, Yandex, Bing, and Baidu user agents.

This commit is contained in:
Azareal 2018-01-09 08:46:16 +00:00
parent a25ee29197
commit c2a3e66c6b
2 changed files with 19 additions and 3 deletions

View File

@ -221,7 +221,7 @@ var agentMapEnum = map[string]int{
"opera": 3,
"safari": 4,
"edge": 5,
"internet-explorer": 6,
"internetexplorer": 6,
"googlebot": 7,
"yandex": 8,
"bing": 9,
@ -235,7 +235,7 @@ var reverseAgentMapEnum = map[int]string{
3: "opera",
4: "safari",
5: "edge",
6: "internet-explorer",
6: "internetexplorer",
7: "googlebot",
8: "yandex",
9: "bing",
@ -342,6 +342,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch {
case strings.Contains(ua,"Google"):
common.AgentViewCounter.Bump(7)
case strings.Contains(ua,"Yandex"):
common.AgentViewCounter.Bump(8)
case strings.Contains(ua,"bingbot"), strings.Contains(ua,"BingPreview"):
common.AgentViewCounter.Bump(9)
case strings.Contains(ua,"OPR"): // Pretends to be Chrome, needs to run before that
common.AgentViewCounter.Bump(3)
case strings.Contains(ua,"Chrome"):
@ -350,6 +354,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
common.AgentViewCounter.Bump(1)
case strings.Contains(ua,"Safari"):
common.AgentViewCounter.Bump(4)
case strings.Contains(ua,"MSIE"):
common.AgentViewCounter.Bump(6)
case strings.Contains(ua,"Baiduspider"):
common.AgentViewCounter.Bump(10)
default:
common.AgentViewCounter.Bump(0)
}

View File

@ -164,7 +164,7 @@ func main() {
"opera",
"safari",
"edge",
"internet-explorer",
"internetexplorer",
"googlebot",
"yandex",
@ -311,6 +311,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch {
case strings.Contains(ua,"Google"):
common.AgentViewCounter.Bump({{.AllAgentMap.googlebot}})
case strings.Contains(ua,"Yandex"):
common.AgentViewCounter.Bump({{.AllAgentMap.yandex}})
case strings.Contains(ua,"bingbot"), strings.Contains(ua,"BingPreview"):
common.AgentViewCounter.Bump({{.AllAgentMap.bing}})
case strings.Contains(ua,"OPR"): // Pretends to be Chrome, needs to run before that
common.AgentViewCounter.Bump({{.AllAgentMap.opera}})
case strings.Contains(ua,"Chrome"):
@ -319,6 +323,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
common.AgentViewCounter.Bump({{.AllAgentMap.firefox}})
case strings.Contains(ua,"Safari"):
common.AgentViewCounter.Bump({{.AllAgentMap.safari}})
case strings.Contains(ua,"MSIE"):
common.AgentViewCounter.Bump({{.AllAgentMap.internetexplorer}})
case strings.Contains(ua,"Baiduspider"):
common.AgentViewCounter.Bump({{.AllAgentMap.baidu}})
default:
common.AgentViewCounter.Bump({{.AllAgentMap.unknown}})
}