enableLegalConsent
Call theenableLegalConsent() 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.
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 thedisableLegalConsent() method when a visitor declines the use of Kameleoon. This method disables normal operation mode. For more information, refer to the Consent management article.
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
TheenableSinglePageSupport() 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
TheenableDynamicRefresh() 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
ThegetConfiguration() method returns a reference to the Configuration object, which contains global constant values for the site’s Kameleoon configuration.
load
Theload() 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
TheprocessRedirect() 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.runWhenConditionTrue
TherunWhenConditionTrue() 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.
runWhenElementPresent
TherunWhenElementPresent() 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.
runWhenShadowRootElementPresent
TherunWhenShadowRootElementPresent() method executes the callback function when a specific element appears in a shadow DOM set to mode: open.