@8select/eightlytics-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

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)

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:

// 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:

await event.send()

Chaining example:

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()

Readme

Keywords

none

Package Sidebar

Install

npm i @8select/eightlytics-client

Weekly Downloads

0

Version

1.0.5

License

UNLICENSED

Unpacked Size

38.8 kB

Total Files

30

Last publish

Collaborators

  • robdasilva
  • akleiber
  • carlcampfield