Kameleoon.API.Core
Dieses Modul enthält Funktionen für die Implementierung von Frontend-A/B-Test-Variationen ohne Flackern. Verwenden Sie diese Methoden in der vorgeschriebenen Reihenfolge für optimale Ergebnisse. Das Modul umfasst auch Methoden zur Engine-Initialisierung, einschließlich derjenigen für Datenschutzgesetze und die Erfassung der rechtlichen Einwilligung. Bevor Sie aufrufen das JavaScript-Objekt der Activation API, stellen Sie sicher, dass die Kameleoon-Engine geladen wurde. Verwenden Sie die Kameleoon Command Queue für die verzögerte Befehlsausführung, wenn Sie Tracking-Daten senden, Experimente auslösen oder Besucherattribute aktualisieren. Wenn die Engine geladen ist, werden übergebene Befehle und Funktionen sofort ausgeführt; andernfalls werden sie für die spätere Ausführung in eine Warteschlange gestellt. Weitere Informationen finden Sie im Command queue Dokumentation.enableLegalConsent
enableLegalConsent() method nachdem Sie die rechtliche Einwilligung des Besuchers zur Aktivierung von Kameleoon erhalten haben. Diese Methode aktiviert den normalen Betriebsmodus von Kameleoon. Weitere Informationen finden Sie im Consent management Artikel.
Arguments
A custom option is also available that allows separate management of Product Recommendation consent. Wenn 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 wenn a visitor declines the use of Kameleoon. Diese Methode disables normal operation mode. Weitere Informationen finden Sie im Consent management article.
Arguments
A custom option is also available that allows separate management of Product Recommendation consent. Wenn 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 die Kameleoon-Engine wenn the active URL changes, regardless of browser page loads. Verwenden Sie diese Methode 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 die Seite that use HTML IDs that begin with “kameleoonElement” or “kameleoonStyleSheet” wenn the SPA reloads.
enableDynamicRefresh
enableDynamicRefresh() method detects element changes and reapplies Graphic Editor modifications. Diese Methode supports SPAs that dynamically modify the DOM without URL changes or page reloads, preventing dynamic updates from removing experiments. Siehe enableSinglePageSupport() for other SPA types.
getConfiguration
getConfiguration() method gibt ein reference to the Configuration object, which contains global constant values for the site’s Kameleoon configuration.
Rückgabewert
load
load() method initializes die Kameleoon-Engine. 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 die Seite that use HTML IDs that begin with “kameleoonElement” or “kameleoonStyleSheet” wenn the SPA reloads.
processRedirect
processRedirect() method redirects the browser to another URL, typically for split A/B experiments. Verwenden Sie diese Methode anstelle von window.location.href = redirectionURL; to ensure accurate background tracking.
Wenn das redirection URL is on a domain other than the base URL and the Kameleoon installation omits unified session data, die Engine adds a
kameleoonRedirect-{experimentID} parameter to the target URL to ensure accurate tracking.Arguments
runWhenConditionTrue
runWhenConditionTrue() method executes the callback function wenn the conditionFunction gibt zurück true. Die Methode uses a polling mechanism, which might cause flickering. Use runWhenElementPresent() instead for improved performance. Siehe the runWhenElementPresent() description for details.
Arguments
runWhenElementPresent
runWhenElementPresent() method executes the callback function wenn a specific element appears in the DOM. Diese Methode uses mutation observers to power antiflickering technology. Identify the key elements for eine 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, wie etwa complex selector queries with high CPU impact.
Arguments
runWhenShadowRootElementPresent
runWhenShadowRootElementPresent() method executes the callback function wenn 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 ausgelöst during the current visit. Diese Methode cannot cancel conversions from previous visits.
Arguments
processConversion
processConversion() method löst aus a conversion. Metadata must be configured in the Kameleoon App before setting them with processConversion().
Wenn Sie initiate conversions from a Tag Management System, wie etwa Google Tag Manager, use the Kameleoon Command Queue to delay execution until die Engine loads. The engine processes queued commands in order after initialization. Example:
Arguments
Metadata values are accessible through raw data exports and the results page.Wenn Sie provide the
metadata parameter, Kameleoon uses those values für den conversion anstelle von the values you previously collected through setCustomData(). Wenn Sie 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 löst aus das Ziel von der code panel without requiring ein Ziel ID.
Arguments
Metadata values are accessible through raw data exports and the results page.Wenn Sie provide the
metadata parameter, Kameleoon uses those values für den conversion anstelle von the values you previously collected through setCustomData(). Wenn Sie 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
Rückgabewert
performRemoteSynchronization
performRemoteSynchronization() method löst aus a Server Synchronization Call (SSC) to the Data API. This call retrieves visit history stored on Kameleoon backend servers for der aktuelle Besucher and writes it to LocalStorage. This ensures that the data is accessible through the Activation API and available for targeting. Diese Methode 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. Diese Methode 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 wenn the server call completes.
Arguments
setCustomData
setCustomData() method sets a custom data value.
Arguments
writeLocalData
writeLocalData() method records local data in der Besucher’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 löst aus custom events for experiment and personalization targeting. Review the Activation API events documentation for standard DOM events.trigger
trigger() method löst aus a custom event for targeting segments.
Arguments
Kameleoon.API.Tracking
This module integrates Kameleoon results with third-party tracking and analytics platforms, wie etwa 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, wie etwa hourly or daily view and purchase counts.This module verfügbar ist wenn 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 löst aus wenn a visitor adds a product to the shopping cart.
Arguments
Parameters for the recommendation platform
trackAddToWishList
trackAddToWishList() method executes wenn a visitor adds or removes a product von der 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. Diese Methode 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 wenn 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 von der 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 von der specified collection.
Arguments
API response
Products
API gibt ein 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 ein Experiment, which overrides the standard allocation algorithm. Wenn Sie call this before das Experiment triggers, die Engine pre-allocates die Variation for later activation. If das Experiment has already triggered, set the override argument to true to replace the existing association.
Arguments
block
block() method prevents ein Experiment 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 das Experiment for the entire visit.
Arguments
getAll
getAll() method gibt zurück all live experiments (running, not draft/paused/stopped).
Rückgabewert
getActive
getActive() method gibt zurück active experiments für den 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().
Rückgabewert
getById
getById() method gibt zurück das Experiment for the specified ID.
Arguments
Rückgabewert
getByName
getByName() method gibt zurück das Experiment for the specified name.
Arguments
Rückgabewert
getTriggeredInVisit
getTriggeredInVisit() method gibt zurück all experiments ausgelöst during the current visit.
Rückgabewert
getActivatedInVisit
getActivatedInVisit() method gibt zurück all experiments activated during the current visit.
Rückgabewert
trigger
trigger() method forces ein Experiment to trigger, bypassing targeting segment conditions. This action initiates das Experiment but might not activate it.
Arguments
Kameleoon.API.Personalizations
This module provides methods to access live personalizations.disable
disable() method marks eine Personalisierung as disabled. Use this for interactive elements like pop-ins. Wenn a user closes the element, call disable() to update die Personalisierung status. Kameleoon automatically implements this call for native, non-custom interface elements.
Arguments
getActive
getActive() method gibt zurück active personalizations für den visit and page. A personalization is active if its variation code has executed and the associated action remains visible. To retrieve personalizations that ausgelöst on other URLs or that are now closed, wie etwa pop-ins, use getTriggeredInVisit().
Rückgabewert
getAll
getAll() method gibt zurück all live personalizations (running, not draft/paused/stopped).
Rückgabewert
getById
getById() method gibt zurück die Personalisierung for the specified ID.
Arguments
Rückgabewert
getByName
getByName() method gibt zurück die Personalisierung for the specified name.
Arguments
Rückgabewert
getTriggeredInVisit
getTriggeredInVisit() method gibt zurück all personalizations ausgelöst during the current visit.
Rückgabewert
getActivatedInVisit
getActivatedInVisit() method gibt zurück all personalizations activated during the current visit.
Rückgabewert
trigger
trigger() method forces eine Personalisierung to trigger, bypassing targeting segment conditions. This action initiates die Personalisierung 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 gibt zurück all live segments, including those verknüpft mit experiments, personalizations, or Audience tracking.
Rückgabewert
getById
getById() method gibt zurück das Segment for the specified ID.
Arguments
Rückgabewert
getByName
getByName() method gibt zurück das Segment for the specified name.
Arguments
Rückgabewert
reevaluate
reevaluate() method forces an immediate re-evaluation of the Targeting-Bedingungen for the specified segment. Evaluation typically occurs at page load, resulting in statuses of true, false, or undefined. Diese Methode restarts the evaluation process as if die Engine just initialized.
Arguments
trigger
trigger() method forces ein Segment trigger for der aktuelle Besucher and bypasses Targeting-Bedingungen.
Arguments
Kameleoon.API.Triggers
This module provides methods to manage löst aus and targeting.getAll
getAll() method gibt zurück all live triggers, including those verknüpft mit experiments, personalizations, or Audience tracking.
Rückgabewert
getById
getById() method gibt den trigger for the specified ID.
Arguments
Rückgabewert
getByName
getByName() method gibt den trigger for the specified name.
Arguments
Rückgabewert
reevaluate
reevaluate() method forces an immediate re-evaluation of the Targeting-Bedingungen for the specified trigger. Evaluation typically occurs at page load, resulting in statuses of true, false, or undefined. Diese Methode restarts the evaluation process as if die Engine just initialized.
Arguments
trigger
trigger() method forces a trigger to fire for der aktuelle Besucher and bypasses Targeting-Bedingungen.
Arguments
Kameleoon.API.Utils
This module provides utility methods for common operations.addEventListener
addEventListener() method attaches ein Ereignis handler to the specified element.
Kameleoon resets all event listeners created via this API during engine reloads. Verwenden Sie diese Methode 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 die Engine 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., wenn 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
Rückgabewert
getURLParameters
getURLParameters() method parses the current URL and gibt zurück all detected parameters. Diese Methode supports both search (?) and hash (#) parameters.
Rückgabewert
performRequest
performRequest() method initiates a call to a remote web server.
Arguments
querySelectorAll
querySelectorAll() method gibt zurück all document elements matching the specified CSS selectors as a static NodeList object.
Diese Methode supports selectors with :contains and :eq.
Arguments
Rückgabewert
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. Verwenden Sie diese Methode in SPAs to ensure proper cleanup.
Arguments
Rückgabewert
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. Verwenden Sie diese Methode in SPAs to ensure proper cleanup.
Arguments
Rückgabewert
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 der Besucher 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.
Rufen Sie diese method as early as possible, specifically before Kameleoon löst aus any experiments. Wenn Sie update the VisitorCode after die Engine assigns eine Variation, die Engine reassigns die 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 der Besucher.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, wie etwa ausgelöst 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 der Besucher 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 das 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 das Segment and the associated single variation. The Variation object contains the JavaScript and CSS code that implements die Personalisierung action.Properties
ExperimentActivation
AnExperimentActivation object represents ein Experiment activated during a specific visit. Because visits can be historical, the associated experiment might have stopped. In such cases, die Engine does not inject experiment metadata (name, launch date, segment) into the application file, which makes it unavailable through the API. Allerdings, IDs remaining available.
Properties
PersonalizationActivation
APersonalizationActivation object represents eine Personalisierung activated during a specific visit. As with experiments, metadata is unavailable if die Personalisierung has stopped, although IDs remain accessible.
Properties
Variation
AVariation object represents a component of an Experiment. An A/B test contains multiple variations, wie etwa 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 das Segment. On the Kameleoon platform, segments include constant conditions, wie etwa age or location, and triggering conditions, wie etwa 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, löst aus include constant conditions, wie etwa age or location, and triggering conditions, wie etwa time on page or cart contents.Properties
Product
AProduct object describes items in a catalog. Most properties are optional and might be null.