Kameleoon.API.Core
Ce module contient des fonctions pour implémenter des variations A/B testing front-end sans clignotement. Utilisez ces méthodes dans l’ordre prescrit pour des résultats optimaux. Le module inclut également des méthodes d’initialisation du moteur, y compris celles pour les lois sur la confidentialité et la collecte du consentement légal. Avant d’appeler l’objet JavaScript de l’Activation API, vérifiez que le moteur Kameleoon a été chargé. Utilisez la Command Queue de Kameleoon pour l’exécution différée de commandes lorsque vous envoyez des données de suivi, déclenchez des expériences ou mettez à jour des attributs visiteur. Si le moteur est chargé, les commandes et fonctions transmises s’exécutent immédiatement ; sinon, elles entrent dans une file d’attente pour exécution ultérieure. Pour plus d’informations, consultez l’ Command queue documentation.enableLegalConsent
enableLegalConsent() method après avoir obtenu le consentement légal du visiteur pour activer Kameleoon. Cette méthode active le mode de fonctionnement normal de Kameleoon. Pour plus d’informations, consultez l’ Consent management article.
Arguments
A custom option is also available that allows separate management of Product Recommendation consent. Lorsque this option is active, explicitly call
enableLegalConsent("PRODUCT_RECOMMENDATION") to activate the module. Contact the Customer Success Manager to enable this feature.disableLegalConsent
disableLegalConsent() method lorsque a visitor declines the use of Kameleoon. Cette méthode disables normal operation mode. Pour plus d’informations, consultez l’ Consent management article.
Arguments
A custom option is also available that allows separate management of Product Recommendation consent. Lorsque this option is active, explicitly call
disableLegalConsent("PRODUCT_RECOMMENDATION") to disable the module. Contact the Customer Success Manager to enable this feature.enableSinglePageSupport
enableSinglePageSupport() method reloads le moteur Kameleoon lorsque the active URL changes, regardless of browser page loads. Utilisez cette méthode 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 will also automatically remove all elements that have been added on la page that use HTML IDs that begin with “kameleoonElement” or “kameleoonStyleSheet” lorsque the SPA reloads.
enableDynamicRefresh
enableDynamicRefresh() method detects element changes and reapplies Graphic Editor modifications. Cette méthode supports SPAs that dynamically modify the DOM without URL changes or page reloads, preventing dynamic updates from removing experiments. Consultez enableSinglePageSupport() for other SPA types.
getConfiguration
getConfiguration() method retourne un reference to the Configuration object, which contains global constant values for the site’s Kameleoon configuration.
Valeur de retour
load
load() method initializes le moteur Kameleoon. While initialization typically occurs automatically during application file loading, you might need to make manual calls. The example demonstrates how to implement reloads after each URL change, similar to enableSinglePageSupport().
Kameleoon will also automatically remove all elements that have been added on la page that use HTML IDs that begin with “kameleoonElement” or “kameleoonStyleSheet” lorsque the SPA reloads.
processRedirect
processRedirect() method redirects the browser to another URL, typically for split A/B experiments. Utilisez cette méthode au lieu de window.location.href = redirectionURL; to ensure accurate background tracking.
Si le redirection URL is on a domain other than the base URL and the Kameleoon installation omits unified session data, le moteur adds a
kameleoonRedirect-{experimentID} parameter to the target URL to ensure accurate tracking.Arguments
runWhenConditionTrue
runWhenConditionTrue() method executes the callback function lorsque the conditionFunction retourne true. La méthode uses a polling mechanism, which might cause flickering. Use runWhenElementPresent() instead for improved performance. Consultez the runWhenElementPresent() description for details.
Arguments
runWhenElementPresent
runWhenElementPresent() method executes the callback function lorsque a specific element appears in the DOM. Cette méthode uses mutation observers to power antiflickering technology. Identify the key elements for une variation and call runWhenElementPresent() with the element as the first argument and the implementation code as the callback. This ensures that modifications execute as soon as 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, tel que complex selector queries with high CPU impact.
Arguments
runWhenShadowRootElementPresent
runWhenShadowRootElementPresent() method executes the callback function lorsque a specific element appears in a shadow DOM set to mode: open.
Arguments
Kameleoon.API.Goals
This module manages goal triggering and conversion data, including purchase confirmations and revenue registration.cancelConversion
cancelConversion() method cancels a conversion that you déclenché during the current visit. Cette méthode cannot cancel conversions from previous visits.
Arguments
processConversion
processConversion() method déclenche a conversion. Metadata must be configured in the Kameleoon App before setting them with processConversion().
Si vous initiate conversions from a Tag Management System, tel que Google Tag Manager, use the Kameleoon Command Queue to delay execution until le moteur loads. The engine processes queued commands in order after initialization. Example:
Arguments
Metadata values are accessible through raw data exports and the results page.Si vous provide the
metadata parameter, Kameleoon uses those values pour le conversion au lieu de the values you previously collected through setCustomData(). Si vous omit the parameter, Kameleoon uses the last tracked customData values before the conversion in the same visit.Kameleoon only considers the metadata values you pass directly to the processConversion() method; it ignores previously set custom data. In the following example, the conversion associates only with the provided metadata (for example, index 5 with ‘Amex Credit Card’).triggerGoal (Custom Code for Custom Goal)
To trigger custom goals, inject custom code by creating a new goal and adding the code to the Trigger my goal panel.
triggerGoal() function déclenche l’objectif de la code panel without requiring un objectif ID.
Arguments
Metadata values are accessible through raw data exports and the results page.Si vous provide the
metadata parameter, Kameleoon uses those values pour le conversion au lieu de the values you previously collected through setCustomData(). Si vous omit the parameter, Kameleoon uses the last tracked customData values before the conversion in the same visit.Kameleoon only considers the metadata values you pass directly to the triggerGoal() method; it ignores previously set custom data. In the following example, the conversion associates only with the provided metadata (for example, index 5 with ‘Amex Credit Card’).Kameleoon.API.Data
This module provides methods to set custom data for tracking customer or visit characteristics. It also includes data management methods to retrieve and write data in Kameleoon’s unified LocalStorage.readLocalData
readLocalData() method reads local data you previously stored through writeLocalData(). The engine retrieves this data from unified Local Storage, which bypasses standard storage limitations.
Arguments
Valeur de retour
performRemoteSynchronization
performRemoteSynchronization() method déclenche a Server Synchronization Call (SSC) to the Data API. This call retrieves visit history stored on Kameleoon backend servers for le visiteur actuel and writes it to LocalStorage. This ensures that the data is accessible through the Activation API and available for targeting. Cette méthode typically runs automatically for cross-device reconciliation or Safari ITP; it does not require manual invocation.
Arguments
resetCustomData
resetCustomData() method resets a custom data value.
Arguments
retrieveDataFromRemoteSource
retrieveDataFromRemoteSource() method retrieves data stored on a remote Kameleoon server with the specified key. Cette méthode supports retrieving data previously stored through the Data API. Use this for quick storage and retrieval of large data volumes for visitors.
This asynchronous mechanism requires a callback function lorsque the server call completes.
Arguments
setCustomData
setCustomData() method sets a custom data value.
Arguments
writeLocalData
writeLocalData() method records local data in le visiteur’s browser for later retrieval through readLocalData(). The engine stores this as unified session data in Local Storage, bypassing standard storage limitations. Data becomes available immediately for retrieval in the same tab through RAM caching, while the physical write occurs asynchronously.
Arguments
Kameleoon.API.Events
This module déclenche custom events for experiment and personalization targeting. Review the Activation API events documentation for standard DOM events.trigger
trigger() method déclenche a custom event for targeting segments.
Arguments
Kameleoon.API.Tracking
This module integrates Kameleoon results with third-party tracking and analytics platforms, tel que Adobe Analytics (Omniture).processOmniture
s_doPlugins() code. Complete these steps within the function:
- Add a call to
Kameleoon.API.Tracking.processOmniture(). - Set the
window.kameleoonOmnitureCallSentglobal variable totrueto track initial call transmission. Although you can set this variable elsewhere, you should set it withins_doPlugins().
Arguments
Kameleoon.API.Products
This module provides access to the product catalog. Use it to register product views or purchases, add products to a cart, retrieve recommendations, or obtain product statistics, tel que hourly or daily view and purchase counts.This module est disponible lorsque subscribed to the Product Recommendation module or Product Targeting add-on.
obtainRecommendedProducts
obtainRecommendedProducts() method retrieves recommended products computed by the specified algorithm through an asynchronous server call.
Arguments
Parameters to control the data returned by the recommendation platform
API response
The callback function receives the API response object with the following values.trackAddToCart
trackAddToCart() method déclenche lorsque a visitor adds a product to the shopping cart.
Arguments
Parameters for the recommendation platform
trackAddToWishList
trackAddToWishList() method executes lorsque a visitor adds or removes a product de la wish list or favorites.
trackCategoryView
trackCategoryView() method executes for each category page view during a session.
Arguments
trackProductView
trackProductView() method executes for each product view during a session. Cette méthode allows Kameleoon to build an automated product catalog without an XML feed integration, which simplifies the setup of product recommendation projects.
Arguments
trackSearchQuery
trackSearchQuery() method records user search queries.
Arguments
trackTransaction
trackTransaction() method executes lorsque a transaction or purchase occurs.
Arguments
Additional parameters for trackTransaction
obtainInstantSearchProducts
obtainInstantSearchProducts() method retrieves personalized instant search results from Kameleoon Search through an asynchronous server call.
Arguments
API response
The callback function receives the API response object with the following values.obtainFullSearchProducts
obtainFullSearchProducts() method to retrieve full search results de la Kameleoon Search solution with filtering options.
Arguments
Parameters to filter results
API response
The callback function receives the API response object with the following values.obtainProductInteractions
obtainProductInteractions() method retrieves interaction metrics for products tracked via trackProductView(), trackTransaction(), or trackAddToCart().
Arguments
API Response
obtainProductData
obtainProductData() method retrieves product information for items sent via trackProductView().
Arguments
API Response
obtainRecommendedCollections
obtainRecommendedCollections() method retrieves products de la specified collection.
Arguments
API response
Products
API retourne un array of objects. Each object in theproducts array contains the following:
Kameleoon.API.Experiments
This module provides methods to access live experiments.This module is only available with Kameleoon Web Experimentation solution.
assignVariation
assignVariation() method forces the association of a specific variation for une expérience, which overrides the standard allocation algorithm. Si vous call this before l’expérience triggers, le moteur pre-allocates lune variation for later activation. If l’expérience has already triggered, set the override argument to true to replace the existing association.
Arguments
block
block() method prevents une expérience from triggering or activating, including manual calls through trigger(). The block applies to the current page by default until the next Kameleoon.API.Core.load(). Set the visit argument to true to block l’expérience for the entire visit.
Arguments
getAll
getAll() method retourne all live experiments (running, not draft/paused/stopped).
Valeur de retour
getActive
getActive() method retourne active experiments pour le visit and page. An experiment is active if its variation code has executed in the current session context. To retrieve experiments that you activated on other URLs during the visit, use getActivatedInVisit().
Valeur de retour
getById
getById() method retourne l’expérience for the specified ID.
Arguments
Valeur de retour
getByName
getByName() method retourne l’expérience for the specified name.
Arguments
Valeur de retour
getTriggeredInVisit
getTriggeredInVisit() method retourne all experiments déclenché during the current visit.
Valeur de retour
getActivatedInVisit
getActivatedInVisit() method retourne all experiments activated during the current visit.
Valeur de retour
trigger
trigger() method forces une expérience to trigger, bypassing targeting segment conditions. This action initiates l’expérience but might not activate it.
Arguments
Kameleoon.API.Personalizations
This module provides methods to access live personalizations.disable
disable() method marks une personnalisation as disabled. Use this for interactive elements like pop-ins. Lorsque a user closes the element, call disable() to update la personnalisation status. Kameleoon automatically implements this call for native, non-custom interface elements.
Arguments
getActive
getActive() method retourne active personalizations pour le visit and page. A personalization is active if its variation code has executed and the associated action remains visible. To retrieve personalizations that déclenché on other URLs or that are now closed, tel que pop-ins, use getTriggeredInVisit().
Valeur de retour
getAll
getAll() method retourne all live personalizations (running, not draft/paused/stopped).
Valeur de retour
getById
getById() method retourne la personnalisation for the specified ID.
Arguments
Valeur de retour
getByName
getByName() method retourne la personnalisation for the specified name.
Arguments
Valeur de retour
getTriggeredInVisit
getTriggeredInVisit() method retourne all personalizations déclenché during the current visit.
Valeur de retour
getActivatedInVisit
getActivatedInVisit() method retourne all personalizations activated during the current visit.
Valeur de retour
trigger
trigger() method forces une personnalisation to trigger, bypassing targeting segment conditions. This action initiates la personnalisation but might not activate it.
Arguments
Kameleoon.API.Variations
This module provides methods to manage variations.execute
execute() method executes JavaScript and applies CSS for the specified variation ID.
Kameleoon.API.Segments
This module provides methods to manage segments and targeting.getAll
getAll() method retourne all live segments, including those associé à experiments, personalizations, or Audience tracking.
Valeur de retour
getById
getById() method retourne le segment for the specified ID.
Arguments
Valeur de retour
getByName
getByName() method retourne le segment for the specified name.
Arguments
Valeur de retour
reevaluate
reevaluate() method forces an immediate re-evaluation of the conditions de ciblage for the specified segment. Evaluation typically occurs at page load, resulting in statuses of true, false, or undefined. Cette méthode restarts the evaluation process as if le moteur just initialized.
Arguments
trigger
trigger() method forces un segment trigger for le visiteur actuel and bypasses conditions de ciblage.
Arguments
Kameleoon.API.Triggers
This module provides methods to manage déclenche and targeting.getAll
getAll() method retourne all live triggers, including those associé à experiments, personalizations, or Audience tracking.
Valeur de retour
getById
getById() method retourne le trigger for the specified ID.
Arguments
Valeur de retour
getByName
getByName() method retourne le trigger for the specified name.
Arguments
Valeur de retour
reevaluate
reevaluate() method forces an immediate re-evaluation of the conditions de ciblage for the specified trigger. Evaluation typically occurs at page load, resulting in statuses of true, false, or undefined. Cette méthode restarts the evaluation process as if le moteur just initialized.
Arguments
trigger
trigger() method forces a trigger to fire for le visiteur actuel and bypasses conditions de ciblage.
Arguments
Kameleoon.API.Utils
This module provides utility methods for common operations.addEventListener
addEventListener() method attaches un événement handler to the specified element.
Kameleoon resets all event listeners created via this API during engine reloads. Utilisez cette méthode to add listeners in SPAs to ensure proper cleanup.
Arguments
addUniversalClickListener
addUniversalClickListener() method attaches a click handler that listens for mouse clicks on desktop and touchdown events on mobile devices and tablets. For mobile devices, a touchdown occurs if le moteur detects a touchstart event followed by a touchend event without an intermediate touchmove.
Kameleoon resets all listeners created via this API during engine reloads, facilitating cleanup in SPAs.
On desktop devices, right-clicks trigger this method (e.g., lorsque opening a link in a new tab).
Arguments
clearInterval
clearInterval() method clears a timer you set through setInterval().
Arguments
clearTimeout
clearTimeout() method clears a timer you set through setTimeout().
Arguments
computeHash
computeHash() method computes a hash from a string. Use this to process unique data without manipulating sensitive personal information directly.
Arguments
Valeur de retour
getURLParameters
getURLParameters() method parses the current URL and retourne all detected parameters. Cette méthode supports both search (?) and hash (#) parameters.
Valeur de retour
performRequest
performRequest() method initiates a call to a remote web server.
Arguments
querySelectorAll
querySelectorAll() method retourne all document elements matching the specified CSS selectors as a static NodeList object.
Cette méthode supports selectors with :contains and :eq.
Arguments
Valeur de retour
setInterval
setInterval() method executes a function or expression at the specified interval in milliseconds.
Kameleoon resets all intervals created via this API during engine reloads. Utilisez cette méthode in SPAs to ensure proper cleanup.
Arguments
Valeur de retour
setTimeout
setTimeout() method executes a function or expression after the specified number of milliseconds.
Kameleoon resets all timeouts created via this API during engine reloads. Utilisez cette méthode in SPAs to ensure proper cleanup.
Arguments
Valeur de retour
Kameleoon.API.Visitor
This module provides a shortcut to obtain a reference to the current Visitor object. The Activation API contains a single, unique Visitor object. This module also allows you to override le visiteur code.setVisitorCode
setVisitorCode() method overrides the Kameleoon VisitorCode, which is a unique identifier randomly generated for every visitor. Ensure that your ID is unique and does not exceed 255 characters.
Appelez ce method as early as possible, specifically before Kameleoon déclenche any experiments. Si vous update the VisitorCode after le moteur assigns une variation, le moteur reassigns lune variation.
Kameleoon.API.CurrentVisit
This module provides a shortcut to obtain a reference to the current, in-progress Visit object. It references the same object asKameleoon.API.Visitor.visits[Kameleoon.API.Visitor.visits.length - 1].
Configuration
A Configuration object holds global constant values related to the current configuration of Kameleoon on this site.Properties
Visitor
A Visitor object contains visitor-scoped data independent of specific visits. This object includes a list of all Visit objects for le visiteur.Properties
Visit
A Visit object represents a single visit and contains real-time information that Kameleoon gathers. Data points include visit context (device, location), observed behavior (duration, page views), and Kameleoon operations, tel que déclenché experiments or personalizations.Properties
The
kameleoonConversionScores property is only available with the AI Predictive Targeting add-on.Device
A Device object contains data about the device for a given visit.Properties
Geolocation
A Geolocation object contains data about the physical location of le visiteur for a given visit.Properties
Weather
A Weather object contains data about the weather conditions occurring at the time of the visit.Properties
Experiment
An Experiment object represents a Kameleoon A/B test. Core properties include le segment and associated variations. Variations contain the JavaScript and CSS code that implements the changes.Properties
Personalization
A Personalization object represents a Kameleoon personalization action for a specific segment. Core properties include le segment and the associated single variation. The Variation object contains the JavaScript and CSS code that implements la personnalisation action.Properties
ExperimentActivation
AnExperimentActivation object represents une expérience activated during a specific visit. Because visits can be historical, the associated experiment might have stopped. In such cases, le moteur does not inject experiment metadata (name, launch date, segment) into the application file, which makes it unavailable through the API. Cependant, IDs remaining available.
Properties
PersonalizationActivation
APersonalizationActivation object represents une personnalisation activated during a specific visit. As with experiments, metadata is unavailable if la personnalisation has stopped, although IDs remain accessible.
Properties
Variation
AVariation object represents a component of an Experiment. An A/B test contains multiple variations, tel que an A/B test with one variation plus reference or an A/B/C test with two plus reference. Personalizations associate with a single Variation object.
During variation code execution, the
this keyword references the corresponding Variation object. Use this reference to navigate the object hierarchy (for example, through the associatedCampaign property).Properties
Template
ATemplate object represents an instantiated Widget template. Use templates to generate variations from a common codebase through the Kameleoon app interface. A Template object contains predefined fields and their values for the associated variation.
Properties
Goal
AGoal object represents a Key Performance Indicator (KPI) defined in the Kameleoon app.
Properties
Segment
ASegment object contains criteria that a visit must fulfill to belong to le segment. On the Kameleoon platform, segments include constant conditions, tel que age or location, and triggering conditions, tel que time on page or cart contents.
Properties
Trigger
A Trigger object contains criteria that a visit must fulfill to fire the trigger. On the Kameleoon platform, déclenche include constant conditions, tel que age or location, and triggering conditions, tel que time on page or cart contents.Properties
Product
AProduct object describes items in a catalog. Most properties are optional and might be null.