Create custom rules for Sitecore Device Detection

Last updated Friday, July 21, 2017 in Sitecore Experience Platform for Administrator, Developer
Keywords: Azure, Rules

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 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:

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";
  }
}

Send feedback about the documentation to docsite@sitecore.net.