Emit custom goals when working with experiences

This is for:


In this article, we’ll show you how to emit custom goals using our emitCustomGoal function.

What are custom goals?

Custom goals are a great option where you are looking to evaluate the success of an experience in triggering a QP event or getting the user to interact with a button or a similar UI element. Unlike the primary goal, which is Conversion Rate (CR) focused, an experiment might want to consider something different, such as clicks, joining a segment, or reaching a specific page type.

Custom goals are added to an experience using the emitCustomGoal function. This is typically added to triggers.js, where your want the goal to apply to both the control and any variations in an experience, but could equally be added to variation.js if you want the goal to be emitted when the visitor interacts with something you built specifically for the experience variation, for example, a button or similar UI element.

emitCustomGoal function

The function uses the QP API and takes a single parameter, name:


The function is bound to the options object of the variation or triggers and can be called as shown above. Any events sent through this are bound to the experience, and can only be tracked by the experience they are sent from.

Let’s look at a straightforward example, used in an experience to emit a custom goal when a user selects a button:


and a corresponding advanced segment for users that completed the goal:

  <timeout type="never">

When creating the advanced segment, you’ll need to pass in the goal Id, in the above example, 497740. You can get this by hovering your cursor over the goal in the Results tab for your experience.

In this example, we see that the goal Id is 643910



  • name: This is the name of the custom event you want to emit, and can be any string value. It’s this value that needs to be added to the Event action for it to be tracked as an experience goal:

advanced goals

We increment the count for a custom goal each time options.emitCustomGoal() is emitted. However, to ensure statistical accuracy, we only count once per iteration for each visitor when reporting progress against goals.