@ichnos/core
Core library for ichnos tracking
Last updated 7 months ago by tmohamed1 .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @ichnos/core 
SYNC missed versions from official npm registry.

@ichnos/core

Install

npm install @ichnos/core

if you using yarn as package manager

yarn add @ichnos/core

Getting started

Create Ichnos instance and register event types.

import Ichnos from '@ichnos/core'

const ichnos = new Ichnos({
    options: { id: 'GTM-XXX' },  
    events: [  // register events
        { type: 'addToCart' }
    ]
})

next, you can fire events with payload as follow:

ichnos.send(
    ichnos.events.addToCart({ productId: 'abc' })
)

Configurations

config.options

Name type default comments
id (required) string
events (required) { type: String } [] register event types
active boolean false whether to enable sending gtm events
layer string dataLayer whether to enable sending gtm events
debug boolean false show logs in the console

config.events

array of events types to register to ichnos instance, Example:

const ichnos = new Ichnos({
    // ...
    events: [{ type: 'addToCart' }]
    // ...
})

then, you can use it to generate event with payload before send

ichnos.send(
    ichnos.events.addToCart({ productId: 'abc'})
)

config.hook

Events defined with a lifecycle in ichnos to reduce any boilerplate and redundunt code and make it simple to roll out your tracking events. below list of hooks can be applied:

beforeSend

beforeSend(type:string, payload: any, history: gtmEvents[])

hook called before send gtm event to the datalayer

below is example to attach event property to all the events schema.

import Ichnos from '@ichnos/core'

const ichnos = new Ichnos({
    // ...
    hook: {
        beforeSend: (type, payload, history) => {
            let event = payload;

            if(type === 'addToCart'){
                return {
                    userId: 'xyz'
                    ...event
                }
            }

            return event;
        }
    }
})
//...
ichnos.send(ichnos.events.addToCart({ productId: '123' })); // { userId: 'xyz', productId: '123' }

Current Tags

  • 0.0.5-alpha.0                                ...           canary (a year ago)
  • 1.0.2                                ...           latest (7 months ago)

9 Versions

  • 1.0.2                                ...           7 months ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.0.14                                ...           a year ago
  • 0.0.13                                ...           a year ago
  • 0.0.10                                ...           a year ago
  • 0.0.10-alpha.0                                ...           a year ago
  • 0.0.8-alpha.0                                ...           a year ago
  • 0.0.5-alpha.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 12
Last Day 0
Last Week 0
Last Month 10
Dependencies (5)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2016 © taobao.org |