Custom goals in Compose can help you track more specific events or actions in an A/B test. Please note that Javascript code needs to be written for any custom goals. Your code will need to respond to some user action on your site and inform Compose that a custom goal has occurred.
Examples for common custom goals include:
- When a specific button is clicked
- When a link is clicked
- When a user submits a form
For example, we want to test the placement of the CTA on the homepage. It would be best in this case to compare engagement results only for visitors interacting with the CTA we’re testing. To achieve this we’ll create a custom goal called “hp-cta-click” to specifically track engagement with the homepage CTA.
After selecting our link by class name, we add a click event listener. Every time the CTA element is clicked we want to tell Compose that an event has occurred for our custom goal by dispatching an event, giving it a name prefixed with “goal:” followed by the name of our custom event “hp-cta-click”.
const el = document.querySelector('.hp-cta');
el.addEventListener('click', () => {
window.compose.dispatchEvent(new CustomEvent('goal:hp-cta-click'))
});
It is important to note that this portion in particular is how Compose knows to track a conversion for the custom goal:
window.compose.dispatchEvent(new CustomEvent('goal:hp-cta-click'))
Furthermore, this will only count at most one conversion per visitor. Although multiple clicks of the CTA button will in turn dispatch the goal event multiple times, Compose will count the first goal event as a conversion for the visitor and ignore all subsequent goal events of the same name.
In Compose, the custom goal is set up so that the Goal Name matches the name in the javascript code so that Compose knows where to count the conversion. In this case, the name is ‘hp-cta-click’ to match the code:
new CustomEvent('goal:hp-cta-click')
For custom goals, you will see the same type of table and graphs as you do for the default goals. The example below shows an experiment with a custom goal tracking orders that contain low inventory products.
Although custom goals are a great way to collect more information specific to the needs of a test, they are by no means necessary to running successful and meaningful A/B tests. Read more about our default goals here.