Coordinate Kameleoon SDKs across websites, mobile apps, and backend servers to maintain a unified visitor identity. This coordination ensures consistent experiment handling and data flow across all platforms. Use this guide if a project implements multiple Kameleoon SDKs:Documentation Index
Fetch the complete documentation index at: https://docs.kameleoon.com/llms.txt
Use this file to discover all available pages before exploring further.
- The JavaScript SDK or
engine.jsfor web environments. - The mobile SDK for Android or iOS apps.
- Server-side SDKs for backend integrations and decision logic.
Architecture overview
A typical multi-environment setup includes the following components:- Website: Uses the JavaScript SDK or
engine.jsto run client-side experiments and personalization campaigns. - Mobile app: Uses a mobile SDK to display variations and track conversions.
- Backend server: Uses a server-side SDK to make centralized variation decisions or synchronize visitor data.
Data and visitor code flow
- The visitor code identifies users consistently across all environments.
- The server-side SDK coordinates variation decisions when required.
- Each SDK sends analytics and tracking data directly to the Kameleoon platform.
Visitor code and cross-device management
Generate and share visitor codes
Each unique visitor must have one consistent visitor code across all platforms. This code allows Kameleoon to unify experiment decisions and tracking. Follow this cross-platform flow:- The engine, web SDK, server-side SDK, or mobile application generates the visitor code.
- The backend retrieves the existing visitor code when the user logs in on a new platform.
- The system passes the visitor code to the mobile, server-side, and web SDKs. This ensures all platforms evaluate the same user consistently.
Synchronize visitor codes
- Store the visitor code securely in the backend or user database and link it to the user ID.
- Follow these steps when a user login occurs on another platform:
- Mobile app: Request the visitor code from the backend.
- Server-side SDK: Use the same visitor code for all variation and tracking calls.
- Web SDK: Set the visitor code using the JavaScript API:
The web SDK and server-side SDK communicate automatically via the
kameleoonVisitorCode cookie. You do not need to perform additional steps to link these two.Best practices
- Map the existing user identifier (such as
userId) to a single Kameleoon visitor code across all platforms. - Maintain the backend as the source of truth for visitor codes.
- Prevent SDKs from overwriting existing visitor codes for known users.
Experiment handling across environments
Coordinate decisions and variation displays for experiments that span multiple environments, such as mobile and backend.Example scenario
In this scenario:- The mobile app displays the variation.
- The backend server determines the assigned variation.
Implementation options
Option 1: Server-side decision logic- The mobile app sends the visitor code to the backend.
- The server-side SDK calls
getVariation()(or its equivalent) to retrieve the assigned variation. - The backend returns the variation ID or name to the mobile app.
- The mobile app displays the variation and tracks exposure.
- Both the mobile and server SDKs use the same visitor code for tracking events.
- Centralizes variation logic and ensures consistent decisions.
- Supports experiments that affect both backend logic and UI elements.
- The mobile SDK retrieves the variation assignment using the visitor code.
- The mobile app applies the variation locally and tracks exposure directly.
- (Optional) If the backend also participates in tracking or validation, the server-side SDK reuses the same visitor code to ensure consistent reporting.
- Provides a synchronous, zero-latency decision.
- Reduces latency by avoiding a server round trip.
- Optimizes UI-focused experiments that do not depend on backend logic.
Choose the right setup
| Use case | Decision layer | Visitor code source | Notes |
|---|---|---|---|
| Mobile UI experiment | Mobile SDK | Backend | Handles variation locally |
| Backend or API-driven | Server-side SDK | App or website | Centralized decision logic |
| Cross-device consistency | Any | Backend | Ensures unified tracking |
Code examples: Pass visitor code between layers
To handle SDK implementation across different layers:
- Assign a single visitor code per user across all platforms.
- Manage and distribute visitor codes from the backend.
- Select the variation logic layer based on the experiment type (server for centralized logic, client-side for app-driven UI).
- Maintain consistent, cross-device data by tracking all user activity with the same visitor code.