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 which are defined later on page(below the main tracking code inclusion point). This DMP (Data Management Platform) feature allows it to target for example lead score/stage from you Marketing Automation tool (like Marketo, Pardot, Elequou, Hubspot or Salesforce) without to many efforts.

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: 

convert_recheck_experiment()

When that code will execute, a re-check of the experiment's conditions will be scheduled for 50 ms later for the next about two minutes or until the experiment JS condition check is final(whichever comes first); let's take the following example 

(function() {
if(typeof(window.my_variable)=="undefined") {
convert_recheck_experiment(); return false;}
else return (window.my_var=="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 like this be defined later on page, after main Convert tracking script and experiment will be checked and will fire eventually when that variable is defined. 

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

  •  we would set the above condition into the Include part of the Site Area
  • into the Exclude part of the Site Area we would add a URL targeting rule like below: URL does not contain /test_page.html. Doing so, we'd include into 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 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" 

Have more questions? Submit a request

Comments