Skip to content

Repository files navigation

@quantity-digital/analytics-ts

A small TypeScript wrapper for sending GA4-style events to the browser's window.dataLayer.

Installation

npm install @quantity-digital/analytics-ts

Usage

import { analytics } from "@quantity-digital/analytics-ts";

analytics.track.addToCart({
  currency: "DKK",
  value: 299,
  items: [
    {
      item_id: "sku-123",
      item_name: "T-Shirt",
      price: 299,
      quantity: 1,
    },
  ],
});

The package attaches the analytics API to window.analytics when it is imported in a browser. It initializes window.dataLayer when an event is tracked. The package can be imported during server-side rendering, but tracking methods must only be called in a browser.

Releasing

Releases use conventional commits and are published from version tags by GitHub Actions. See PUBLISHING.md for the one-time npm setup and release procedure.

License

MIT

About

Track GA4 recommended events via dataLayer, with strong typing

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages