Skip to main content
This module contains functions for implementing frontend A/B testing variations without flickering. The module also includes engine initialization methods, which cover privacy laws and legal consent collection.

enableLegalConsent

Call the enableLegalConsent() method after you obtain legal consent from the visitor to activate Kameleoon. This method activates Kameleoon’s normal operation mode. For more information, refer to the Consent management article.
Arguments
A custom option is also available that allows separate management of Product Recommendation consent. When this option is active, explicitly call enableLegalConsent("PRODUCT_RECOMMENDATION") to activate the module. Contact the Customer Success Manager to enable this feature.

disableLegalConsent

Call the disableLegalConsent() method when a visitor declines the use of Kameleoon. This method disables normal operation mode. For more information, refer to the Consent management article.
Arguments
A custom option is also available that allows separate management of Product Recommendation consent. When this option is active, explicitly call disableLegalConsent("PRODUCT_RECOMMENDATION") to turn off the module. Contact the Customer Success Manager to enable this feature.

enableSinglePageSupport

The enableSinglePageSupport() method reloads the Kameleoon engine when the active URL changes, regardless of browser page loads. Use this method for Single Page Applications (SPAs) with multiple URLs and a single initial load. Kameleoon treats each URL change as a new page, enabling URL targeting and accurate tracking of metrics like page views.
Kameleoon also automatically removes all elements added to the page that use HTML IDs that begin with “kameleoonElement” or “kameleoonStyleSheet” when the SPA reloads.

enableDynamicRefresh

The enableDynamicRefresh() method detects element changes and reapplies Graphic Editor modifications. This method supports SPAs that dynamically modify the DOM without URL changes or page reloads, preventing dynamic updates from removing experiments. Refer to enableSinglePageSupport() for other SPA types.

getConfiguration

The getConfiguration() method returns a reference to the Configuration object, which contains global constant values for the site’s Kameleoon configuration.
Return value

load

The load() method initializes the Kameleoon engine. While initialization typically occurs automatically during application file loading, you might need to make manual calls. To reload Kameleoon after each URL change in a single-page app, use enableSinglePageSupport() instead of watching the URL yourself.
Kameleoon also automatically removes all elements added to the page that use HTML IDs that begin with “kameleoonElement” or “kameleoonStyleSheet” when the SPA reloads.

processRedirect

The processRedirect() method redirects the browser to another URL, typically for split A/B experiments. Use this method instead of window.location.href = redirectionURL; to ensure accurate background tracking.
If the redirection URL is on a domain other than the base URL and the Kameleoon installation omits unified session data, the engine adds a kameleoonRedirect-{experimentID} parameter to the target URL to ensure accurate tracking.
Arguments

runWhenConditionTrue

The runWhenConditionTrue() method executes the callback function when the conditionFunction returns true. The method uses a polling mechanism, which might cause flickering. Use runWhenElementPresent() instead for improved performance. Refer to the runWhenElementPresent() description for details.
Arguments

runWhenElementPresent

The runWhenElementPresent() method executes the callback function when a specific element appears in the DOM. This method uses mutation observers to power antiflickering technology. Identify the key elements for a variation and call runWhenElementPresent() with the element as the first argument and the implementation code as the callback. Calling the method ensures that modifications execute when the element appears, before the browser initiates a display refresh cycle. To act on multiple elements, call runWhenElementPresent() separately for each element rather than targeting only the expected final element. A single call may result in flickering if a refresh cycle occurs between the appearance of different elements.
Providing this value disables Mutation Observers and Anti-Flickering, reverting to legacy polling. Use this argument only in specific cases, such as complex selector queries with high CPU impact.
Arguments

runWhenShadowRootElementPresent

The runWhenShadowRootElementPresent() method executes the callback function when a specific element appears in a shadow DOM set to mode: open.
Arguments