Skip to main content

Segmentation

Add or remove users from segments programmatically via the Kompassify Player API.

Waiting for Kompassify API to be ready

It is highly recommended to wait for the Kompassify API Script to be fully loaded before calling any of the API functions.

The event KOMPASSIFY_BOOT_LOADER_IS_READY is dispatched when the Kompassify API is ready to be used.

window.addEventListener('message', function (event) {
if (event.data.TYPE === "KOMPASSIFY_BOOT_LOADER_IS_READY") {
// Do your stuff here
}
});

How to add a user to a segment

You can add a user to a segment by calling:

window.kompassifySegmentation.addUserToSegment("YOUR_SEGMENT_NAME");

Or via window.postMessage:

window.postMessage({
TYPE: "KOMPASSIFY_SEGMENTATION_ADD_USER_TO_SEGMENT",
segmentName: segmentName,
});

Parameters

PropertyTypeDescription
segmentNameStringThe name of the predefined segment.

A user can belong to multiple segments. To debug which segments the current user has been added to, check the localStorage variable localStorage.kompassifyUserSegments.

Removing a user from a segment

You can remove a user from a segment via JavaScript:

window.kompassifySegmentation.removeUserFromSegment("YOUR_SEGMENT_NAME");

Or via window.postMessage:

window.postMessage({
TYPE: "KOMPASSIFY_SEGMENTATION_REMOVE_USER_FROM_SEGMENT",
segmentName: segmentName
});