@scaleway/use-gtm
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

@scaleway/use-gtm

A tiny provider to handle Google Tag Manager in React

Install

$ pnpm add @scaleway/use-gtm

Usage

Basic

import GTMProvider, { useGTM } from '@scaleway/use-gtm'

const Page = () => {
  const { sendGTM } = useGTM()

  sendGTM?.({
    hello: 'world
  })

  return <p>Hello World</p>
}

const App = () => (
  <GTMProvider id="testId">
    <Page />
  </GTMProvider>
)

With injected events

import GTMProvider, { useGTM } from '@scaleway/use-gtm'

const events = {
  sampleEvent: (sendGTM?: SendGTM) => (message: string) => {
    sendGTM?.({
      event: 'sampleEvent',
      hello: message,
    })
  },
}

const Page = () => {
  const { events } = useGTM()

  events.sampleEvent?.('world')

  return <p>Hello World</p>
}

const App = () => (
  <GTMProvider id="testId">
    <Page />
  </GTMProvider>
)

With global setter

import GTMProvider, { sendGTM } from '@scaleway/use-gtm'

const Page = () => {
  sendGTM?.({
    hello: 'world
  })

  return <p>Hello World</p>
}

const App = () => (
  <GTMProvider id="testId">
    <Page />
  </GTMProvider>
)

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @scaleway/use-gtm

      Weekly Downloads

      2

      Version

      3.0.1

      License

      MIT

      Unpacked Size

      12.3 kB

      Total Files

      16

      Last publish

      Collaborators

      • codelax
      • quantumsheep
      • scaleway-bot
      • mprost
      • imanu
      • vincentaudebert
      • maliszewskid
      • phiphi