GithubHelp home page GithubHelp logo

bebeto84 / ichnos Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tamer-mohamed/ichnos

0.0 1.0 0.0 288 KB

Library for Tracking client-side events via Google Tag Manager (GTM).

License: MIT License

JavaScript 2.91% TypeScript 97.09%

ichnos's Introduction

Codecov Snyk Vulnerabilities for GitHub Repo CircleCI branch GitHub David npm bundle size

Ichnos

Library for Tracking client-side events via Google Tag Manager (GTM).

What is Ichnos?

  • Built with Typescript ๐Ÿš€
  • Flexible-scalable solution for gtm tracking
  • Can be pluged to any view framework - see integrations
  • Redux-like: Easy to use and can hook into events
  • Super small: less than 2kb (minified)

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' }

Integrations

  • @ichnos/vue - Vue integration
  • @ichnos/react
  • @ichnos/preact
  • @ichnos/angular

ichnos's People

Contributors

tamer-mohamed avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.