Secret recipe of Sitecore Device Detection

What is Device Detection?

Device detection is a technology that recognizes the devices being used to access the website. This will include detailed information about the device like model, processing power, browser type, resolution of the scree and lot more.

Sitecore 9.0 and later, Sitecore Device Detection is provided out of the box.The database provider is 51Degrees and hosted by Sitecore.

Device Detection is enabled only on Content delivery, Processing or Standalone and will not work in other roles like Content Management.

51Degrees

51Degrees.mobi Limited is a UK based privately held limited company and specializes in this technology.

http://51degrees.com/device-detection

Why do we need this?

Sitecore provides rules that you could be used to personalize the content. Helps in tailored user experience with higher performance.

Example: If the user is using iOS you could show the iOS app download banner rather showing both Android and iOS

How to Configure?

Out of the box it is configured for "Standalone or ContentDelivery or Processing". If you are migrating from older versions ensure the Device detection is enabled.

By default it is set to "true".

Go to the App_Config\Sitecore\DeviceDetection.Client\Sitecore.CES.DeviceDetection.config, and set DeviceDetection.Enabled to true

Configuration Guide

https://doc.sitecore.com/developers/90/sitecore-experience-manager/en/configure-sitecore-device-detection.html

How it works?

Sitecore uses 51Degrees sql lite database as source, When device detection is enabled. Initialize will check the available database files in the app_data\devicedetection folder with extension .db and picks the latest version available. If it is not available a job is queued to download from the Sitecore servers. Sitecore instance downloads the db to the server and uses it for Device detection.

Manual Cleanup Needed (9.0-9.2)

Ensure the database is cleaned up. Since the downloaded db is close to 500MB and happens multiple times in a month. Whenever there is an update it will download a new copy. I have setup for 35 days considering minimum one db per month. If the instance is up the latest file will be locked. So, it will avoid deletion of the latest one.

Patch Config

Auto clean job is available in 9.3

Troubleshooting

Place the following device detection diagnostics page in \sitecore\admin\custom\DeviceDetectionDiagnostic.aspx and you can check the functionality.

https://github.com/bala-one/blog/blob/master/DeviceDetection/DeviceDetectionDiagnostic.aspx

  • Check if the Database is setup and downloaded in the following location App_Data/DeviceDetection and the size is close to 470MB+

  • Ensure the device detection rules are setup. When we migrated from 8.1 we noticed the device detection rule were updated in 9 and we have to add the rules again to match 9.1 new templates.

    https://doc.sitecore.com/developers/90/sitecore-experience-manager/en/rules-and-parameters-for-device-detection.html

    /sitecore/system/Settings/Rules/Definitions/Elements/Device Detection {2AA36ECE-6259-4327-B17A-5A0C81CE6ED1}

  • Ensure the sitecore domains are whitelisted to download the db

    *.cloud.sitecore.net (if your firewall allows it), or for the following URLs:

    discovery-ces.cloud.sitecore.net

    devicedetection-ces.cloud.sitecore.net

  • The enum DeviceType.Bot is now obsolete. To check robots, use the following code instead:

    var isRobot = DeviceDetectionManager.GetExtendedProperty(HttpContext.Current.Request.UserAgent, "IsCrawler");

  • Log error if you enable Device Detection in Content Management

    ManagedPoolThread #12 16:08:06 ERROR Error in Mobile device processing.

    Exception: System.InvalidOperationException

    Message: deviceRuleContext.HttpContext is null

    Source: Sitecore.CES.DeviceDetection.Rules

Photo by William Iven on Unsplash