We'll show you how to emit custom goals using our emitCustomGoal function.
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.
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.
The function uses the QP API and takes a single parameter, name
:
options.emitCustomGoal(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:
options.emitCustomGoal('Q006:appointment:booked')
and a corresponding advanced segment for users that completed the goal:
<segment>
<timeout type="never">
<condition
event="qubit.goalAchieved"
path="goalId"
type="Integer"
op="in"
value="497740"
/>
</timeout>
</segment>
TIP: When creating the advanced segment, you will 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 is this value that needs to be added to the Event action for it to be tracked as an experience goal:INFO: 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.