SDK setup and configuration Copy page Copy link View Markdown Configure the page and visitor context once, then follow the rendering and tracking guidance for your integration style. For the full lists of setters, attributes, and types, see the SDK reference. Recommended rollout order Assume item metadata integration is already in place outside the frontend SDK. For production integrations, do not treat recommendation rendering as a substitute for event integration. Froomle models still rely on baseline event history, so the recommended rollout keeps event tracking live before recommendation placements are introduced. Recommended order: Complete item metadata integration outside the frontend SDK. Configure shared SDK state on every relevant page (setEnvironment, setPageVisit, and setContextItem on detail pages). Connect your consent manager so the SDK uses the visitor’s choice and receives updates. Enable page-level and business event tracking first. Verify page_visit, detail_pageview, and any manual retail/business events before enabling recommendations broadly. Choose who renders and tracks each placement. If a list can show original content, supply its item identity. See Benchmarking and A/B Testing with the SDK for assignment and per-list content policy. Add recommendation placements or programmatic recommendation requests. Verify recommendation attribution events (impression, click_on_recommendation) once recommendations are actually rendered. By integration style: Script-tag / declarative: SDK init can send page_visit or detail_pageview even before any recommendation placeholder is added. The SDK tracks eligible impressions and clicks on cards it registers. See Tracking server-rendered recommendations for cards your application fills itself. React: mount FroomleSdkInit for automatic page events. Render hook results through FroomleReco for automatic recommendation tracking, or send recommendation events explicitly if your application renders the finished cards itself. Programmatic JS/TS: initialize SDK state first, call trackCurrentPage() for the current page, and send business events through the dedicated helpers (sendAddToCart(…), sendRemoveFromCart(…), sendPurchase(…), sendStartSubscription(…), sendCancelSubscription(…), …), or sendEvent(…) for custom events. Add getRecommendations(…) / proxy requests later. Recommendation placements: choose what each list shows and who renders it when implementing the placement. Page and business events do not choose a list’s content policy. Development and production If you are new to the SDK, separate the two onboarding goals clearly: Development path: Start with one script tag and one recommendation placeholder. Confirm a recommendation request reaches the browser network tab. Add detail-page context (context_item) for article/product pages. Production rollout: Complete item metadata integration outside the frontend SDK. Initialize shared SDK state and enable page/business event tracking first. Verify consent handling and add permitted identity and history. Choose the recommendation integration shape for each placement. Check what each list should show to each group. Use the SDK defaults unless you need external assignment or a different list policy. Add recommendation placements. Move to module-based setup (npm import), programmatic APIs, or React bindings when your frontend architecture requires them. Rendering patterns by integration style Choose the SDK integration pattern that matches your frontend architecture. Mode Integration style Use when Declarative HTML attribute-centric (data-froomle-…) You want SDK-driven DOM population from placeholders. Works for plain HTML and SSR templates (including JSP-generated markup). Declarative JS/TS bootstrap + HTML attributes You initialize SDK in JS/TS (setEnvironment, setPageVisit, …), while recommendation blocks are still mapped with data-froomle-…. Programmatic JS/TS API-centric You fetch recommendations directly in code with getRecommendations or proxyReco and render your own UI. Programmatic Component-centric (React bindings) You use @froomle/frontend-sdk/react (useCreateReco, FroomleReco, FroomleOrder, …) to compose recommendation UI in React. JSP + TS is the same integration model as JS/TS bootstrap + HTML attributes. The main difference is only where markup is rendered (server template vs client template generation). Runtime Scope Guide Use this quick map to choose the correct sections for your integration runtime: Runtime Sections to use Notes Script-tag/global (froomle.global.js) Script-Tag Setup, Script Loading and Initialization Modes, Script-tag Whitelist Uses HTML script attributes and init hooks (froomle:before-init, froomle:init). Module/import (JS/TS bundles) Module Setup, Core Configuration, Programmatic API (JS/TS) Use imported setters (setEnvironment, setPageVisit, setConsent, …). If you render declarative data-froomle-… placeholders from a module/import setup, call init() explicitly after those setters. React bindings Module Setup, React Bindings, Core Configuration React apps use module/import setup. Script-tag init hooks do not apply. Shared (all runtimes) Core Configuration, Recommendations in Markup, Programmatic API (JS/TS) Setting semantics are shared across runtimes. Only bootstrap/initialization entrypoint differs. Shared Runtime State vs Recommendation Block Configuration Across runtimes, distinguish between shared SDK runtime state and per-block or per-request configuration. Common page/app-level runtime state is typically set once for the current page context: setEnvironment(…) setPageVisit(…) setChannel(…) setSiteContext(…) for an optional analytics-context override setSubscriptionLevel(…) setUtmTrackingEnabled(…) when URL UTM enrichment must be disabled setReferrerTrackingEnabled(…) when browser referrer enrichment must be disabled setConsent(…) setDeviceId(…) setUserId(…) setContextItem(…) setContextItemType(…) Optional runtime-wide overrides such as setRequestDomain(…), setSafeRequest(…), setRecommendationsBearer(…), and setRecommendationsBearerProvider(…) are also configured centrally when your integration requires them. Benchmark assignment and the default list policy are shared startup settings. Set them with setCurrentGroup(…) or configureBenchmark(…) only if you need to change the defaults. In browser integrations, site_context defaults to window.location.hostname when available. Use setSiteContext(…) only when you need to override that with a customer-defined analytics context such as example.com or specific.example.com; the SDK sends the effective value as site_context on Events API payloads and leaves recommendation request payloads unchanged. Site context defaulting works as follows: Applies in browser-based SDK integrations: script-tag/DOM, JS/TS module, React, and browser programmatic flows. Runs when the browser SDK module is evaluated, before automatic DOM/React events are emitted. Uses the page hostname from window.location.hostname, not the Froomle request domain or API host. Does not apply in non-browser runtimes where window.location is unavailable, for example server-side rendering or backend-only code. Does not affect recommendation request payloads; it is event analytics metadata only. Does not override an explicit value from data-froomle-site-context, setSiteContext(…), or per-event extras.site_context. To disable the event field entirely, call setSiteContext("") before the first event is sent. In script-tag integrations, do this in froomle:before-init; an empty data-froomle-site-context="" attribute is ignored by bootstrap and does not clear the hostname default. Script-tag override or disable example: <script> window.addEventListener("froomle:before-init", function (event) { const sdk = event.detail.sdk // Override the hostname default: sdk.setSiteContext("specific.example.com") // Or disable site_context entirely before automatic events: // sdk.setSiteContext("") }, { once: true }) </script> Module/React override or disable example: import { setSiteContext } from '@froomle/frontend-sdk' // Override the hostname default before rendering/initializing the SDK: setSiteContext('specific.example.com') // Or disable site_context entirely before the first event: // setSiteContext('') Use setSubscriptionLevel(…) for the current visitor entitlement state; accepted values are NONE, REGISTERED, TRIAL, and SUBSCRIPTION. The SDK sends it as subscription_level on Events API payloads and leaves recommendation request payloads unchanged. This field describes the visitor state, not a recommended item’s access_type and not the subscription_type used by subscription lifecycle events. Browser UTM tracking is enabled by default for campaign attribution. When an event is sent, the SDK reads standard UTM parameters from the current window.location URL and adds them to Events API payloads only. Recommendation request payloads are unchanged. Supported URL parameters are: utm_id, utm_source, utm_medium, utm_campaign, utm_source_platform, utm_term, utm_content, utm_creative_format, and utm_marketing_tactic. UTM tracking behavior: Applies in browser-based SDK integrations: script-tag/DOM, JS/TS module, React, and browser programmatic flows. Reads the current URL at event-send time. The SDK does not persist UTM parameters in cookies, localStorage, or sessionStorage. Does not apply in non-browser runtimes where window.location is unavailable, for example server-side rendering or backend-only code. Does not affect recommendation request payloads; it is event analytics metadata only. Does not override explicit event fields. If a manual event passes extras.utm_source, that value wins over the URL value for that event. Coexists with email campaign attribution. Froomle email attribution fields such as campaign_id, list_name, and request_id stay separate from generic UTM fields. To disable URL UTM enrichment before the first event, call setUtmTrackingEnabled(false). In script-tag integrations, you can also set data-froomle-utm-tracking="false" on the SDK script tag. Call setUtmTrackingEnabled(true) to enable it again for later events. Script-tag UTM opt-out example: <script defer src="https://cdn.jsdelivr.net/npm/@froomle/frontend-sdk/dist/froomle.global.js" data-froomle-utm-tracking="false"> </script> Module/React UTM opt-out example: import { setUtmTrackingEnabled } from '@froomle/frontend-sdk' setUtmTrackingEnabled(false) Browser referrer tracking is enabled by default for current-page source attribution. When an event is sent, the SDK reads window.location.href with the URL fragment removed and the browser-standard document.referrer, then adds page/source fields to Events API payloads only. Recommendation request payloads are unchanged. The SDK sends: page_url: the current page URL from window.location.href with the URL fragment removed referrer_url: the previous page URL as exposed by document.referrer referrer_type: direct, internal, or external referrer_origin: the parsed referrer origin, for example https://www.google.com referrer_domain: the parsed referrer hostname, for example www.google.com Referrer tracking behavior: Applies in browser-based SDK integrations: script-tag/DOM, JS/TS module, React, and browser programmatic flows. Reads window.location.href with the URL fragment removed at event-send time. Reads document.referrer at event-send time. Sends referrer_type: "direct" when the browser exposes no referrer. Classifies a non-empty same-hostname referrer as internal; a non-empty different-hostname referrer as external. Does not apply in non-browser runtimes where document.referrer is unavailable, for example server-side rendering or backend-only code. Does not affect recommendation request payloads; it is event analytics metadata only. Does not override explicit event fields. If a manual event passes extras.page_url, extras.referrer_url, or extras.referrer_domain, that value wins over the browser-derived value for that event. Coexists with URL UTM tracking and email campaign attribution. If a page has UTM parameters and a browser referrer, both sets of fields can be sent on the same event. Sends referrer_url only as exposed by browser document.referrer; depending on referrer policy this can be empty, origin-only, or a full URL. To disable browser referrer enrichment before the first event, call setReferrerTrackingEnabled(false). In script-tag integrations, you can also set data-froomle-referrer-tracking="false" on the SDK script tag. Call setReferrerTrackingEnabled(true) to enable it again for later events. Script-tag referrer opt-out example: <script defer src="https://cdn.jsdelivr.net/npm/@froomle/frontend-sdk/dist/froomle.global.js" data-froomle-referrer-tracking="false"> </script> Module/React referrer opt-out example: import { setReferrerTrackingEnabled } from '@froomle/frontend-sdk' setReferrerTrackingEnabled(false) If a page contains multiple recommendation blocks, reuse that shared SDK state across all of them. If the page context changes in an SPA or hybrid navigation flow, update the page-level setters once for the new route/context. Per-block or per-request configuration is usually supplied separately for each recommendation block or API call: recommendation list name and sizing (limit / list_size in programmatic, React, and smart-sort flows; number of placeholders in regular declarative DOM flows) block-specific filters and variables the list’s optional showFroomleContentFor policy, which changes content selection without changing the visitor’s group recommendation request arguments passed to getRecommendations(…), useCreateReco(…), or useRecoList(…) block-specific rendering and layout In script-tag integrations, shared runtime state usually lives on the SDK script tag or in froomle:before-init, while per-block configuration lives on the recommendation placeholders. In React and programmatic integrations, shared runtime state is typically initialized once in the app/bootstrap layer, while each recommendation block or API call provides its own list/filter/rendering configuration. Module Setup (JS/TS/React/JSP Bundles) npm install @froomle/frontend-sdk Initialize shared SDK state in code: import { setEnvironment, setPageVisit } from '@froomle/frontend-sdk' setEnvironment('your_env') setPageVisit('home') Pass the visitor’s actual CMP choice to the imported setConsent(level) before starting work. See Consent. Module/import setup has two valid bootstrap shapes: React and purely programmatic JS/TS integrations do not call init(). If your module/import integration also uses declarative data-froomle-… placeholders, call init() explicitly after the shared SDK setters to start DOM placeholder mode. Consent Setter Name by Runtime Use the consent setter name that matches how the SDK is loaded: Runtime mode Consent call Script-tag/global (froomle.global.js) setFroomleConsent(level) or window.FroomleFrontendSdk.setConsent(level) Module/import (npm install @froomle/frontend-sdk) setConsent(level) from import { setConsent } … Local Development For static HTML files, avoid file:// and run a local server: python3 -m http.server 8080 For module projects, run your framework/bundler dev command (for example npm run dev or npm run serve). Core Configuration This section defines setting semantics shared across runtimes. For setter scope (shared page/app runtime state vs per-block or per-request configuration), use Runtime Scope Guide. For script-tag timing and hook placement (what must be set before the first request), use Script Loading and Initialization Modes and Supported Inputs by Location. React follows module/import setup and does not use script-tag init hooks. Environment and Page Visit (Required) Set both before requesting recommendations. Script-tag setup: <script src="https://cdn.jsdelivr.net/npm/@froomle/frontend-sdk@latest/dist/froomle.global.js" data-froomle-env="sample_env" data-froomle-page-visit="home" ></script> Module setup: import { setEnvironment, setPageVisit } from '@froomle/frontend-sdk' setEnvironment('sample_env') setPageVisit('home') Identity: device_id and user_id Let the SDK manage the device ID in a normal browser integration. Supply a separate account ID only when your application knows who is signed in. device_id identifies the browser instance. The SDK supplies a real device ID on recommendation requests, including when tracking is off. user_id identifies a signed-in account. Use an opaque account ID, not an email address or name. The SDK sends it only at consent level 2 and only if you supply it. SDK-managed device ID At levels 0 and 1, the SDK uses an in-memory device ID. It does not load or persist the ID via the froomle_device_id cookie at those levels. A new page without consent to persist the ID gets a new in-memory ID. When consent rises to 2, the SDK keeps the current in-memory ID and persists it in the first-party froomle_device_id cookie. When the page starts at level 2 before a device ID has been issued, the SDK can reuse an existing valid cookie. When consent drops from 2 to 1 or 0, the SDK clears its device cookie and switches to a new in-memory ID. A later grant persists that new ID; it does not restore the withdrawn ID. Repeating the same consent level does not rotate it. If your application intentionally manages its own device identity, use setDeviceId(id) or set data-froomle-device-id on the SDK script tag. The supplied ID takes precedence. The SDK does not persist or rotate that ID for you; your application owns when it is appropriate to provide or change it. If you do not need an override, leave it unset. When Froomle consent is 0, don’t reuse a persistent device ID. Leave the override unset so the SDK can manage the ID, or supply a fresh ID that you keep only in memory for the current page. If consent is withdrawn after you’ve supplied an ID, your application must replace it before making further requests at level 0. The SDK sends no tracking events at that level, but reusing the ID can still link a recommendation request to earlier activity. Account identity and logout Supply the current logged-in account ID with setUserId(id) in the browser or data-froomle-user-id on the SDK script tag. The SDK does not persist the account ID in storage. Supply it again on each full page load that has an authenticated account. When the user signs out without a reload, call setUserId(null); do not send a shared ID for anonymous visitors. Browser storage The browser SDK does not use localStorage. Consent cookie (froomle_consent): An explicit consent setter attempts to save the chosen level, including 0. The default level and the startup tag do not create this cookie by themselves. Device cookie (froomle_device_id): The SDK uses this cookie to load or persist an SDK-managed device ID only at level 2. It clears the cookie when consent drops below 2. The SDK does not persist an ID supplied by your application. Email click deduplication (sessionStorage): When dispatching an eligible SDK email click, the SDK stores a deduplication key for the current tab. This applies to landing-page URL parameters and explicit attribution helpers. Pending attribution held before consent permits tracking is kept in memory, not in sessionStorage. Consent Your consent management platform (CMP) is the source of truth. Map your CMP’s vendor and purpose settings to an SDK consent level and forward the initial choice and every change, including withdrawal. The SDK does not decide which CMP settings represent consent for your integration. Consent behavior Level Recommendation requests SDK events 0 Device ID, no account ID or pageview history. Not sent. 1 Device ID, no account ID or pageview history. Sent without an account ID. 2 Device ID, plus the account ID and eligible pageview history when available. Sent with the account ID when supplied. Recommendation requests include the numeric consent_level. Request-local histories.exclude can still be sent below level 2 to avoid returning items already on the page. It is not pageview history. Consent and experiment assignment are separate decisions: a consent level is not a benchmark group. Startup consent and later updates For script-tag integrations, the SDK uses these sources in order: The latest explicit consent setter call, if one has been made. A valid saved froomle_consent cookie. A valid data-froomle-consent value on the SDK script tag. Level 0 if none of the above applies. Use the tag only as a startup fallback when it reflects the current visitor’s known choice. Do not put a consent grant in shared or cached markup. Reading the tag at startup does not save a new consent choice. An explicit setter updates the live level and attempts to save it in the consent cookie. Later changes to the script attribute are not consent updates; use the setter. Script tag: Call setFroomleConsent(level) or window.FroomleFrontendSdk.setConsent(level). In froomle:before-init, use event.detail.sdk.setConsent(level) to apply a known CMP choice before the first request. Module imports, including React: Import setConsent from @froomle/frontend-sdk. Supply the CMP value in your browser bootstrap before starting work and forward later updates with the same setter. The setter accepts numeric 0, 1, and 2, or the exact strings "0", "1", and "2". Invalid input throws a RangeError without changing consent. Connect an external consent manager Use the SDK’s froomle:before-init hook to connect your existing CMP. Register the listener before the SDK script tag. The hook lets you apply an available CMP decision before the first recommendation request. Use the same setter for later changes; you do not need to read or write the SDK’s consent cookie yourself. The hook does not wait for an asynchronous CMP decision. If the CMP is still loading when it runs, leave the level unset to use the SDK’s startup fallback. Calling setConsent(0) explicitly changes the level and attempts to save it; it does not mean “still waiting.” The example below shows how to wait for a CMP decision before any SDK requests or events. The page waits before inserting the SDK tag, then uses the same hook to apply the decision. This does not block the rest of the page. A confirmed level 0 still allows recommendation requests, but not tracking events. window.siteConsent is your application’s CMP adapter, not an SDK API: whenReady() waits for a decision, getFroomleLevel() reads it, and onChange() subscribes to later decisions. <script type="module"> const consent = window.siteConsent await consent.whenReady() window.addEventListener('froomle:before-init', ({ detail: { sdk } }) => { const syncConsent = () => { const level = consent.getFroomleLevel() if (level !== undefined) sdk.setConsent(level) } consent.onChange(syncConsent) syncConsent() }, { once: true }) const script = document.createElement('script') script.src = 'https://cdn.jsdelivr.net/npm/@froomle/frontend-sdk@latest/dist/froomle.global.js' script.dataset.froomleEnv = 'your_env' script.dataset.froomlePageVisit = 'home' document.head.appendChild(script) </script> With module imports, use the imported setConsent to apply an available decision before calling init(), mounting the SDK’s React components, or making programmatic requests. If you need a confirmed decision before any SDK activity, wait for it before taking those steps. For later changes, call the setter again; do not rerun initialization or remount components. Automatic tracking after consent changes In automatic DOM and React integrations, forward the CMP change with the consent setter. The SDK can refresh mounted recommendation placements under the new consent state, with fresh recommendation request IDs. It measures the eligible cards that are visible after the change; it does not replay impressions or clicks blocked before consent. Reapplying the same level does not start a new observation period. Automatic current-page tracking is independent of the recommendation response. After an increase from 0 to 1 or 2, the SDK can record the current page. An increase from 1 to 2 can record a separate current-page observation even if one was sent at level 1. A decrease does not initiate a new automatic page event. Events already sent are not rewritten. For purely programmatic integrations, recommendation fetching and event calls remain explicit. trackCurrentPage() can record the current page when consent permits; calling it does not fetch or fill recommendations. If you use email recommendation links, see Email campaign attribution for the separate pending-attribution behavior. Request Domain, Channel, and Transport Use these when needed: setRequestDomain('your.domain') setSafeRequest(false) for non-HTTPS/local environments setChannel('www-desktop' | 'www-mobile') If you want to run SDK traffic on your own subdomain, follow Custom domain (CNAME) for DNS, SSL, and SDK setup steps. Responsive channel example: import { setChannel } from '@froomle/frontend-sdk' const channel = window.matchMedia('(max-width: 767px)').matches ? 'www-mobile' : 'www-desktop' setChannel(channel) Recommendation Authentication By default, browser SDK integrations do not need bearer auth for recommendation requests. Use the auth setters only when your recommendation API is configured to require a bearer token in the browser. Recommendation auth only affects recommendation requests. Tracked events (page_visit, detail_pageview, impression, click_on_recommendation) remain unauthenticated in the current SDK. Rules: Keep client_id and client_secret on your backend. Do not call /oauth/token from the browser. Configure auth before the first recommendation request. Use setRecommendationsBearer(token) when your backend already rendered a short-lived token into the page. Use setRecommendationsBearerProvider(async ({ forceRefresh }) ⇒ token) when the browser should ask your backend for a token. This section only covers how the frontend SDK receives and uses a bearer token. The actual OAuth token flow, client-credentials exchange, token refresh strategy, and backend responsibilities are documented in Authentication Flow. When to use which pattern: Static bearer: backend-rendered pages, SSR templates, or any flow where a valid token is already available synchronously. Provider: frontend apps that need to fetch a token from a minimal backend endpoint and refresh it after a 401. Static bearer in script-tag/global usage: <script> window.__FROOMLE_RECO_BEARER__ = '{{ server_rendered_short_lived_token }}' window.addEventListener('froomle:before-init', function (event) { var sdk = event.detail && event.detail.sdk if (!sdk) return sdk.setRecommendationsBearer(window.__FROOMLE_RECO_BEARER__) }, { once: true }) </script> <script defer src="https://cdn.jsdelivr.net/npm/@froomle/frontend-sdk@latest/dist/froomle.global.js" data-froomle-env="your_env" data-froomle-page-visit="home" ></script> Static bearer in module and React usage: import { setEnvironment, setPageVisit, setRecommendationsBearer } from '@froomle/frontend-sdk' setEnvironment('your_env') setPageVisit('home') setRecommendationsBearer(window.__FROOMLE_RECO_BEARER__) Provider behavior: The SDK waits for the provider before the first recommendation request. If the recommendation request returns 401, the SDK calls the provider once more with forceRefresh: true. The SDK retries the recommendation request once with the refreshed token. Provider callback in script-tag/global usage: <script> window.addEventListener('froomle:before-init', function (event) { var sdk = event.detail && event.detail.sdk if (!sdk) return sdk.setRecommendationsBearerProvider(async function (options) { var forceRefresh = !!(options && options.forceRefresh) var response = await fetch( '/your-backend/froomle-recommendations-token?refresh=' + (forceRefresh ? '1' : '0'), { credentials: 'include' } ) if (!response.ok) { throw new Error('Token endpoint failed with status ' + response.status) } var body = await response.json() return body.token }) }, { once: true }) </script> <script defer src="https://cdn.jsdelivr.net/npm/@froomle/frontend-sdk@latest/dist/froomle.global.js" data-froomle-env="your_env" data-froomle-page-visit="home" ></script> Provider callback in module and React usage: import { setEnvironment, setPageVisit, setRecommendationsBearerProvider } from '@froomle/frontend-sdk' setEnvironment('your_env') setPageVisit('home') setRecommendationsBearerProvider(async ({ forceRefresh }) => { const response = await fetch( '/your-backend/froomle-recommendations-token?refresh=' + (forceRefresh ? '1' : '0'), { credentials: 'include' } ) if (!response.ok) { throw new Error(`Token endpoint failed with status ${response.status}`) } const body = await response.json() return body.token }) React uses the same auth setters from @froomle/frontend-sdk. The React package @froomle/frontend-sdk/react provides rendering bindings, not separate auth APIs. Minimum Initialization Automatic DOM recommendations require a non-blank environment and page type. Without either setting, the SDK does not request automatic recommendations or change publisher markup. These examples use the default benchmark configuration; register any external assignment before initialization. Wire up your consent manager separately before enabling tracking. Minimal module-based setup (programmatic or React): import { setEnvironment, setPageVisit } from '@froomle/frontend-sdk' setEnvironment('sample_env') setPageVisit('home') Minimal module + markup setup (explicit DOM mode): import { init, setEnvironment, setPageVisit } from '@froomle/frontend-sdk' setEnvironment('sample_env') setPageVisit('home') init() Minimal plain HTML setup: <script defer src="https://cdn.jsdelivr.net/npm/@froomle/frontend-sdk@latest/dist/froomle.global.js" data-froomle-env="sample_env" data-froomle-page-visit="home" ></script>