# @tokenscript/analytics-client

> This is the client SDK for Analytics

Latest version **0.4.0** (published 2023-04-28) · 0 weekly downloads

## Install

```sh
npm install @tokenscript/analytics-client
pnpm add @tokenscript/analytics-client
yarn add @tokenscript/analytics-client
bun add @tokenscript/analytics-client
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2023-04-28 |
| First published | 2023-03-02 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.13.0 |
| Dependencies | 4 |
| Unpacked size | 18 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | snowwhitedev, stj89, jf-stl, futantan, jot2re, micwallace, victor928, nicholastaras |

## Links

- npm: https://www.npmjs.com/package/@tokenscript/analytics-client
- npm.io page: https://npm.io/package/@tokenscript/analytics-client

## Dependencies (4)

- [zod](https://npm.io/package/zod.md) ^3.20.6
- [uuid](https://npm.io/package/uuid.md) ^9.0.0
- [@trpc/client](https://npm.io/package/@trpc/client.md) ^10.12.0
- [@trpc/server](https://npm.io/package/@trpc/server.md) ^10.12.0

## Recent versions

- 0.4.0 (latest) — 2023-04-28
- 0.3.0 — 2023-04-17
- 0.2.0 — 2023-03-29
- 0.1.6 — 2023-03-07
- 0.1.5 — 2023-03-03
- 0.1.4 — 2023-03-02
- 0.1.3 — 2023-03-02

## README

# Analytics Client

This is the client SDK for Analytics

## Install

```sh
npm install --save @tokenscript/analytics-client
```

## How to use

1. Initialize the sdk client

The analytics client will generate a distinctId(uuid) to be used for the following event report and user identification.

```js
import Analytics from '@tokenscript/analytics-client';

const analyticsUrl = "http://127.0.0.1:3006";
// jwt token is generated per client_id/brand/campaign
const jwtToken = "eyJhbGciOiJIUzI...";

const analytics = new Analytics(analyticsUrl, jwtToken);
```

2. Hook with Token Negotiator

By connecting to the tokenNegotiator, all the concerned events triggered from tokenNegotiator will be reported automatically.

```js
// accept the token negotiator instance
analytics.connectTokenNegotiator(window.tokenNegotiator); 
```

3. Manual user/event report

When Token Negotiator is not used or a custom event outside of Token Negotiator need to be reported, user can perform manual report by directly accessing the tRPC client

```js
// Report event (timestamp is added automatically)
analytics.client.event({
  name: "customer-event",
  properties: {...}
});

// Identify user
analytics.client.user({
  email: "a@b.com",
  chain_id: 1,
  wallet_address: "0x123abc..."
});
```

---
_Source: https://npm.io/package/@tokenscript/analytics-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
