SDK setup and feature flag tutorial
caution
Always check the SDK documentation to ensure correct method names.
The methods below are from the Node.js SDK.
Some features or methods may not be available in all SDKs.
SDK checklist overview
This guide provides a step-by-step checklist to set up and use the Kameleoon SDK, configure Feature Flags, and optionally enable Hybrid Mode (SDK + engine.js).
1. Basics
One-time setup (in the SDK)
Step 1 – Install, configure, and initialize the SDK
- Install the SDK and configure it, paying attention to:
updateInterval: Defines how often the SDK fetches the latest configuration from Kameleoon.trackingInterval: Defines how often the SDK sends tracked data to Kameleoon.
- Create a new
KameleoonClientand callinitialize()to load configuration. - PHP SDK only: Install a cron job to collect data.
Step 2 – Set the visitor code
- Use
getVisitorCode()or a custom method to set thekameleoonVisitorCodecookie.
Step 3 (Optional) – Enable Cross-Device Experimentation & Custom Bucketing Key
- Cross-Device Experimentation: Share the same
kameleoonVisitorCodeacross devices. - Custom Bucketing Key: Show the same variation to a defined group of visitors (e.g., users from the same organization).
Step 4 – Handle consent
- If an experiment requires consent, call
setLegalConsent(). (Not needed if the feature flag type uses Delivery Rules.)
Step 5 – Send predefined data
- Use
addData()to target:- Device
- Browser
- Page URL
- Other predefined criteria
- Call
flush()to send data to Kameleoon.
(Note:flushis also called implicitly byisFeatureActive,getVariation, andtrackConversion.)
Step 6 – Exclude and tag bots
- Exclude bots from results using
addData()with theuserAgenttype. - To tag internal bots, pass
curl/8.0touserAgentinaddData().