In the Conscia DX Engine, you can use Context Field Enrichment to set a Context Field that supports date comparisons in Experience Rules. For example, an insurance company may want to present personalized content if the visiting customer’s insurance policy expires within some number of days from the present moment. The following recipe is a model for how to use Context Fields and Experience Rules to make data comparisons to determine content selection.
Mapping Out DX Engine Elements
This example consists of the following Conscia elements:
- Context Value: This orchestration flow uses a context value named
policyExpirationDateTime
that contains the date when the customer’s policy expires in ISO format such as "2024-03-14T18:45:16.943Z
". Context Field Enrichment sets the value of thepolicyExpirationDateTime
Context Field based on the value inpolicyExpiresInXDays
. In a real solution, another Component would likely define this value, and you would use the componentResponse() function to retrieve that value. policyExpiresInXDays
: This Context Field contains the number of days until the customer’s policy expires. Defining a Context Field makes its value available in the Experience Designer for defining rules. The Preliminary Component uses Context Field Enrichment to set a value for this Context Field.- Preliminary Component: An Orchestration Component that runs before the **Personalization Component ** to apply Context Field Enrichment. This is not a specific component; you can use any component for this Context Field Enrichment.
- Personalization Component: An Orchestration Component that defines the Experience Rules.
DX Engine Configuration Details
You don’t need to do anything to define a context value such as policyExpiresInXDays
. You do not need to define a Context Field in the Conscia UI to use a value from Context. You simply pass a named key in Context to an Orchestration flow, and then you can use the contextField() function to retrieve its value whether or not you have defined a Context Field in Conscia, and if so, whether or not you have used Context Field Enrichment for that Context Field. So, for
To define the policyExpiresInXDays
Context Field, in the Conscia DX Engine UI:
- Click Settings in the top navigation, and then click Context Fields. The Manage Context Fields page appears.
- Click Add Context Field. The Create Context Field wizard appears.
- For Context Field Name, enter
policyExpiresInXDays
. - For Data Type, select
Number
. - Click Submit.
To use the Preliminary Component to use Context Enrichment to set a value in the policyExpiresInXDays
Context Field, in the Conscia DX Engine UI:
- Click Manage Experiences, and then click Components. The Manage Components page appears.
- Next to the Preliminary Component, click the Edit button. The Edit Component wizard appears.
- In the Update Context area, add a Context Field Enrichment for the
policyExpiresInXDays
Context Field, setting Expression to the following value:
(DateTime.fromISO(contextField('policyExpirationDateTime')) - DateTime.now())/86400000
- Click Submit.
This expression converts the policyExpirationDateTime
context value to an object that represents a date and time and subtracts the current date and time to determine the number of days until that date, storing the result as a decimal number in the policyExpiresInXDays
Context Field.
To add Experience Rules that use the policyExpiresInXDays
Context Field in the Personalization Component, in the Conscia DX Engine UI:
- In the top navigation, click Manage Experiences, and then click Experiences. The Manage Experiences page appears.
- Select the **Personalization Component ** and ensure that a default rule exists.
- Click Add Experience Rule.
- Enter a Rule ID and a Rule Name and set Priority to a value lower than that of the default rule
- In the Experience area, under Real-time Context Evaluation, click Edit Filter. The Edit Filter wizard appears.
- Drag a condition such as Less Than onto the first area of the canvas.
- With that condition selected, for Field, select
policyExpiresInXDays
, and set value to some number of days. If the current date is within that number of days ofpolicyExpirationDateTime
, this rule evaluates to true. - Click Submit.
- Specify the intended behavior for the Personalization Component.
- Click Submit.