JavaScript API (Client-Side API)

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

runWhenElementPresent

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);

runWhenConditionTrue

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);

processRedirect

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. 

triggerEvent

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.

Kameleoon.API.triggerEvent(eventName)
      • eventName : Name of the event to trigger.

processConversion

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.

processOmniture

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) {
	Kameleoon.API.processOmniture(s);
}
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.

loadScriptSequentially

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

Kameleoon.API.loadScriptSequentially(script_url)
  • script_url : external site URL to load in the variation code.

For instance:

Kameleoon.API.loadScriptSequentially("https://www.votrescript.com/script.js")

readLocalData

This function allows to read the value of a cookie.

Kameleoon.Utils.readLocalData(cookieName)
  • cookieName : Name of the cookie from which you want to find out the value.

For instance:

Kameleoon.Utils.readLocalData("monCookie")

createLocalData

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