Segmentation based on provided attributes
Definition
This document provides a detailed walkthrough of the inner workings of segmentation based on provided attributes API, covering both the Loader Script and Settings SDK aspects step by step.
Segmentation based on provided attributes in Loader(configuration) Script
Once a user includes their attributes in the query parameters, as exemplified below, the Loader SDK, upon loading, will conduct a check to ascertain if the 'attr' parameter has been included in the query parameters. If the 'attr' parameter is found, the Loader SDK will include its value in the request URL for the subsequent 'get setting' call. The convention allows a maximum of 10 key-value pairs to be passed via the attr query parameter. Each key-value pair should be formatted as key.value and separated by a comma. For example: attr=key1.value1,key2.value2.
<script type="module" src="https://optifyr.com/pulse/{{appName}}/module/pulse.js?include=settings,tracker&prefetch=tag1,tag3&ur=userRole1,userRole2&attr=key1.value1,key2.value2" async fetchpriority="high" onerror="window.pulseFailedToLoad = true; window.dispatchEvent(new Event('pulseLoadFailed'))"></script>
<script nomodule src="https://optifyr.com/pulse/{{appName}}/nomodule/pulse.js?include=settings,tracker&prefetch=tag1,tag3&ur=userRole1,userRole2&attr=key1.value1,key2.value2" async fetchpriority="high" onerror="window.pulseFailedToLoad = true; window.dispatchEvent(new Event('pulseLoadFailed'))"></script>
Note: Segmentation based on provided attributes will be accessible in Pulse SDK versions 1.86.0 or later.
Segmentation based on provided attributes in React wrapper(configuration)
If you provide the attributes using the PulseProvider, they must be passed as key-value pairs within an object. Both the keys and values should be regular strings.
example:
<PulseProvider
app="your app name"
defaults={{}}
attributes={{
key1: "value1",
key2: "value2",
}}
version="your app version"
>
...
</PulseProvider>
Segmentation based on provided attributes in Settings SDK
When the settings SDK is initialized, it caches any prefetched settings and stores the provided attributes value in the IndexedDB record for each setting if supplied through a prefetch script or PulseProvider.
When a user requests a setting, the SDK checks if the attributes value provided by the client matches the cached value. If they differ, the SDK clears the cache; otherwise, it treats the cached settings as valid.
If the cached settings are valid, the SDK returns them. However, if no valid cached settings are found, the SDK makes a fetch call to retrieve the latest settings, including the attributes in the request URL.
Note: If the client provides attributes through both a prefetch script and PulseProvider, and the attributes differ, the Settings SDK will make redundant GET requests for settings due to the mismatch. To avoid this, ensure that identical attributes are provided during initialization.