Engine execution flow
Learn how the experimentation engine loads, tracks, and executes experiments.Experimentation engine overview
Kameleoon provides a single-platform optimization solution for web and full-stack app experimentation. The platform supports two primary solutions:- Web Experimentation: Conduct A/B testing and other forms of experimentation for websites and web applications.
- Feature Experimentation: Enable full-stack feature flagging and experimentation. Kameleoon also provides additional APIs and tools to eliminate flickering in A/B experiments, integrate with your existing tools, and automate tasks.
Code flow: loading
The Kameleoon engine runs theengine.js tag (previously kameleoon.js). Invoke this JavaScript tag through the HTML source code of your web pages.
At the entry point, the engine:
-
Activation: The
engine.jstag invokes an Activation API call throughKameleoon.Analyst.load(). - Command queue execution: After loading, the engine checks the kameleoonQueue array and executes commands in the order you pushed them. Use this for code that must run before Kameleoon instantiates functions.
Kameleoon only executes functions added to the queue with the
IMMEDIATE parameter.- Anti-flicker and global variables: Flickering occurs when the original page displays briefly before the variation appears. This effect can lead to inaccurate results. Kameleoon uses advanced techniques to eliminate flickering. If you configure anti-flicker, the system loads the Kameleoon script asynchronously with anti-flicker code.
window.KameleoonEndLoadTime variable stores the completion timestamp.
Adjust the timeout using the
kameleoonLoadingTimeout variable in the installation snippet. Kameleoon recommends keeping the default value of 750 milliseconds. This variable determines the maximum time the installation tag can delay page display while waiting for the application file.-
Check for blocking reasons: Before completing initialization, the engine checks for these blocking reasons:
- Storage: If local or session storage is unavailable, the engine terminates and returns the
Kameleoon::Abortedevent with theSTORAGEcode. - Timeout: If
engine.jstakes more than 750 ms to load and you configured the project to turn off Kameleoon for the page or visit, the engine returnsTIMEOUT. - Prerender: Kameleoon requires the document to be ready (
document.visibilityState == "prerender"). If it isn’t, the script terminates and returnsPRERENDER. It reloads when the visibility state changes. - Custom script: If a custom script aborts the session, the engine returns
SCRIPT. - Parameter: If the URL contains
KameleoonDisabled == true, the engine returnsPARAMETERand terminates. - Disabled: If you turn off the project in the dashboard, the engine returns
DISABLED. See this article for details.
- Storage: If local or session storage is unavailable, the engine terminates and returns the
Only a Kameleoon technical account manager can configure custom abortion scripts.
- Deferrals: The engine postpones code and campaigns for a second call if necessary. In this case, the engine fetches configuration and campaigns in SYNC mode from
https://SITECODE.kameleoon.com/engine-configuration.js(previously namedkameleoon-configuration.js) andhttps://SITECODE.kameleoon.com/engine-campaigns.js(previously namedkameleoon-actions.js), respectively.
Only a Kameleoon technical account manager can configure the option to defer all campaigns. You can defer specific experiments using the “DELAYED” tag.
Code flow: tracking
After initialization, Kameleoon retrieves visitor data:- Kameleoon collects technical data such as the visitor’s browser and operating system.
- If you enable unify session data across subdomains, Kameleoon retrieves past data using an iFrame on the main local storage domain.
- If you enable
real-time sync of visitsor thecross-deviceoption, the engine fetches usage history from Kameleoon servers.
Real-time sync is active by default for Kameleoon Feature Experimentation or for Safari to manage ITP impacts.
- The engine initializes a visitor. If no code exists in the
kameleoonVisitorCodecookie or local storage, the engine assigns a new visitor code and parses all visits. - The engine parses and stores data such as the Page URL, device, operating system, geolocation, and goals.
If you use the product recommendation add-on, Kameleoon instantiates the recommendation engine here.
- The global custom script executes any inserted JavaScript before initializing experiments.
- The global experiment script runs after the custom global script. This script executes regardless of targeting and stops when the experiment pauses. See this guide for details.
- The engine executes pending commands from the
CommandQueuethat don’t use theIMMEDIATEparameter. - The
Kameleoon::Startedevent triggers when initialization completes and the engine stores the data. - If you enable SPA management, Kameleoon monitors URL changes. When the URL changes, the engine reloads to ensure campaigns function correctly on the new view.
- Before initializing campaigns, Kameleoon:
- Checks for an ad blocker.
- Runs
mutationObserverto optimizequerySelectoroperations. - Fetches geolocation data from
https://eu-data.kameleoon.io/ipif the segment requires it.
- To load campaign configuration, Kameleoon fetches data from
https://SITECODE.kameleoon.com/live-experiments/config.jsand caches it for 2 minutes.
The Live Update Experiments feature refreshes experiments tagged with
LIVE-UPDATE to allow real-time configuration changes without browser caching delays.Tracking queue and activity events
The engine processes outgoing requests through an internal queue that runs approximately every 500 ms. The queue batches events and recursively sends additional batches if needed. On page unload or cleanup, the engine forces immediate processing of all queued events. In Safari, the engine persists unsent events to session storage to prevent data loss. The engine also sends an activity event every 60 seconds when it detects a scroll or click. When the engine detects no activity, it makes no additional tracking calls.Code flow: execution
When the experimentation loop runs, the engine:- If the visitor is part of a “holdout” group, the engine sends a holdout inclusion event.
- The engine triggers an exposure event containing a
nonce,experimentID, andvariationId. For example:eventType=experiment&nonce=5800F1BDD0667747&id=250830&variationId=978588. - If the visitor isn’t in a holdout group, the engine sends a “Holdout exclusion event.”
Holdout experiments allow you to manage and block other experiments:
- The engine checks for holdout experiments first.
- If a user is in a holdout group, the engine assigns them to a group and sends an event for reporting.
- If the user is in the reference group, the engine blocks all other experiments.
- If the user is in the variation group, the engine allows other experiments to proceed.
- PERSONALIZATION_CAPPING: The personalization reached its global visitor limit.
- SCHEDULE: The personalization is off based on its schedule.
- SCENARIO: Some scenario conditions remain unmet.
- PRIORITY: A higher-priority personalization exists.
- VISITOR_CAPPING: The visitor reached a limit preventing display.
DELAYED tag with an experiment, the engine triggers it after the first page load. The engine downloads variation data from https://SITECODE.kameleoon.com/(personalizations)/$campaign_id/variations/$variation_id.js.
Delaying an experiment is useful for popups or below-the-fold modifications where flickering is minimal.
https://SITECODE.kameleoon.com/audiences/segments.js to detect opportunities.
Kameleoon checks segments created or modified in the last 90 days, excluding those starting with
[DEV], [TEST], or [QA].FAQ
What network requests does the Kameleoon engine make?
What network requests does the Kameleoon engine make?
The Kameleoon engine initiates several network requests to ensure a seamless experience:
Segments request
- Purpose: Collects events for targeted segments by the visitor.
- Endpoint:
https://${SITECODE}.kameleoon.io/audiences/segments.js - Method: GET
- Note: The browser caches the file for 90 minutes.
Live-update experiments configuration request
- Purpose: Retrieves LIVE-UPDATE tagged experiments configuration.
- Endpoint:
https://${SITECODE}.kameleoon.io/live-experiments/config.js - Method: GET
- Note: The browser caches the file for 2 minutes.
Feature flag rules configuration request
- Purpose: Loads feature flag rules and variations from a file separate from the main configuration. The engine fires this request only when the site has at least one feature flag rule.
- Endpoint:
https://${SITECODE}.kameleoon.io/live-ff/config.js - Method: GET
- Note: To serve the file from your own location (for example, a proxy or CDN), set
window.kameleoonFeatureFlagRulesFileto the full URL before the Kameleoon engine loads. - Listener: To wait for this request to complete and run code only after the engine registers the feature flag rules, listen for the
Kameleoon::FeatureFlagFileLoadedevent:
Deferred experiment variation request
- Purpose: Loads variation data for DELAYED tagged experiments.
- Endpoint:
https://${SITECODE}.kameleoon.io/experiments/${action.id}/variations/${variationId}.js - Method: GET
- Note: The browser caches the file for 30 days.
Deferred personalization variation request
- Purpose: Loads variation data for DELAYED tagged personalizations.
- Endpoint:
https://${SITECODE}.kameleoon.io/personalizations/${action.id}/variations/${variationId}.js - Method: GET
- Note: The browser caches the file for 30 days.
Previous visits request
- Purpose: Obtains previous visits for cross-device reconciliation and real-time sync of visits.
- Endpoint:
https://(eu|na)-data.kameleoon.(eu|io)/visit/visitor - Method: GET
Tracking events request
- Purpose: Records events during visits.
- Endpoint:
https://(eu|na)-data.kameleoon.(eu|io)/visit/events - Method: POST
Kameleoon sends an event every 60 seconds when a scroll or click occurs. This ensures correct session length tracking. If the engine detects no activity, it makes no additional tracking call.
IP address request
- Purpose: Enables exclusion/inclusion of visitors based on IP address.
- Endpoint:
https://(eu|na)-data.kameleoon.(eu|io)/ip - Method: GET
- Note: Kameleoon never stores IPs in databases. The visitor’s browser employs the IP solely for comparison purposes.
Geolocation request
- Purpose: Obtains geolocation data for targeting and analytics.
- Endpoint:
https://(eu|na)-data.kameleoon.(eu|io)/geolocation - Method: GET
Current weather request
- Purpose: Returns current weather conditions.
- Endpoint:
https://(eu|na)-data.kameleoon.(eu|io)/weather/weather - Method: GET
Weather forecast request
- Purpose: Returns a 5-day weather forecast.
- Endpoint:
https://(eu|na)-data.kameleoon.(eu|io)/weather/forecast - Method: GET
Kameleoon script detection request
- Purpose: Detects the implementation status of the Kameleoon Script.
- Endpoint:
https://(eu|na)-data.kameleoon.(eu|io)/active-script/event - Method: POST
Products request
- Purpose: Gathers product events for targeting and recommendations.
- Endpoint:
https://(eu|na)-data.kameleoon.(eu|io)/product/events - Method: POST
Kameleoon conversion scores request
- Purpose: Retrieves predictive scores for targeting.
- Endpoint:
https://(eu|na)-data.kameleoon.(eu|io)/predict/latestPredictionScoreHistograms - Method: GET