Optimize for non-Webflow sites

API: Trigger custom goals

Updated

Trigger custom goal tracking using the JavaScript API sendEvent().

Important

All JavaScript APIs in Optimize must be wrapped in a .ready() callback to run properly.

Use the sendEvent() API to trigger a goal event that's recorded in an associated custom goal in Optimize. This lets you track clicks, form submissions, purchases, or other custom actions that default optimization goals don’t capture. You can call this API with or without an optional value property.

sendEvent()

Without the optional value:

intellimize.sendEvent(apiName);

With the optional value:

intellimize.sendEvent(apiName, { value: amount });

About apiName

The apiName is the value you define when setting up a custom goal in Optimize. It must be 40 printable ASCII characters or fewer, and can’t contain spaces.

Formatting the value property

Use this format: { value: amount }. The amount must meet the following conditions:

  • Can be a string or a number
  • Must not be negative — e.g., 10 is valid, -10 is not
  • Can include up to two decimal places — e.g., 10, 10.5, 10.50
  • Must not include currency symbols — e.g., 10.50 is valid, $10.50 is not

To ensure two-decimal accuracy:

Number.parseFloat(rawValue).toFixed(2);

Record dynamic values

You can also use this API to record goal values that vary based on user action — for example, the total purchase amount when someone clicks a “Buy” button in a shopping cart.

var apiName = 'purchase';
var price = document.getElementById('total_price').value;
intellimize.sendEvent(apiName, { value: price });

Use with Google Tag Manager

It’s common to track conversions using Google Tag Manager (GTM), and you may already have triggers set up for actions you'd like to track in Optimize. In that case, you can create a custom HTML tag that calls sendEvent() and use one of your existing GTM triggers to fire it.

For example, if you already have a Facebook tracking pixel that fires on a “Form Submission” trigger, you can reuse that same trigger to call sendEvent():

<script>
intellimize.ready(function() {
  intellimize.sendEvent('form-submitted');
});
</script>