# @8select/eightlytics-client

> ## Usage

Latest version **1.0.5** (published 2021-07-15) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install @8select/eightlytics-client
pnpm add @8select/eightlytics-client
yarn add @8select/eightlytics-client
bun add @8select/eightlytics-client
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2021-07-15 |
| First published | 2021-07-08 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 37.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 8SELECT GmbH |
| Maintainers | carlcampfield, eightselect |

## Links

- npm: https://www.npmjs.com/package/@8select/eightlytics-client
- Repository: https://github.com/8select/8.LYTICS-3.0-client-js
- npm.io page: https://npm.io/package/@8select/eightlytics-client

## Dependencies (1)

- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) ^3.0.0

## Recent versions

- 1.0.5 (latest) — 2021-07-15
- 1.0.4 — 2021-07-15
- 1.0.3 — 2021-07-08
- 1.0.1 — 2021-07-08

## README

# 8.LYTICS 3.0 JavaScript Client

## Usage

### Installation:

```
yarn add @8select/eightlytics-client
```

or

```
npm install --save @8select/eightlytics-client
```

To send your 8.LYTICS events with this client, start by creating an event context with your API ID and optionally assign a user context:  
(for reference please view: https://docs.8select.io/api-tracking/general)

```typescript
import EightlyticsContext, { CurrencyCode } from '@8select/eightlytics-client'

const eightlyticsContext = new EightlyticsContext('<api-id>')
  // if commission based pricing is used, the user is required. otherwise optional
  .setUserContext('<user-id>')
  // optionally, if not set here, will be set in api
  .setPageContext('https://example.com/product/123')
```

Now you can use this context throughout your application to send any events.

To create a specific event you can use the utility functions provided by the context:

```typescript
// user sees a setCompose product set
const productClickEvent = eightlyticsContext.createViewSetComposeEvent('<set-compose-id>')

// user clicks on a product
const productClickEvent = eightlyticsContext
  // optionally
  .setContentContext(ContentType.SET_COMPOSE, '<set-compose-id>')
  .createProductClickEvent('<product-sku>')

// user adds a product to the cart
const productAddToCartEvent = eightlyticsContext
  // optionally
  .setContentContext(ContentType.SET_COMPOSE, '<set-compose-id>')
  .createProductAddToCartEvent('<product-sku>')

// user submits an order
const orderEvent = eightlyticsContext
  .createOrderEvent('<order-id>')
  // for each order position, create an order line.
  // CurrencyCode is an enum that contains all ISO 4217 currencies
  .addOrderLine('<product-sku>', <quantity>, <unit-price>, CurrencyCode.EUR)
```

After creating your event (or chained directly if you prefer) you can send it by calling it's `send` method:

```typescript
await event.send()
```

Chaining example:

```typescript
await new EightlyticsContext('<api-id>')
  .setUserContext('<user-id>')
  .setPageContext('https://example.com/product/123')
  .setContentContext(ContentType.SET_COMPOSE, '<set-compose-id>')
  .createProductAddToCartEvent('<product-sku>')
  .send()
```

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