User Role based Segmentation
Definition
This document provides a detailed walkthrough of the inner workings of the user role based segmentation API, covering both the Loader Script and Settings SDK aspects step by step.
User Role based Segmentation in Loader(configuration) Script
Once a user includes their user role in the query parameters, as exemplified below, the Loader SDK, upon loading, will conduct a check to ascertain if the 'ur' parameter has been included in the query parameters. If the 'ur' parameter is found, the Loader SDK will include its value in the request URL for the subsequent 'get setting' call. Otherwise, the loader script will remove any 'ur' records from localStorage if they exist. Additionally, the Loader SDK will store the 'ur' value in the localStorage, ensuring its availability for the settings SDK.
<script type="module" src="https://optifyr.com/pulse/{{appName}}/module/pulse.js?include=settings,tracker&prefetch=tag1,tag3&ur=userRole1,userRole2" 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" async fetchpriority="high" onerror="window.pulseFailedToLoad = true; window.dispatchEvent(new Event('pulseLoadFailed'))"></script>
Note: User role based segmentation will be accessible in Pulse SDK versions 1.49.0 or later.
User Role based Segmentation in Settings SDK
Upon initializing the settings SDK, it will cache any prefetch settings and, if the 'ur' (user role) value is present in localStorage, it will store this 'ur' value in the indexedDB record for each setting.
When a user attempts to retrieve a setting, the SDK will verify whether the 'ur' value in localStorage differs from the cached value. If there is a mismatch, the SDK will clear the cache. Otherwise, the cached settings will be considered valid.
If the cached setting is deemed valid, the SDK will provide the cached setting. However, if the cached setting is not valid or there is no cached setting, the settings SDK will initiate a fetch call to obtain the latest settings, including the 'ur' value in the request URL.