Skip to main content

Custom tracking

By default, the Uniform tracker captures a variety of visitor and visit data. You are able to programmatically write custom data using the tracker, as well. This section describes why and how to do this.

tip

If your goal is to support personalization using custom data, you do not need to add this custom data to the tracker. See the complex custom condition example for details on how to support this use case.

Example (visit activity)#

JSS (React)#

This example will add an activity named "important click" when a component is clicked. The event data will include the id of the component that was clicked.

  1. Open the code for the component whose clicks you want to track.

  2. Add the following import statements:

    import { useContext } from 'react';import { VisitActivity } from '@uniformdev/tracking';import { TrackerContext } from '@uniformdev/tracking-react';
  3. Add the following code to your component:

    const trackerContext = useContext(TrackerContext);
  4. Add the following event handler to your component:

    function(e) {    const { tracker, visitorId } = trackerContext;    const activity = new VisitActivity("important click", new Date().toISOString());    activity.data = { component: e.target?.id };    tracker.event("visit-activity", activity, { visitorId });}