Targeting Experiments and Firing Goals Based on a JS Condition

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 many efforts.

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;

Note: The javascript expression will be evaluated into the global "window" context; 

Currently, it's possible to use the Javascript expression targeting in three locations:

  1. Advanced Goal Setup; a goal can be fired if the javascript condition used evaluates to true:
  2. Experiment Site Area; you can run an experiment on pages where a certain Javascript condition evaluates true:
  3. 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

Have more questions? Submit a request

Comments

  • Avatar
    Ken Hanson

    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:

    1. User shows up to page I'm experimenting on 
    2. User is given treatment A 
    3. User interacts with treatment 
    4. User triggers objective my treatment was trying to get them to trigger 
    5. "goalVariable" is now set to True 
    6. Upon next page load, the variation is attributed to a success/conversion because the experiment JS fires and checks the goal.

    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!

    Edited by Ken Hanson
  • Avatar
    George Crewe

    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.