Target experiment based on a custom Javascript condition that evaluates true at a later stage

Experiments are evaluated as soon as the Convert Experiences tracking script loads. Sometimes it's needed to fire an experiment based on values of variables that are defined later on the page (below the main tracking code inclusion point). This DMP (Data Management Platform) feature allows it to target, for example, lead score/stage from your Marketing Automation tool (like Marketo, Pardot, Elequou, Hubspot, or Salesforce) without much effort.

In that case, we can use a custom javascript condition targeting rule and an API call to re-check the experiment later.

Inside the JS condition, the following JS API function can be used: 


When that code executes, a re-check of the experiment's conditions is scheduled for 50 ms later, for approximately the next two minutes, or until the experiment JS condition check is final (whichever comes first).  Here is an example:

(function() {
if(typeof(window.my_variable)=="undefined") {
convert_recheck_experiment(); return false;}
else return (window.my_variable == "test_value");

In the above example, we check if variable window.my_variable is defined at the run time; if not we call the API function to recheck in 50ms; if it's defined, we check its value against test_value and return true or false, depending on whether they match or not. The window.my_variable can be defined later on the page, after the main Convert tracking script, and the experiment will be checked and fired when that variable is defined. 


The above type of targeting can be combined with the URL targeting type. If we wanted to fire the experiment like above but only for a page that has path /test_page.html:

  •  we would set the above condition into the Locations JS condition
  • and we would add a URL targeting rule like below: URL does not contain /test_page.html. In doing so, we'd include the experiment pages where the JS condition is true but exclude all the pages that do not contain /test_page.html  into the URL (therefore just the ones that contain /test_page.html  will be included)

There are multiple use cases of this functionality limited only by the imagination of whoever uses it. It's worth mentioning one other common use case: fire the experiment when an element was added to the page (maybe via Ajax); the JS condition would look something like the below:

(function() {
if(convert.$("element_selector").length==0) {
convert_recheck_experiment(); return false;}
else return true;

Note: In the above code, convert.$ is the instance of jQuery included by Convert.

keywords: "DMP", "Data Management Platform" 

Need assistance? Start a conversation with our Support Team.

Reliably Convert More Site Visitors, Even If Everything Else is Changing in Your Business.

✓ No Credit Card  ✓ Easy Set-Up  ✓ Access All Features