@8select/eightlytics-client 中文文档教程

发布于 3年前 浏览 19 项目主页 更新于 3年前

8.LYTICS 3.0 JavaScript Client

Usage

Installation:

yarn add @8select/eightlytics-client

或者

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

要使用此客户端发送您的 8.LYTICS 事件,首先使用您的 API ID 创建一个事件上下文,并可选择分配一个用户上下文:
(有关参考,请查看: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')

现在您可以在整个应用程序中使用此上下文来发送任何事件。

要创建特定事件,您可以使用上下文提供的实用函数:

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

创建事件后(或者如果您愿意,可以直接链接)您可以通过调用它的 send 方法来发送它:

await event.send()

链接示例:

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

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()
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文