Custom Event Tracking with Javascript

Define any activity and track it within Klaviyo. Use events to trigger messages through flows or for custom reporting.

Events, also referred to as metrics, record actions that customers take on your website, in response to an email, or through any other data source where customer behavior takes place. Using the _learnq object that's automatically added by the Klaviyo web tracking snippet, the track method can be leveraged to capture all kinds of custom events.

Klaviyo's event tracking and analytics are very flexible; customize events to keep track of what's important to your business, whether you're building a custom integration or looking to track additional events within a native Klaviyo integration.

Track an Event

If you already have our onsite javascript, _learnq should be available to you. You will likely have installed klaviyo.js during your account setup, however, if you need to install web tracking check out the web tracking setup wizard.

📘

When you add Klaviyo's web tracking snippet to your site, we are only able to track the browsing activity of "known browsers" - browsers that have visited and engaged at least once before. Klaviyo will not track anonymous browsers. Read more about Klaviyo Web Tracking.

The track method accepts the custom event name as a string, and can be given any name you require:
_learnq.push(['track', 'Custom Event Name'])

It also accepts an optional dictionary or hash of properties associated with that event. For example, if you wanted to include properties associated with recently viewed items:

_learnq.push(["trackViewedItem", {
     "Title": item.ProductName,
     "ItemId": item.ProductID,
     "Categories": item.Categories,
     "ImageUrl": item.ImageURL,
     "Url": item.URL
     }
   }])

The track method accepts a variety data types:

  • strings
  • numbers
  • booleans
  • dates

You can also track events when a customer clicks a custom button you have defined. In this example, an event listener tracks when a customer clicks a "Like" button on an item, creating an Added Like custom event. We can then set up a custom flow trigger to send emails to customers about items they've "liked" or view reports on "liked" items.

<script type="text/javascript">
    var _learnq = _learnq || [];
    document.getElementById("Like").addEventListener('click',function (){
        _learnq.push(['track', 'Added Like', item]);
    });
</script>

Note that if you wish to send custom events to a customer's profile, that customer must be cookied. Ensure that profiles are tracked prior to capturing custom event data.

Using Custom Events in Flows

Once your event tracking is set up, you can create a new flow and select your custom metric as the trigger. The Flows Library also has a variety of prebuilt flows to choose from which can be modified to suit the purpose of your custom event. For example, if you'd like to remind customers of items they've previously "liked" you can modify a standard winback flow with your Added Like metric.

Read more about creating a metric-triggered flow. The metric trigger option allows you to queue people for a flow when they take a certain action. This action can be any event activity captured through an integration (e.g., started a checkout, placed an order, filled out a form) or events created via the Klaviyo API. For example, an abandoned cart flow would trigger off the Started Checkout event, with an additional flow filter to restrict the flow only to those who have not followed through with placing an order. Although this guide covers metrics standard to Klaviyo's native integrations, any custom metric can be used to trigger a flow.

Report on Custom Events

Klaviyo’s pre-built, customizable reports enable you to dive deeper into metrics, campaign, flow, or product performance. To track the performance of your custom events, set up a custom report on those metrics.

To access custom reports, click on the Analytics tab and select Custom Reports from the main dashboard. Create a new report by selecting Create from scratch.

Next, click on Select report type and choose Single Metric Deep Dive Report from the dropdown menu. With the single metric report, you can choose any metric in your account to build a report around and can further customize it by selecting different timeframes, properties, and groupings.

Select your custom metric to report on. From the designated dropdown, you can select any metric available in your account. Finally, customize and run your report.

Read more about creating a single metric deep dive report.


Did this page help you?