We now track the IE, Yandex, Bing, and Baidu user agents.
This commit is contained in:
parent
a25ee29197
commit
c2a3e66c6b
|
@ -221,7 +221,7 @@ var agentMapEnum = map[string]int{
|
||||||
"opera": 3,
|
"opera": 3,
|
||||||
"safari": 4,
|
"safari": 4,
|
||||||
"edge": 5,
|
"edge": 5,
|
||||||
"internet-explorer": 6,
|
"internetexplorer": 6,
|
||||||
"googlebot": 7,
|
"googlebot": 7,
|
||||||
"yandex": 8,
|
"yandex": 8,
|
||||||
"bing": 9,
|
"bing": 9,
|
||||||
|
@ -235,7 +235,7 @@ var reverseAgentMapEnum = map[int]string{
|
||||||
3: "opera",
|
3: "opera",
|
||||||
4: "safari",
|
4: "safari",
|
||||||
5: "edge",
|
5: "edge",
|
||||||
6: "internet-explorer",
|
6: "internetexplorer",
|
||||||
7: "googlebot",
|
7: "googlebot",
|
||||||
8: "yandex",
|
8: "yandex",
|
||||||
9: "bing",
|
9: "bing",
|
||||||
|
@ -342,6 +342,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
switch {
|
switch {
|
||||||
case strings.Contains(ua,"Google"):
|
case strings.Contains(ua,"Google"):
|
||||||
common.AgentViewCounter.Bump(7)
|
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
|
case strings.Contains(ua,"OPR"): // Pretends to be Chrome, needs to run before that
|
||||||
common.AgentViewCounter.Bump(3)
|
common.AgentViewCounter.Bump(3)
|
||||||
case strings.Contains(ua,"Chrome"):
|
case strings.Contains(ua,"Chrome"):
|
||||||
|
@ -350,6 +354,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
common.AgentViewCounter.Bump(1)
|
common.AgentViewCounter.Bump(1)
|
||||||
case strings.Contains(ua,"Safari"):
|
case strings.Contains(ua,"Safari"):
|
||||||
common.AgentViewCounter.Bump(4)
|
common.AgentViewCounter.Bump(4)
|
||||||
|
case strings.Contains(ua,"MSIE"):
|
||||||
|
common.AgentViewCounter.Bump(6)
|
||||||
|
case strings.Contains(ua,"Baiduspider"):
|
||||||
|
common.AgentViewCounter.Bump(10)
|
||||||
default:
|
default:
|
||||||
common.AgentViewCounter.Bump(0)
|
common.AgentViewCounter.Bump(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ func main() {
|
||||||
"opera",
|
"opera",
|
||||||
"safari",
|
"safari",
|
||||||
"edge",
|
"edge",
|
||||||
"internet-explorer",
|
"internetexplorer",
|
||||||
|
|
||||||
"googlebot",
|
"googlebot",
|
||||||
"yandex",
|
"yandex",
|
||||||
|
@ -311,6 +311,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
switch {
|
switch {
|
||||||
case strings.Contains(ua,"Google"):
|
case strings.Contains(ua,"Google"):
|
||||||
common.AgentViewCounter.Bump({{.AllAgentMap.googlebot}})
|
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
|
case strings.Contains(ua,"OPR"): // Pretends to be Chrome, needs to run before that
|
||||||
common.AgentViewCounter.Bump({{.AllAgentMap.opera}})
|
common.AgentViewCounter.Bump({{.AllAgentMap.opera}})
|
||||||
case strings.Contains(ua,"Chrome"):
|
case strings.Contains(ua,"Chrome"):
|
||||||
|
@ -319,6 +323,10 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
common.AgentViewCounter.Bump({{.AllAgentMap.firefox}})
|
common.AgentViewCounter.Bump({{.AllAgentMap.firefox}})
|
||||||
case strings.Contains(ua,"Safari"):
|
case strings.Contains(ua,"Safari"):
|
||||||
common.AgentViewCounter.Bump({{.AllAgentMap.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:
|
default:
|
||||||
common.AgentViewCounter.Bump({{.AllAgentMap.unknown}})
|
common.AgentViewCounter.Bump({{.AllAgentMap.unknown}})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue