@leancodepl/gtag
v9.6.6
Published
Google Tag Manager integration utilities for web analytics
Readme
@leancodepl/gtag
Type-safe Google Tag Manager data layer integration.
Installation
npm install @leancodepl/gtag
# or
yarn add @leancodepl/gtagAPI
mkgtag()
Creates a type-safe Google Tag Manager data layer push function.
Returns: Function that accepts data layer arguments and pushes to GTM
Usage Examples
Basic Event Tracking
import { mkgtag } from "@leancodepl/gtag"
const gtag = mkgtag<{ event: "page_view"; page_title: string }>()
gtag({
event: "page_view",
page_title: "Home Page",
})Custom Events with Callbacks
import { mkgtag } from "@leancodepl/gtag"
interface CustomEvent {
event: "button_click"
element_id: string
}
const gtag = mkgtag<CustomEvent>()
gtag({
event: "button_click",
element_id: "signup-button",
eventCallback: containerId => {
console.log("Event sent to container:", containerId)
},
eventTimeout: 2000,
})