Segments

Applying Segments

To ensure the correct timing when making alterations handle the send2crmLoading event in your own script:

window.addEventListener('send2crmLoading', (evt) => { // Segment evaluation code goes here. });

Set a Segment for the Goal threshold

Segments may be applied when the visitor reaches a threshold value for a particular Goal.

// Apply the Personalization Segment 'VIP_VISITOR' when the 'IMPORTANT_GOAL' Goal value reaches 50 total for the Visitor. send2crm.personalization.setSegmentForGoal('VIP_VISITOR', 'IMPORTANT_GOAL', 50);

The Segment will be applied automatically when the specified Goal reaches the given value.

Set a Segment using Custom Logic

Segments may also be applied using your own logic. This uses a callback function that provides the current Visitor object.

// Apply the Personalization Segment 'REPEAT_VISITOR' when the Visitor has more than one Session. send2crm.personalization.setSegmentWhen('REPEAT_VISITOR', function(visitor) { return (visitor.sessionCount > 1); });

See Visitor information for a list of available Visitor properties. The session property contains the current Session object. Use this data to perform your logic and return true if the Segment should be applied.

Retrieving Segments

Use the values of saved Segments to determine when you want to apply personalization to your website.

Testing

To check whether a visitor has a Segment applied, call the Send2CRM library function:

Persistence

Segments are recorded against the visitor, and generally not removed once applied. They are also sent to the Send2CRM service for Identified Visitors and synchronized across different browsers.

Segment Cookie

If the personalizationCookie setting is enabled, Send2CRM will automatically populate a cookie named send2crm with the values of all Segments separated by pipe (|) characters. e.g.:

This allows accessing the values of applied Segments server-side on your website.

Standard requirements for user acceptance of cookies apply. You may need to implement a suitable notice on your website if not already in place.