Skip to main content

Enabling Analytics on Optimize Tracker

Optimize Deprecation

Uniform Optimize has been deprecated and replaced by Context, a more powerful and flexible personalization solution. Optimize is not being discontinued at this time, but it will not receive updates or new features.

We do not recommend starting a new project with Optimize. If you have an existing project that uses Optimize, you can upgrade your project to Context at no cost using our upgrade guide. If you have any issues with this process you can contact our team.

To have the <Personalize /> component push analytics events, you need to ensure your site is configured with the Uniform analytics plugin. This plugin will need to be enabled and configured when you call createDefaultTracker; it is disabled by default - discussed in Getting started.

Install Package

Start with installing the Uniform analytics plugin npm package:

npm install @uniformdev/optimize-tracker-analytics

Configure Analytics

Then open the file where you are initializing your tracker. createDefaultTracker accepts an array of custom plugins that should also be enabled.

The default Optimize analytics plugin relies on Analytics, a thin abstraction layer over a wide range of analytics tools. This example will use Analytics' Google Analytics plugin to send personalization data to GA (Google Analytics). The same procedure will also work for other plugins such as Segment.

Install the core analytics library and Google Analytics plugin:

npm install analytics @analytics/google-analytics

In the file where you created your tracker instance (i.e., local-tracker.ts), import and initialize the Analytics library; you will then pass your analytics ID to the Google Analytics library.

import Analytics from 'analytics'
import googleAnalytics from '@analytics/google-analytics'

const analytics = Analytics({
app: 'UniformConf', // Your site here
plugins: [
trackingId: 'UA-12345-1'

Add Analytics to the Uniform Tracker

We need to tell the tracker about this Analytics object. You're free to use this library across your site as you need to trigger custom analytics events while the tracker will call the same functions to log its events.

In your tracker configuration file, import and pass the tracker into createDefaultTracker using the addPlugins field.

// TypeScript

// Import Optimize Analytics plugin
import { addAnalyticsPlugin } from '@uniformdev/optimize-tracker-analytics';

// Analytics initialization code here

export const createLocalTracker = (ctx?: NextPageContext): Tracker =>
intents: intentManifest as DeliveryAPIResult,
addPlugins: [addAnalyticsPlugin({ analytics })], // Pass Analytics plugin to tracker

Add Event Names to Personalizations

To give analytics context, each personalization that will have data collected needs to be tagged with an event name to send to the analytics destination(s). The event name enables a data analyst to evaluate each personalization independently.