Installation

You can install the Unify Intent JS Client with your preferred package manager:

npm
npm install @unifygtm/intent-client
yarn
yarn add @unifygtm/intent-client

Usage

After installing the client, you must initialize it in your application code:

You should only initialize the client one time in your application.
index.ts
import { UnifyIntentClient, UnifyIntentClientConfig } from '@unifygtm/intent-client';

const writeKey = 'YOUR_PUBLIC_API_KEY';

const config: UnifyIntentClientConfig = {
  autoPage: true,
  autoIdentify: false,
};

const unify = new UnifyIntentClient(writeKey, config);

// Do not call mount during server side rendering. Only call it in a browser context.
unify.mount();

You can then use the resulting client instance to log intent data. See the Client Spec for more details on how to use the client.

Cleanup

When you are done using the client, if you wish to clean up the side effects generated by it, you can do so with the unmount method:

cleanup.ts
import { UnifyIntentClient, UnifyIntentClientConfig } from '@unifygtm/intent-client';

const writeKey = 'YOUR_PUBLIC_API_KEY';

const unify = new UnifyIntentClient(writeKey);
unify.mount();

// Use the client for some time, then later...

unify.unmount();