Create segment characteristics

Once you create a segment, you define one or more characteristics that contain the conditions, upon which Sitefinity CMS serves personalized content to the segment. Such conditions may be IP address, Location, Landing URL, and so on. Sitefinity API supports programmatic creation of the following characteristics by:

  • User role
  • IP address
  • Location
  • Landing URL
  • Query string
  • Referral URL
  • Visited page URL
  • Time of day
  • Visit duration

Segment characteristics are represented programmatically as objects of type Criterion (Telerik.Sitefinity.Personalization.Impl.Model.Criterion). To create a Criterion, you need to instantiate a new object of type Criterion and set its properties:

  • CriterionName – the predefined name of the Criterion (for example, IP Address, Location, Roles). This property represents the label of the characteristic type, as displayed in the UI.

    IMPORTANT: Make sure you use the property names provided in the code samples in this section.

  • CriterionTitle – has the same value as the CriterionName property. Sitefinity persists the value of the CriterionTitle property in the database.

    IMPORTANT: Make sure you use the property names provided in the code samples in this section.

  •  CriterionValue – represents the business logic of the characteristic condition. You need to serialize the property value, so make sure you follow the convention demonstrated in the samples from this section.
  • CriterionDisplayValue – represents the value of the characteristic, as displayed in the UI under CriterionName so you know what condition you set for this characteristic.
  • IsNegated – a Boolean property that controls the way the criterion value is interpreted by Sitefinity: [Characteristic] is / is not [Value]. In most scenarios, you set this value to false.
CriterionProps

The following samples give more details how to use the properties, listed above:

Create criterion by user role:

To create a criterion by user role you pass the role Id and Name and set the CriterionValue in the proper format:

Create criterion by IP Address

Creating a criterion by IP address is as simple as passing the IP address as string and setting the address to the CriterionValue property in the proper format:

Create criterion by Landing URL or Querystring:

Creating criteria by Landing URL or Querystring introduce an added functionality of using a criterion operator. Since these criteria allow you to specify a desired value and a second value to compare to, you also need to choose which operator to use for the comparison of the two. Thus, you can set conditions, such as “this characteristic is valid for visitors that land on an URL that contains/equals/starts with etc. the following value” The supported criterion operators are:

  • "=" - equal to
  • "!" - not equal to
  • "contains" - contains
  • "!contains" - does not contain
  • "startswith" - starts with
  • "!startswith" - doesn't start with
  • "endswith" - ends with
  • "!endswith" - does not end with

The following example demonstrates how to create a Landing URL and use the criterion operators, listed above:

The similar logic applies when creating a criterion by QueryString:

Create criterion by Location:

Create criterion by Time of day:

To create a Time of day criterion, you need to pass two different DateTime values when building the CriterionValue – one for the start time and one for end time of the specified timeframe of the visit. For example, the criterion applies to visitors that browse the website between 9am and 5pm:

Create criterion by page visit duration

Similar to the Time of day criterion, when working with Page visit duration criterion, you need to pass two values to specify min and max duration. You also specify the time unit.

NOTE: Supported values for time unit are “seconds” or “minutes”.

Create criterion by visited page URL

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?