Target Based on JavaScript Condition
You might want to fire a conversion or run an experiment when some sort of JavaScript expression evaluates to "true".
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 too much effort.
Important Note: Any JavaScript used inside the expression has to be defined before the main Convert Experiments tracking code. If they are defined later on the page, their values cannot be used at the time of evaluation and the condition might not be matched. Convert also provides a convert.recheck() function to evaluate the condition every 50ms for 2 minutes, as the variable might not be declared when the convert script executes. You can find more information about it in this article.
Note: The javascript expression will be evaluated into the global "window" context.
Currently, it is possible to use the JavaScript expression targeting in three locations:
- Advanced Goal Setup - a goal can be fired if the JavaScript condition used evaluates to true:
- Experiment Locations - you can run an experiment on pages where a certain Javascript condition evaluates true:
- Experiment Audience - You can run an experiment for a certain group of visitors. For example, if one has a certain JavaScript variable holding the visitor status (client or anonymous), then it would be possible to run an experiment only for clients:
Keywords: trigger goal, trigger conversion
I'm not 100% clear on the Important Note at the top of the article here, specifically with regards to Goals.
It's confusing because: often during an experiment, a user will trigger the goal. But according to the important note, the goal truthy statement has to be defined before the main convert experiments tracking code. If a goal is going to get triggered via an injected experiment, shouldn't the goal be able to be tracked during an experiment session and not before / after?
Just thinking through the lifecycle of an experiment:
The risk with the above, if I'm understanding correctly is that the user could potentially never trigger an additional page load for the JS Condition Goal to get caught (they're done and leave the site). So I can't have the goal set before the page load, and the user leaves the site after the goal evaluates to true but before the script can check the experiment again.
The above scenario is probably uncommon, I just want to make sure that if this is the behaviour of JS Condition Goals, I know about it so that I can make sure goals are tracked appropriately.
Is there a way to use the `convert_recheck_experiment();` to always check for a JS Condition Goal that will get defined late?
Will the `convert_recheck_experiment();` also recheck the goals on its own?
Thanks for any help in more clearly defining this!
Hello Ken,
You touch a very important point.
Regarding JS Conditions on the goal context, they will only be checked on page load when the initial polling occurs, or if it is triggered again at some stage. You can find how to trigger the polling in the SPA article page
At this stage, we do not have a way to poll for JS Conditions of goals without triggering the whole polling sequence. So, you have to do it with Custom JS Goals which can be triggered via a JS event, or a GTM event.
I have added this as a feature request to our product manager.
We have recheck_goals available now - search for "Goals checked through polling" in the following article:
https://support.convert.com/hc/en-us/articles/205159975-Running-Experiments-on-Single-Page-Apps