Variation Triggers
Triggers activate different variations for a specific user. Out of the box there are three different kinds of triggers, each of them having a corresponding strategy used to evaluate them.
The CxTriggerService executes the registered strategies (the strategies are automatically found in the global context using their type). Because strategies are automatically injected into the CxTriggerStrategy they don't have aliases. To override a strategy with a different bean, declare a bean with the same name in global context.
At any time you can implement your own trigger that suits your needs. For details, see Create a Trigger Type.
CxDefaultTriggerStrategy
The CxDefaultTriggerStrategy is a simple strategy for triggering a default variation. It uses the CxDefaultTrigger models to find variations, which should be triggered. All variations related to CxDefautlTrigger models are returned. If a default trigger is present it will always return the variations it is associated with.
This type of trigger is useful if you need a default variation activated when no other variation is returned for the current user. If this is your use case, make sure that the variation linked to a default trigger has the lowest priority in the customization. There is nothing that prevents you from having the default variation at the highest priority in which case no other variation from the customization will be evaluated.
CxDefaultTrigger has an interceptor, which prevents creating more than one trigger for a variation. The default trigger always returns a related variation and there is no point in having any other trigger for such variation.
You can use the default variation trigger if you want your variation to be targeted at all users (regardless of the division to user segments). For details how to set a default variation trigger see Add Customizations.
DefaultSegmentTriggerStrategy
This is a default strategy for triggering variation using related segments. It uses the CxSegmentTrigger models as information storage for evaluating what variation should be triggered.
The CxSegmentTrigger model is linked to multiple segments and also holds an attribute that defines which operation to use when the trigger is evaluated: a variation can be triggered if any of the segments is present (OR operation) or if all are present (AND operation).
The strategy also filters user segments using their affinity. Only the segments which exceed a certain threshold are used in evaluation. This property can be set using the personalizationservices.segment.trigger.strategy.min.affinity property.
ExpressionTriggerStrategy
This strategy handles all instances of CxExpressionTrigger model. The CxExpressionTrigger serves as a container for logical expression defining the combination of CxSegments. The ExpressionTriggerStrategy evaluates such expressions in the context of a given user, and if an expression returns true, the strategy returns a linked variation.
- a group of elements with an operator (AND / OR)
- a negation on single element
- segment definition
"expression": {
"type": "groupExpression",
"elements": [
{
"type": "segmentExpression",
"code": "Men"
},
{
"type": "groupExpression",
"elements": [
{
"type": "segmentExpression",
"code": "Women"
},
{
"type": "negationExpression",
"element": {
"type": "segmentExpression",
"code": "HatsFan"
}
}
],
"operator": "AND"
}
],
"operator": "OR"
}
The above example shows the following: a user belongs to Men segment OR to (Women segment but at the same time not the HatsFan segment). The segments used to build evaluation context also need to satisfy the minimal affinity requirement.
The CxExpressionTrigger is related to segments for validation purposes, but this relation is dynamic and based on an expression. Manual modification of related segments has no effect as it is overwritten while saving it thanks to the CxExpressionTriggerInterceptor.
The CxSegment can't be removed if it's related to a CxExpressionTrigger as it would alter the expected behavior of the CxExpressionTrigger.
Managing CxSegment and CxSegmentTrigger
The backoffice configuration defined in the personalizationservicesbackoffice extension provides you with a CxSegment/CxSegmentTrigger management tool. The purpose of this CRUD tool is to limit the functionality and manage relations between the CxSegment and CxSegmentTrigger. To ensure smooth management, the following interceptors were introduced:
- CxSegmentRemoveInterceptor: prevents removing CxSegment if it's related to any CxSegmentTrigger, because that way the relation is also removed.
- CxSegmentTriggerValidationInterceptor: by extending the BaseTriggerInterceptor, it prevents creating or updating the relation between the CxSegment and CxSegmentTrigger, if there is one already defined for the other trigger.