Activation
The Uniform tracker handles visitor classification. It is a component that runs on the visitor's device. As a result, the approach used to add the tracker to an application depends on the technology used to build the front-end.
Add Context to app
In Uniform, the Context object handles tracking visitor activity. Adding this object to your application enables tracking.
- React
Add the following npm packages to your application:
@uniformdev/context
@uniformdev/context-reactAbout this stepThis adds references to the packages for React apps that need to use Context. For more information on these packages, see npm package reference.
Generate the manifest for your Uniform project.
Add the following code to your app component.
/pages/_app.jsximport {
Context,
} from "@uniformdev/context";
import { UniformContext } from "@uniformdev/context-react";
import manifest from "../lib/uniform/contextManifest.json";
const context = new Context({
});
function MyApp({
Component,
pageProps,
}) {
return (
<Component {...pageProps} />
);
}
export default MyApp;About this stepThis creates the context object that is used to configure how the tracker works. For more information about this component, see the Context type reference.
Add the following code:
/pages/_app.jsximport {
Context,
} from "@uniformdev/context";
import manifest from "../lib/uniform/contextManifest.json";
const context = new Context({
manifest,
});
...Add the following code:
/pages/_app.jsximport {
Context,
} from "@uniformdev/context";
import manifest from "../lib/uniform/contextManifest.json";
const context = new Context({
defaultConsent: true,
manifest,
});
...About this stepFor more information, see the compliance and consent capability.
Add the following code:
/pages/_app.jsximport {
Context,
} from "@uniformdev/context";
import { UniformContext } from "@uniformdev/context-react";
import manifest from "../lib/uniform/contextManifest.json";
const context = new Context({
defaultConsent: true,
manifest,
});
function MyApp({
Component,
pageProps,
}) {
return (
<UniformContext context={context}>
<Component {...pageProps} />
</UniformContext>
);
}
export default MyApp;About this stepThis creates a custom React context object that components in the app can use to access to the context. For more information about this component, see the Context component reference.
By adding the context to your app, you have activated the Uniform tracker. The tracker runs automatically when the app is loaded and when the route changes.
If you want to be able to see the activity captured during the tracking process, you should enable Uniform dev tools.