Setting up a test on a pop-in

Two steps are needed to create this kind of test: adding a JavaScript code to your page, then defining the targeting segment.

Adding the script

To add your script, you have two options:

  • Changing the page source code: use this option if you can, it is the most efficient.
  • Adding the script without changing the page source code: if you don't have access to your page source code, don't panic! Kameleoon has a solution for you. 

In the page source code

If you have the ability to change the source code of your page, you can simply trigger a JavaScript event when the pop-in opens and target the name of this event.

To do this, add to the code the instruction:

Kameleoon.API.triggerEvent("Event name") 

When the pop-in opens or when the visitor clicks on the "Add to the basket" button for instance.

Via your preferences

If you cannot change the source code of your page, Kameleoon offers a solution allowing you to add a personalized script on the fly. This script will run after each call of Kameleoon script on your pages.

To do this, login to your personal space and use the left menu to go to the "Configured sites" page.


Click on the "Configuration" button under the name of the website for which you want to create the A/B test.


Click on the "General" tab and add your script on the "Global custom script" box.


Here is an example of a personalized script you can use. You simply have to put the name of the event in the targeting of your test. Kameleoon will run the test only when receiving the JavaScript event.

//Use of the triggerEvent API function when the “Add to basket button” is triggered and opens the jQuery confirmation pop-in ("#add-to-cart-button").click(function(){
   Kameleoon.API.triggerEvent("KAM_POPUP_OPENED"); // The name of the event must be placed on the same level as the targeting configuration pop-up.

//Or, the use of the function as soon as the pop-in appears
Kameleoon.API.runWhenElementPresent("#POPUP_ELEMENT_ID", function(){
}, 200);

Via the editor

You can also add your script from the editor. To do so, click on the cogwheel on the top left of the header.

A pop-in opens, allowing you to inject your JavaScript code.

Make sure you have checked the "Also add the JavaScript and CSS code on the original", otherwise the result will not be registered for the original.

Targeting segment

When you launch your test, in the "Test finalizer" window, choose to run the test on "Specific advanced segment" to open the advanced targeting window.

If you have already created your segment, click on "A template segment" to select it.

In the "Technical" par, select the "Custom event" criterion.

Indicate the name of the event. It should correspond to the one you added on your JavaScript code. Kameleoon will only run the test when the event is triggered.

Have more questions? Submit a request
Powered by Zendesk