0.1.4 • Published 4 years ago

mp-ga-enhancer-ecommerce v0.1.4

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

mp-ga-enhancer-ecommerce

E-Commerce enhancer for mp-ga-tracker.

Installation

$ npm install mp-ga-enhancer-ecommerce --save

Usage

// import the main SDK, which should be installed separately
import GaTracker from 'mp-ga-tracker'
// import the E-Com enhancer
import * as gaTrackerEcomEnhancer from 'mp-ga-enhancer-ecommerce'

// init the GA tracker
// see more details in the doc of mp-ga-tracker
const gaTracker = new GaTracker(...config)

// inject as the non-first argument of the gaTracker tracking methods that supports the enhancers
// for example, trackScreenview
gaTracker.trackScreenview(
  'screen_view',
  gaTrackerEcomEnhancer.impression([
    index: 2,
    nm: 'Product Impression List Name',
    products: [
      {
        id: 'Product Impression SKU',
        nm: 'Product Impression Name',
        ps: 'Product Impression Position',
      },
    ],
  ]),
)

API

  • All the API supports the list and products type to be either Array or Object
  • While the <listIndex> and <productIndex> would be automatically generated, they could be overridden by simply attaching a specific index value (NOTE: index value should be in the range 1, 200)

impression(Array | Object)

The activity of a product being displayed somewhere, e.g. PLP.

impression([
  {
    // list `nm` is required
    nm: 'Product Impression List Name',
    // ?optional, to specify the index value
    index: 2,
    // the products could be either object or array
    products: {
      // product `id`, `nm`, `ps` are required
      id: 'Product Impression ID',
      nm: 'Product Impression Name',
      ps: 'Product Impression Position',
      // product `pr`, `br`, `ca`, `va` are optional
      pr: 'Product Impression Price',
      br: 'Product Impression Brand',
      ca: 'Product Impression Category',
      va: 'Product Impression Variant',
    },
  },
])

// the argument could be an object as well
impression({
  nm: 'Product Impression List Name',
  products: [],
})

click(Object)

The activity of a product being clicked on.

click({
  pal: 'Product Action List',
  products: {
    // `id`, `nm`, `ps` are required
    id: 'Product SKU'
    nm: 'Product Name',
    ps: 'Product Position',
    // `pr`, `br`, `ca`, `va`, `qt`, `cc` are optional
    pr: 'Product Price',
    br: 'Product Brand',
    ca: 'Product Category',
    va: 'Product Variant',
    qt: 'Product Quantity',
    cc: 'Product Coupon Code',
  },
})

detail(Object)

The activity of a PDP being viewed.

detail({
  pal: 'Product Action List',
  products: {
    // `id`, `nm`, `ps` are required
    id: 'Product SKU'
    nm: 'Product Name',
    ps: 'Product Position',
    // `pr`, `br`, `ca`, `va`, `qt`, `cc` are optional
    pr: 'Product Price',
    br: 'Product Brand',
    ca: 'Product Category',
    va: 'Product Variant',
    qt: 'Product Quantity',
    cc: 'Product Coupon Code',
  },
})

add(Object)

The activity of a product being added to cart.

add({
  products: {
    // `id`, `nm`, `ps`, `pr`, `qt` are required
    id: 'Product SKU'
    nm: 'Product Name',
    ps: 'Product Position',
    pr: 'Product Price',
    qt: 'Product Quantity',
    // `br`, `ca`, `va`, `cc` are optional
    br: 'Product Brand',
    ca: 'Product Category',
    va: 'Product Variant',
    cc: 'Product Coupon Code',
  },
})

remove(Object)

The activity of a product being removed from cart.

remove({
  products: {
    // `id`, `nm`, `ps`, `pr`, `qt` are required
    id: 'Product SKU'
    nm: 'Product Name',
    ps: 'Product Position',
    pr: 'Product Price',
    qt: 'Product Quantity',
    // `br`, `ca`, `va`, `cc` are optional
    br: 'Product Brand',
    ca: 'Product Category',
    va: 'Product Variant',
    cc: 'Product Coupon Code',
  },
})

checkout(Object)

The activity of a product being checked out.

checkout({
  // `cos`, `col` are optional
  cos: 'Checkout Step',
  col: 'Checkout Option',
  products: {
    // `id`, `nm`, `ps`, `pr`, `qt` are required
    id: 'Product SKU'
    nm: 'Product Name',
    ps: 'Product Position',
    pr: 'Product Price',
    qt: 'Product Quantity',
    // `br`, `ca`, `va`, `cc` are optional
    br: 'Product Brand',
    ca: 'Product Category',
    va: 'Product Variant',
    cc: 'Product Coupon Code',
  },
})

purchase(Object)

The activity of a product being purchased and order being created.

purchase({
  // `ti`, `tr` are required
  ti: 'Transaction/Order ID',
  tr: 'Transaction Revenue',
  // `tt`, `ts`, `tcc` are optional
  tt: 'Transaction Tax',
  ts: 'Transaction Shipping',
  tcc: 'Transaction Coupon Code',
  products: {
    // `id`, `nm`, `ps`, `pr`, `qt` are required
    id: 'Product SKU'
    nm: 'Product Name',
    ps: 'Product Position',
    pr: 'Product Price',
    qt: 'Product Quantity',
    // `br`, `ca`, `va`, `cc` are optional
    br: 'Product Brand',
    ca: 'Product Category',
    va: 'Product Variant',
    cc: 'Product Coupon Code',
  },
})

refund(Object)

The activity of a product and its transaction being refunded.

refund({
  // `ti`, `tr` are required
  ti: 'Transaction/Order ID',
  tr: 'Transaction Revenue',
  // `tt`, `ts`, `tcc` are optional
  tt: 'Transaction Tax',
  ts: 'Transaction Shipping',
  tcc: 'Transaction Coupon Code',
  products: {
    // `id`, `nm`, `ps`, `pr`, `qt` are required
    id: 'Product SKU'
    nm: 'Product Name',
    ps: 'Product Position',
    pr: 'Product Price',
    qt: 'Product Quantity',
    // `br`, `ca`, `va`, `cc` are optional
    br: 'Product Brand',
    ca: 'Product Category',
    va: 'Product Variant',
    cc: 'Product Coupon Code',
  },
})