Skip to main content

NPM Package

@jitsu/js is an NPM package that allows you to track events from your JavaScript code. The package is isomorphic and can be used in both browser and Node.js environments.

tip

In all examples below, replace your-jitsu-domain.com with your Jitsu installation domain.

Jitsu Cloud users may find domain in the top-right corner of Site's Setup Instruction page or attach custom domain for a specific Site and use it instead.

Installation

npm install @jitsu/js
npm install -D @jitsu/protocols # optional, for TypeScript users

Usage

export async function track() {
const analytics = jitsuAnalytics({
host: "https://your-jitsu-domain.com",
// Browser Write Key configured on Jitsu Site entity.
// If no Browser Write Key is added for Site entity, Site ID value can be used a Write Key.
// On Jitsu.Cloud can be omitted if Site has explicitly mapped domain name that is used in host parameter
writeKey: "",
});
await analytics.identify("userId", {email: "test", anyOtherProperty: "value"});
await analytics.track("test page", {pageProperty: "propValue"});
await analytics.page("test", {a: 1});
}

Sending Events to Jitsu

analytics object implements standard Analytics.js interface. See a full list of methods in JavaScript Reference section

info

In browser, page properties such as title, location will be detected automatically. In Node.js, you need to provide them manually. See RuntimeFacade interface. Provide you own implementation of RuntimeFacade for nodejs