Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

Commit 1438bfb

Browse files
rvflashmssola
authored andcommitted
Adds the Adsense bot (mobile) (#46)
Added support for AdsBot Google Mobile's user agents
1 parent d7bd3b0 commit 1438bfb

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

all_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ var uastrings = []struct {
8989
ua: "Mozilla/5.0 (compatible; AhrefsBot/4.0; +http://ahrefs.com/robot/)",
9090
expected: "Mozilla:5.0 Browser:AhrefsBot-4.0 Bot:true Mobile:false",
9191
},
92+
{
93+
title: "AdsBotGoogle",
94+
ua: "AdsBot-Google (+http://www.google.com/adsbot.html)",
95+
expected: "Browser:AdsBot-Google Bot:true Mobile:false",
96+
},
97+
{
98+
title: "AdsBotGoogleMobile",
99+
ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)",
100+
expected: "Mozilla:5.0 Browser:AdsBot-Google-Mobile Bot:true Mobile:true",
101+
},
92102

93103
// Internet Explorer
94104
{

bot.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ func getFromSite(comment []string) string {
4343
// mobile bot. This function also modifies some attributes in the receiver
4444
// accordingly.
4545
func (p *UserAgent) googleBot() bool {
46-
// This is a hackish way to detect Google's mobile bot.
47-
if strings.Index(p.ua, "Googlebot") != -1 {
46+
// This is a hackish way to detect Google's mobile bot (Googlebot, AdsBot-Google-Mobile, etc.).
47+
// See https://support.google.com/webmasters/answer/1061943
48+
if strings.Index(p.ua, "Google") != -1 {
4849
p.platform = ""
4950
p.undecided = true
5051
}

0 commit comments

Comments
 (0)