Passer au contenu principal

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

Appelez la 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

Appelez la 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

The 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

The 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

The getConfiguration() method retourne un reference to the Configuration object, which contains global constant values for the site’s Kameleoon configuration.
Valeur de retour

load

The 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

The 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

The 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

The 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

The 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

The cancelConversion() method cancels a conversion that you déclenché during the current visit. Cette méthode cannot cancel conversions from previous visits.
Arguments

processConversion

Before implementing the processConversion, review the Custom Code for Custom Goal feature, which simplifies customization by removing the requirement for un objectif ID.
The 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.
The 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

The 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

The 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

The resetCustomData() method resets a custom data value.
Arguments

retrieveDataFromRemoteSource

The 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

The setCustomData() method sets a custom data value.
Arguments

writeLocalData

The 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

The 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

Kameleoon provides a native integration with Adobe Analytics (Omniture). Follow the example to modify the file containing the s_doPlugins() code. Complete these steps within the function:
  • Add a call to Kameleoon.API.Tracking.processOmniture().
  • Set the window.kameleoonOmnitureCallSent global variable to true to track initial call transmission. Although you can set this variable elsewhere, you should set it within s_doPlugins().
The integration minimizes the number of Adobe Analytics hits to help you manage costs. Kameleoon sends an additional hit only if une expérience or personalization déclenche after the main tracking call. This results from asynchronous loading (in which Kameleoon loads after the analytics code) or “late” triggers, tel que those that occur after page load, for example button clicks. If Kameleoon loads first and identifies active experiments at page load, the global tracking call includes all additional data.
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

The obtainRecommendedProducts() method retrieves recommended products computed by the specified algorithm through an asynchronous server call.
Cette méthode requires correct product tracking, tel que trackProductView() or trackCategoryView(), to return meaningful results.
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

The trackAddToCart() method déclenche lorsque a visitor adds a product to the shopping cart.
Arguments

Parameters for the recommendation platform

trackAddToWishList

The trackAddToWishList() method executes lorsque a visitor adds or removes a product de la wish list or favorites.

trackCategoryView

The trackCategoryView() method executes for each category page view during a session.
Arguments

trackProductView

The 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

The trackSearchQuery() method records user search queries.
Arguments

trackTransaction

The trackTransaction() method executes lorsque a transaction or purchase occurs.
Arguments
Additional parameters for trackTransaction

obtainInstantSearchProducts

The 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

Utilisez le 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

The obtainProductInteractions() method retrieves interaction metrics for products tracked via trackProductView(), trackTransaction(), or trackAddToCart().
Arguments
API Response

obtainProductData

The obtainProductData() method retrieves product information for items sent via trackProductView().
Arguments
API Response

obtainRecommendedCollections

The obtainRecommendedCollections() method retrieves products de la specified collection.
Arguments

API response

Products
API retourne un array of objects. Each object in the products 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

The 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

The 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

The getAll() method retourne all live experiments (running, not draft/paused/stopped).
Valeur de retour

getActive

The 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

The getById() method retourne l’expérience for the specified ID.
Arguments
Valeur de retour

getByName

The getByName() method retourne l’expérience for the specified name.
Arguments
Valeur de retour

getTriggeredInVisit

The getTriggeredInVisit() method retourne all experiments déclenché during the current visit.
Valeur de retour

getActivatedInVisit

The getActivatedInVisit() method retourne all experiments activated during the current visit.
Valeur de retour

trigger

The 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

The 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

The 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

The getAll() method retourne all live personalizations (running, not draft/paused/stopped).
Valeur de retour

getById

The getById() method retourne la personnalisation for the specified ID.
Arguments
Valeur de retour

getByName

The getByName() method retourne la personnalisation for the specified name.
Arguments
Valeur de retour

getTriggeredInVisit

The getTriggeredInVisit() method retourne all personalizations déclenché during the current visit.
Valeur de retour

getActivatedInVisit

The getActivatedInVisit() method retourne all personalizations activated during the current visit.
Valeur de retour

trigger

The 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

The 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

The getAll() method retourne all live segments, including those associé à experiments, personalizations, or Audience tracking.
Valeur de retour

getById

The getById() method retourne le segment for the specified ID.
Arguments
Valeur de retour

getByName

The getByName() method retourne le segment for the specified name.
Arguments
Valeur de retour

reevaluate

The 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

The 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

The getAll() method retourne all live triggers, including those associé à experiments, personalizations, or Audience tracking.
Valeur de retour

getById

The getById() method retourne le trigger for the specified ID.
Arguments
Valeur de retour

getByName

The getByName() method retourne le trigger for the specified name.
Arguments
Valeur de retour

reevaluate

The 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

The 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

The 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

The 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

The clearInterval() method clears a timer you set through setInterval().
Arguments

clearTimeout

The clearTimeout() method clears a timer you set through setTimeout().
Arguments

computeHash

The 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

The getURLParameters() method parses the current URL and retourne all detected parameters. Cette méthode supports both search (?) and hash (#) parameters.
Valeur de retour

performRequest

The performRequest() method initiates a call to a remote web server.
Arguments

querySelectorAll

The 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

The 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

The 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

The 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 as Kameleoon.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

An ExperimentActivation 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

A PersonalizationActivation 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

A Variation 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

A Template 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

A Goal object represents a Key Performance Indicator (KPI) defined in the Kameleoon app.

Properties

Segment

A Segment 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

A Product object describes items in a catalog. Most properties are optional and might be null.

Properties

Category

Properties

Param

An optional generic field that allows you to upload custom information about a product that does not fit in other fields. Par exemple, this information could be the membership status required to buy a product or departure and return dates for a travel circuit.

Properties

Fashion

An optional generic field that allows you to upload custom information about the product.

Properties

Color

Properties

Auto

An optional generic field that allows you to upload custom information about the product.

Properties

Compatible

Properties