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

Commit

Permalink
Adds the Adsense bot (mobile) (#46)
Browse files Browse the repository at this point in the history
Added support for AdsBot Google Mobile's user agents
  • Loading branch information
rvflash authored and mssola committed Nov 12, 2018
1 parent d7bd3b0 commit 1438bfb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ var uastrings = []struct {
ua: "Mozilla/5.0 (compatible; AhrefsBot/4.0; +http://ahrefs.com/robot/)",
expected: "Mozilla:5.0 Browser:AhrefsBot-4.0 Bot:true Mobile:false",
},
{
title: "AdsBotGoogle",
ua: "AdsBot-Google (+http://www.google.com/adsbot.html)",
expected: "Browser:AdsBot-Google Bot:true Mobile:false",
},
{
title: "AdsBotGoogleMobile",
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)",
expected: "Mozilla:5.0 Browser:AdsBot-Google-Mobile Bot:true Mobile:true",
},

// Internet Explorer
{
Expand Down
5 changes: 3 additions & 2 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func getFromSite(comment []string) string {
// mobile bot. This function also modifies some attributes in the receiver
// accordingly.
func (p *UserAgent) googleBot() bool {
// This is a hackish way to detect Google's mobile bot.
if strings.Index(p.ua, "Googlebot") != -1 {
// This is a hackish way to detect Google's mobile bot (Googlebot, AdsBot-Google-Mobile, etc.).
// See https://support.google.com/webmasters/answer/1061943
if strings.Index(p.ua, "Google") != -1 {
p.platform = ""
p.undecided = true
}
Expand Down

0 comments on commit 1438bfb

Please sign in to comment.