@thg-altitude/tracking

1.2.25 • Public • Published

Tracking SDK

A reusable package for managing Ingenuity GA/BI/UA events.

Installation

    <script is:inline>
      window.Tracker = {
        store: {
          get(k) {
            return Tracker.store[k]
          },
          set(k,v) {
            return Tracker.store[k] = Tracker.store[k] ? Object.assign(Tracker.store[k], v) : v
          }
        }
      }
    </script>
    <script src="https://unpkg.com/@thg-altitude/tracking@1.0.4/index.js" async></script>

How-to-use

Events can be triggered in to ways:

  1. Data Attributes
<button data-track="addToCard" data-track-push="yourStoreKey"/>
  1. Handlers
Tracker.handlers.addToCart({ store: 'yourStoreKey' })

In both cases when you're dependant on enriching the tracking event with meta data (e.g. product page data, list page data, basket contents) you will need to populate a store.

You can populate at store at any time by running the following:

Tracker.store.set('yourStoreKey', {
  ...
})

In the event that objects in the store need to change over time (for e.g. a custom changes quantities for the product after initial load) the store supports records being upserted as long as the keys are the same.

Events

event store supported
addToCart { product }
selectItem { product }

Store Objects

Product

An structure for product would be the following.

{
  item_name: "Donut Friday Scented T-Shirt",
  item_id: "67890",
  price: 33.75,
  item_brand: "Google",
  item_category: "Apparel",
  item_category2: "Mens",
  item_category3: "Shirts",
  item_category4: "Tshirts",
  item_variant: "Black",
  item_list_name: "Search Results",
  item_list_id: "SR123",
  index: 2,
  quantity: 1
}

Publishing

In order to publish a new version you will need a local .npmrc to publish to @thg-altitude.

Update the package.json with the new version before running npm publish

Readme

Keywords

none

Package Sidebar

Install

npm i @thg-altitude/tracking

Weekly Downloads

137

Version

1.2.25

License

ISC

Unpacked Size

51.9 kB

Total Files

3

Last publish

Collaborators

  • sa-altitude