JavaScript API (Client-Side API)

Kameleoon offers you an API and some functions allowing you to handle a specific behavior or complex tests.


This function allows you to execute a JavaScript function as soon as a specific element has been found on the page by Kameleoon (identified with a CSS selector) 

Kameleoon.API.runWhenElementPresent(selector, targetFunction, pollDelay)
  • selector : CSS selector.
  • targetFunction : JavaScript function to execute when the element is found by Kameleoon.
  • pollDelay : Search interval, in miliseconds. Kameleoon will try to find the element with a regular interval. 
Par exemple :
Kameleoon.API.runWhenElementPresent("#bloc-2345", function(){ jQuery("#bloc-2345").text("Mon nouveau texte"); }, 200);


This function allows you to execute a JavaScript function as soon as the conditionFunction function returns true

Kameleoon.API.runWhenConditionTrue(conditionFunction, targetFunction, pollDelay)
  • conditionFunction : JavaScript function to execute. Must return true or false.
  • targetFunction : JavaScript function to execute when the conditionFunction function returns true.
  • pollDelay : Search interval, in miliseconds. Kameleoon will execute the conditionFunction function with a regular interval.
Par exemple :
Kameleoon.API.runWhenConditionTrue(function(){ return typeof jQuery != "undefined"; }, function(){ jQuery("#bloc-2345").text("Mon nouveau texte"); }, 200);


This function allows you to manage split URL tests.

Kameleoon.API.processRedirect(redirectionURL, crossDomain)
      • redirectionURL : URL of the page toward which the visitor will be redirected.
      • crossDomain : Place the true value if it is a redirection to another domain. 


This function allows to trigger an JavaScript event. This can be very useful for A/B tests on pop-ups for instance.

When the pop-up opens, call the Kameleoon.API.triggerEvent("popup_opened") function to indicate to Kameleoon that the test should run. Then, when you set up your test in the editor, you simply have to define an advanced targeting with a custom event and to indicate the name of your event popup_opened.

      • eventName : Name of the event to trigger.


Kameleoon.API.processConversion(nameOrId, conversionRevenue)
      • nameOrId : Name of the goal as it was defined during the goal creation in Kameleoon reporting tool.
      • conversionRevenue (Optional) : Amount of the transaction. This must be a number.


If you are using the Omniture plugin, doPlugins, the processOmniture function must be called in the plugin code for Kameleoon to return the results of your test in your reporting tool. Add these lines:

if (window.Kameleoon) {
Warning: The "s" variable in the processOmniture() function must be your Omniture object. By default, this variable is called "s". To test if the doPlugin function is used, you can type in the following command in your web console: s_doPlugins. If it returns an error, the function is not used on your website.


This function allows to load an external JavaScript library, for instance to test a Zopim or LivePerson plugin.

  • script_url : external site URL to load in the variation code.

For instance:



This function allows to read the value of a cookie.

  • cookieName : Name of the cookie from which you want to find out the value.

For instance:



This function allows to create a cookie on your web browser.

Kameleoon.Utils.createLocalData(cookieName, cookieValue, expirationInDays)
  • cookieName : Name of the cookie to create.
  • cookieValue (Optional): cookie value
  • expirationInDays (Optional) : Amount of days before the expiration of the cookie. If this parameter is not indicated, Kameloon will create a session cookie.

For instance

Kameleoon.Utils.createLocalData("monCookie", "maValeur", 1)
Have more questions? Submit a request
Powered by Zendesk