Create custom rules for Sitecore Device Detection

Current version: 10.1

Sitecore includes a standard set of personalization rules for the Device Detection service. However, you can create your own set of custom rules to further customize it by creating new rules that are appropriate to your organization's needs. You can create a single rule, based on several device parameters, and use it for personalization and tracking that shows personalized content based on several device parameters. For example:

  • You can use device-based parameters to define your own minimum requirements for HTML5 browser support so that it shows sophisticated renderings without breaking a visitor's experience. For example: a device = (hardware + software), e.g. an iPhone + Safari.

  • You can identify all laptops that use fewer than four CPU cores and less than 2GB of RAM so that you can show an upgrade offer.

Use the  Rule Set Editor and the Rules Engine Cookbook to create custom rules for device detection. There are a few basic classes to associate one or more actions with one or more conditions, these include:

Class

Class description

DeviceBoolConditionBase

Use this abstract class to create a Boolean rule.

DeviceStringConditionBase

Use this abstract class to create string-based rules.

DeviceIntegerConditionBase

Use this abstract class to create integer-based rules.

For example, you can create the following custom rule that identifies whether a device is a pair of Google glasses:

RequestResponse
public class GoogleGlassCondition<T> : DeviceBoolConditionBase<T> where T : RuleContext
{
  protected override bool GetDeviceProperty(DeviceInformation deviceInformation)
  {
    return deviceInformation.DeviceType == DeviceType.WearableComputer &&
      deviceInformation.DeviceModelName == "Glass" &&
      deviceInformation.DeviceOperatingSystemVendor == "Google";
  }
}

Do you have some feedback for us?

If you have suggestions for improving this article,