Working with Device Detection Module in Sitecore

 

What is Device Detection in Sitecore?

Sitecore has an in-built feature called Device Detection which helps to detect at which device the content is shown into. When I say in-built that means its included as a standard feature in Sitecore XP 9.0 and later. This feature is also present in Sitecore XM Cloud , hence you do not need to buy a separate add-on or module to utilize device detection features. 

The information gather from Device Detection Module can help content makers, allowing them to tailor the website experience based on the device type they are accessing it with, such as by displaying different layouts or content depending on screen size and capabilities. For Example, An iPhone and Android users might be looking at different content on same page. 

Moreover, developers uses the same mechanism to personalize the components based on the device specific audience. They can setup Device Layout based on specific device parameters or can use the in-built rules to customize the content. They also have option to create custom rules above the existing set of rules which is also called as Predefined Conditions or in case if none of the pre-defined rules solves your purpose then you can create your own custom rule by extending DeviceBoolConditionBase class. 

Here is the quick look on the devices tab which shows the devices used to open cd site:


How it works?

Well, till now you must have got some idea what does Device Detection is useful for, BUT how that works? 

Firstly, Sitecore uses the browser user agent string or other HTTP request headers of visitors to identify their device properties. 

A user agent is a short, technical description of the web browser, operating system, (and maybe mobile device) that you're using as you access the internet. 

Example, open up your browser and go to https://www.whatismybrowser.com/detect/what-is-my-user-agent/

 Below is what I can see in my chrome web browser on my laptop: 


 Now, if you are using chrome, go to developer tools or press F12, you will see an icon to change into different mode:

Now, you can choose any one out of various device models available in the Dimensions drop down. For example let me choose IPhone 14 Pro Max and refresh the page. Like below: 


 As you can see, upon changing the device type, the User Agent string is getting changed. Sitecore uses this User Agent to identify the type of device. 

Sitecore also uses the Device Detection Database which is provided by 51degree service. It is an third party service which provide device detection, geolocation, and other real-time data services. 

Once the Sitecore is setup and Device Detection is enabled then this database file gets downloaded automatically when the instace is started for the first time. 

Location: \App_Data\DeviceDetection

Note: To make this file downloadable, you might have to configure your firewall to access the Sitecore servers. Below are the urls which must be allowed: 

Ødiscovery-ces.cloud.sitecore.net 

Ødevicedetection-ces.cloud.sitecore.net

The related configuration files are placed under \App_Config\Sitecore\DeviceDetection.Client path.


If you want to use some other provider, then you can go for creating a patch in which you can update the provider info: 


How to make use of Device Detection in Sitecore?

In this blog, I am going to setup 2 different Layout devices each for Android and IPhone device users. While setting up the devices we will use the Rule Editor to identify the user agent of the device in which web page are being opened. 

Step 1: Create Android Layout Device 


Step 2: Similarly, create iPhone Layout Device 


Step 3: Creating 3 different data sources


I will use these data source items in a rendering called Article which we will setup on a Page item.

Step 4: Setup Presentation Details



I will use data sources based on the devices, like below for Android Device: 

So till now I have setup a Page item, which has 3 layout devices having Article component having different data sources.

Step 5: Testing 

Test 1: Open in normal web browser:



Test 2: Change to Mobile Mode



Test 3: Change the device from Samsung Galaxy to IPhone device.

 


Summary

In summary, Sitecore's Device Detection Module enhances the delivery of optimized content across multiple devices, leading to better user experience, personalization, and improved conversion rates. It's a key tool for modern, responsive web development in Sitecore-based websites. 

References: 

You can check all the Device Parameter List at below link: 

https://scdp.blob.core.windows.net/downloads/Sitecore%20Experience%20Platform/Sitecore%208.1/Sitecore%20Experience%20Platform%2081%20Initial%20Release/Nonsecure/Sitecore%20Device%20Detection%20Full%20List%20of%20Parameters.csv 

https://doc.sitecore.com/xp/en/developers/latest/sitecore-experience-manager/using-device-detection.html

Comments

Popular posts from this blog

Setup A/B Testing in Sitecore - Part 1

Working with Webhooks in Sitecore - Part 1