Default Update User Segment Strategy

The DefaultCxUpdateUserSegmentStrategy is the default implementation of the UpdateUserSegmentStrategy, defined in the personalizationintegration extension.

The strategy allows to update segments from several external systems at the same time. The DefaultCxUpdateUserSegmentStrategy collects the segments from the implementations of the UserSegmentsProvider defined in the Spring context and assigns the segments to the user. If there are no segments in the system, they can be created if the Auto Create Segments flag is set to true. If it's set to false, the strategy does not set any user to segment relation.

You can change this behavior in the Backoffice Administration Cockpit under Start of the navigation pathPersonalization Next navigation step Personalization ConfigurationEnd of the navigation path. For details on how to manage the configuration, see Set Up a Personalization Configuration.

As a fallback, you can also set the personalizationintegration.updateUserSegment.createSegment property as presented below:
personalizationintegration.updateUserSegment.createSegment=true

User Segments Provider

The UserSegmentsProvider is an interface which should be implemented when connecting another source of user segments.

The UserSegmentsProvider interface contains two base methods:
  • getUserSegments - returning segments for user,
  • getProviderId - returning provider identifier. This method has a default implementation which classifies provider as one of the DEFAULT providers.
    Provider identifier allows to:
/**
 * Interface returning segments assigned to user
 */
public interface UserSegmentsProvider
{
   String DEFAULT_PROVIDER_ID = "DEFAULT";
 
   /**
    * Method returning segments assigned to user
    *
    * @param user
    *           User model
    * @return segments assigned to user or null if segments should not be updated
    */
   List<SegmentMappingData> getUserSegments(final UserModel user);
 
   /**
    * Method returns provider identifier
    *
    * @return - provider identifier
    * @since 1811
    */
   default String getProviderId()
   {
      return DEFAULT_PROVIDER_ID;
   }
}
Out of the box, the Personalization module contains two implementations:
  • UserTypeSegmentsProvider - providing segments to distinguish anonymous and registered users.
  • ConsumptionLayerUserSegmentsProvider - providing segments from Intelligent Selling Services Foundation.

Provider Prefix

The segment returned by the provider can be automatically prefixed. To configure the prefix for segments returned by the provider, or for the already existing ones, use the personalizationintegration.provider.<PROVIDER_ID>.prefix property.
personalizationintegration.provider.SAMPLEID.prefix=PREF

Provider Separator

By default, the separator between prefix and segment code is set as space. To set a different separator, use the personalizationintegration.provider.<PROVIDER_ID>.separator property.

UserTypeSegmentsProvider

  • USER_ANONYMOUS
  • USER_REGISTERED

The UserTypeSegmentsProvider has a DEFAULT provider identifier. This means it uses the segment prefix configured for DEFAULT providers (personalizationintegration.provider.DEFAULT.prefix) and it is called during the update, update_default, or async process actions. This means that depending on the personalization configuration, USER_ANONYMOUS and USER_REGISTERED may not be updated right away when user starts the session or logs in.

To take full advantage of the segments, perform the following:
  • when defining the calculation settings in the Backoffice Administration Cockpit, set the update action to be executed at the beginning of the session and during logon. For details, see the Initial Actions section in Configure Personalization Calculation.
  • when defining the target group expression in SmartEdit, use only USER_REGISTERED or NOT (USER_REGISTERED) options. For details, see Add Customizations.

This behavior reduces instances when the given target group is not triggered.

Define Segments Provider

Context

You can create your own provider used by the DefaultCxUpdateUserSegmentStrategy.

Procedure

  1. Create an implementation of the UserSegmentsProvider interface:
    public class SampleUserSegmentsProvider implements UserSegmentsProvider
    {
       private static final String PROVIDER_ID = "SAMPLEID";
       private CxIntegrationMappingService cxIntegrationMappingService;
     
       @Override
       public List<SegmentMappingData> getUserSegments(final UserModel user)
       {
          //get segment data from external system
          final Object segmentData = ...;
     
          //map external data to segments
          final Optional<MappingData> mappingData = cxIntegrationMappingService.mapExternalData(segmentData,
                "YOUR_INTEGRATION_CONVERTER_NAME");
     
          //return segment list
          return mappingData.map(MappingData::getSegments).orElseGet(() -> Collections.emptyList());
       }
     
       @Override
       public String getProviderId()
       {
          return PROVIDER_ID;
       }
     
       protected CxIntegrationMappingService getCxIntegrationMappingService()
       {
          return cxIntegrationMappingService;
       }
     
       @Required
       public void setCxIntegrationMappingService(final CxIntegrationMappingService cxIntegrationMappingService)
       {
          this.cxIntegrationMappingService = cxIntegrationMappingService;
       }
    }
    The getUserSegments method of the interface returns:
    • a list of segments to be assigned to the user (the segments that are currently assigned to the user and are not on the list, will be removed),
    • an empty list if all the segments assigned to the user should be removed,
    • null if the segment provider can't provide new data, and doesn't want the existing data to be changed.
    The getProviderId method of the interface returns the provider identifier. There is a default implementation of this method, which returns the DEFAULT identifier. This method should be implemented when:
    • you want to be able to set a separate configuration for your provider,
    • you want to have a specific prefix for segments returned by the provider.
  2. Define your provider in the Spring context:
    <bean id="sampleUserSegmentProvider"
        class="de.hybris.platform.extensionname.segment.SampleUserSegmentsProvider">
        <property name="cxIntegrationMappingService" ref="cxIntegrationMappingService"/>
    </bean>
  3. Add the update actions for your provider:

    To add the update actions for your provider, extend the RecalculationAction enum with the following values: UPDATE_<PROVIDER_ID> and ASYNC_PROCESS_<PROVIDERID>.

    ...
    <enum class="de.hybris.platform.personalizationservices.RecalculateAction">
        <value>UPDATE_SAMPLEID</value>
        <value>ASYNC_PROCESS_SAMPLEID</value>
    </enum>
    ...
  4. Configure the prefix for your provider.
    To configure the prefix for segments returned by your provider, set the personalizationintegration.provider.<PROVIDER_ID>.prefix:
    personalizationintegration.provider.SAMPLEID.prefix=PREF

Auto Creation of Segments

In the personalizationintegration extension, the CxConfig was extended to include the autoCreateSegments parameter.

If it is set to true in the Backoffice Administration Cockpit, the segments are automatically created from the external data during update. To allow enabling the auto creation of segments in the Backoffice Administration Cockpit, the personalizationintegration extension was extended with the backoffice configuration.