Ninetailed
Search…
Sending Events
This guide describes how to use Ninetailed Analytics and Events in React.

Overview

To personalize the content we need to know about the visitor currently viewing the page. This data is managed by our customer data platform. Anyhow you need to send events about the user to our API so it can aggregate a profile over time.
To make this process as easy as possible Ninetailed provides the page(), track() and identify() methods which can be used via the useAnalytics hook or via the window object of the browser for example in a Tag Manager.
We recommend triggering Pageviews by an automated tracker depending on your router. For frameworks like Next.js an <AutoTracker /> is prebuilt.

useNinetailed

The useNinetailed hook provides the event tracking functions inside your React components. This is very handy if you want to send events from your code.
1
import React from 'react';
2
import { useNinetailed } from '@ninetailed/experience.js-react';
3
4
const CallToAction = () => {
5
const { track, page, identify } = useNinetailed();
6
7
return (<button
8
type="button"
9
onClick={() => { track('built new Rick'); }}
10
>
11
build new Rick
12
</button>);
13
}
Copied!

Events

Page view

Page views should be sent on every page change. Our SDK populates all data needed as, referrer, url, user-agent and other properties to be consumed by the API.
1
type Page = () => Promise<void>;
Copied!

Track

Track events are used to describe special actions the user did, like signup or registered_for_newsletter.
1
type Track = (event: string) => Promise<void>;
Copied!

Identify

By identifying a user you add a custom id to the profile, like a Hubspot id or an id from your internal database. Even more important, you can set traits about this customer, like the firstname, age or anything you want to personalize the content even more.
1
type Identify = (uid: string, traits: Traits) => Promise<void>;
Copied!

Tag Manager

The Analytics SDK also adds the page(), track() and identify() functions to the window object. That way you can also access them from a Tag Manager. We recommend sending pageviews directly from the code as soon as the SDK is initialized so the personalizations are not delayed.