react-impression-read-click-tracking
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

React Tracking

Easily track Impressions, Reads and Clicks in React.

Installation

NPM

npm install react-impression-read-click-tracking

Yarn

yarn add react-impression-read-click-tracking

Usage

import { 
  useTrackImpressionsReads, 
  useTrackClicks } from 'react-impression-read-click-tracking'

...

const trackGtmEvent = (event: string, context: Object) => {
  window.dataLayer = window.dataLayer || []
  window.dataLayer.push({ event, context })
}

...

const Div = ({id}: DivProps) => {
  const context = {
    ...useContext(TrackingContext),
    id
  }

  const handleImpression = () => trackGtmEvent('div-impression', context)
  const handleRead = () => trackGtmEvent('div-read', context)
  const handleClick = () => trackGtmEvent('div-click', context)

  const ref = useRef(null)
  useTrackImpressionsReads(ref, handleImpression, handleRead)
  useTrackClicks(ref, handleClick)

  return (
    <div ref={ref}/>
  )
}

Package Sidebar

Install

npm i react-impression-read-click-tracking

Weekly Downloads

0

Version

0.1.4

License

MIT

Unpacked Size

17.3 kB

Total Files

11

Last publish

Collaborators

  • timolooser