GithubHelp home page GithubHelp logo

sui-tealium-tracker's Introduction

@s-ui/tealium-tracker

Tool to track events like click or change and, if a tag is present on the element dispatch a link event to tealium.

This tool is meant to be used with the @s-ui/html-tagger tool but you can define your own tags and it will work asswell.

Use:

Basic usage:

To use it require it from the desired file as this:

require('@s-ui/tealium-tracker').tealiumTracker()

you can use it in a ES6 way too:

import { tealiumTracker } from '@s-ui/tealium-tracker'
tealiumTracker()

The package will:

1. Init listeners:

This will add a document listener watching for:

    1. click event
    1. input change event

Once we click on any 'A', 'BUTTON', 'DIV', 'INPUT', 'SVG' the listener callback will act and check if we or any of our parents with that whitelisted types have the tag data-tealium-tag

If the tag exists it will call a throttle function that will call utag.link function. If there's no utag present on the site the package will warn you with a console message.

Custom event dispatcher usage:

require('@s-ui/tealium-tracker').tealiumTracker({ customEventName: 'MyCustomEventName' })

you can do it in a ES6 way:

import { tealiumTracker } from '@s-ui/tealium-tracker'
tealiumTracker({ customEventName: 'MyCustomEventName' })

The package will:

1. Init listeners:

This will add a document listener watching for:

    1. click event
    1. input change event
    1. customEvent trigger

Once we click on any 'A', 'BUTTON', 'DIV', 'INPUT', 'SVG' the listener callback will act and check if we or any of our parents with that whitelisted types have the tag data-tealium-tag

If the tag exists it will call a throttle function that will call utag.link function. If there's no utag present on the site the package will warn you with a console message.

2. Populate window.dispatchCustomEvent function

For retro-compatibility reasons we populate this function to the window so the sites could dispatch their own custom event without problem.

    window.dispatchCustomEvent = (detail) => dispatchEvent({ eventName: this.customEventName, detail })

Anchor delay use case

Some trackers like xiti inject an image in our site with the purpose of do the track effective. If we made a native redirection we could fall on image load cancelations due the redirection of the page. To avoid that you can init the tracker in a anchorDelay mode that will add the anchor as a callback of our link call and delay the location.reload for ensure purposes.

require('@s-ui/tealium-tracker')({ handleAnchorDelay: true })

you can do it in an ES6 way:

import { tealiumTracker } from '@s-ui/tealium-tracker'
tealiumTracker({ handleAnchorDelay: true })

You can use it both with the custom event

require('@s-ui/tealium-tracker')({ handleAnchorDelay: true, customEventName: 'MyCustomEventName' })

you can do it in an ES6 way:

import { tealiumTracker } from '@s-ui/tealium-tracker'
tealiumTracker({ handleAnchorDelay: true, customEventName: 'MyCustomEventName' })

sui-tealium-tracker's People

Contributors

carlesnunez avatar midudev avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.