Skip to main content

Installation Guide

In this guide, we will walk through installing the core Optimize Tracker packages, downloading a project intent manifest, and use this manifest to initialize a tracker instance. These instructions are framework-agnostic.

tip

Looking to get started fast and see a working example of everything pre-installed and personalizing? The Uniform dashboard will allow you to scaffold a starter site on your own repository, wire it up to a headless CMS, and give you some example personalization to start with.

These instructions are relevant for installing Uniform Optimize on an existing codebase, or if you want to begin with the basics.

Install Packages#

First, we need to install the core tracker package that contains our default and recommended version of the tracker object.

npm install @uniformdev/optimize-tracker-browser

Once installed, we will install an optional CLI that will help download the intent manifest from the Optimize APIs. You can install this globally or as a developer dependency.

npm install --save-dev @uniformdev/cli

Fetch Intent Manifest#

We can now use the CLI to download intent manifest data to a file inside of the project. The intent manifest is JSON data provided by Uniform Optimize that defines the intents and signals to drive personalization.

uniform optimize manifest download --output ./lib/intentManifest.json --apiKey $UNIFORM_API_KEY
  • output is the path where the JSON should be written in your project. You will be importing this in a later step.
  • apiKey is your Uniform API key represented here as an environment variable. This environment key can be global or defined in a .env file using dotenv. If you do not have an API key or need help locating one, visit our API Key Management page to learn more.

We recommend wiring this CLI command up to a package script and executing it while your application builds to keep your intent manifest as up to date as possible. For example, use npm-run-all to execute it on your build command before you build your application.

"build": "run-s generate:intents build:next","build:next": "next build","generate:intents": "uniform optimize manifest download --output ./lib/intentManifest.json --apiKey $UNIFORM_API_KEY",

Create Tracker Instance#

After the intent manifest JSON has been downloaded, we can import and use it to create a tracker instance.

import { createDefaultTracker } from '@uniformdev/optimize-tracker-browser';import intentManifest from './intentManifest.json';
const localTracker = createDefaultTracker({  intentManifest,});
export default localTracker;

Integrate with JavaScript Frameworks#

At this point, you should have an initialized tracker that you are initializing with intent manifest data downloaded from the Uniform Optimize API. Now it's time to put the tracker to use; click a guide below to continue setting up personalization.