NPM package

Call inject() directly when none of the framework wrappers fit your setup.

When to use this

The framework adapters (produl-tracker/next, produl-tracker/react, etc.) are thin wrappers around this core API. Use inject() directly when you are working with a framework that does not have a first-class adapter, building a custom integration, or embedding the tracker in an SDK of your own.

Install

bash
npm install produl-tracker

Usage

Import inject from the root produl-tracker package and call it once when your app initializes. Pass your siteId and any other options. After this call the tracker is active and will record pageviews.

ts
import { inject } from 'produl-tracker'

inject({ siteId: 'YOUR_SITE_ID' })

inject accepts an AnalyticsProps object. All fields except siteId are optional:

PropTypeDefaultDescription
siteIdstringRequired. Your site ID from the dashboard.
serverUrlstringhosted instanceOverride the tracker server URL.
disableAutoTrackbooleanfalseDisable automatic pageview tracking.
endpointstring/api/collectBase URL that pageview and event data is sent to.
debugbooleanfalseShow a debug overlay listing every tracked event.
ts
import { inject, type AnalyticsProps } from 'produl-tracker'

const config: AnalyticsProps = {
  siteId: 'YOUR_SITE_ID',
  serverUrl: 'https://your-instance.example.com',
  debug: process.env.NODE_ENV === 'development',
}

inject(config)

Tracking events

Import track to send custom events from anywhere in your codebase. It takes an event name and an optional properties object.

ts
import { track } from 'produl-tracker'

track('purchase', { amount: 99, currency: 'usd' })
The track function is safe to call before inject() has been called — events are queued and flushed once the tracker initializes.