The Kameleoon platform offers a JavaScript-based Activation API for retrieving data (such as visitor geolocation) and modifying engine behavior (such as manual variation assignment). However, developers must ensure the Kameleoon Engine loads before accessing the Activation API. This requirement complicates embedding JavaScript code directly in HTML files. The Kameleoon Command Queue provides delayed command execution, similar to Google Analytics. Instead of calling the Activation API via theDocumentation Index
Fetch the complete documentation index at: https://docs.kameleoon.com/llms.txt
Use this file to discover all available pages before exploring further.
Kameleoon.API object, pass commands and functions to the kameleoonQueue object. The engine executes these commands immediately if loaded; otherwise, it queues them for execution when ready.
Usage and description of the Command Queue Object
To use thekameleoonQueue object, execute the following initialization code first. The Kameleoon installation tag typically includes this code at the top of the HTML file, after the opening <head> tag. In this case, no further action is required. However, if using a custom setup (for example, loading Kameleoon via a Tag Manager), initialize the queue before adding custom code.
kameleoonQueue acts as a standard JavaScript array that accepts commands via the push() method. After loading, the engine processes the array and executes commands in order. The engine then replaces the array with a custom object whose push() method executes commands immediately.
Syntax
Pass either an array or an anonymous function to thepush() method.
Use either the full method name (e.g.,
Kameleoon.API.Core.enableLegalConsent) or the short name (e.g., Core.enableLegalConsent). Additional arguments are optional.kameleoonQueue before the browser encounters the targeted HTML element to ensure click tracking, even if the engine has not loaded.
By default, Kameleoon executes queued commands when the configuration (campaigns, goals, segments, etc.) is ready and after the global custom script runs.Use the In this example, the
level: "IMMEDIATE" argument when pushing a command to execute it immediately, without waiting for configuration processing. This is useful for code required before Kameleoon instantiates functions.Here’s an example of how to use the level: "IMMEDIATE" argument:callback function executes immediately, regardless of configuration processing.Use the level: "IMMEDIATE" argument to override internal Kameleoon functions. Standard function redefinition fails if the engine loads and executes the original version first. The IMMEDIATE level ensures the custom function executes before the engine loads its own version.