I'm trying to figure out how the DeviceDetection api can be used to detect Bots visiting the website. Sitecore version: 9.0.2
When specific pages get visit, I want to log if it is a bot or not.
var deviceInfo = DeviceDetectionManager.GetDeviceInformation(HttpContext.Current.Request.UserAgent);
return deviceInfo != null ? deviceInfo.DeviceType.ToString() : "";
But after testing, it seems that certain UserAgents always return the DeviceType
Computer
. Example UserAgent:
Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36
While I expect the DeviceType to be Bot
in this case. Which it clearly is, it even says Googlebot.
So I started to deassemble the Sitecore.DeviceDetection.CES.dll
- First off all, the documentation specifies to use
DeviceInformation.IsBot
because the enum valueDeviceType.Bot
is obsolete.
But... the DeviceDetection does not even contain a property IsBot. - I looked at the 51Degrees implementation that should set the DeviceType. This is in
Sitecore.CES.DeviceDetection.Providers.FiftyOneDegrees.MatchHelper.cs
.
But... there is no code that ever sets the DeviceType to Bot.
So my question is, how can I check for a Bot using the DeviceDetection api?
Can be helpful: 51degrees website to see what you get back from a given user agent string
Sitecore.Analytics.Core.ContactClassification.IsRobot(currentContact)
to check.It classifies all visitors on their first visit as robots
. Think that could give us some false positives with what we want to do with the data.Sitecore.Analytics.ExcludeRobots.config
as a good reference point for your own robot detection based on user agent...