JavaScript

This page is related to the JavaScript Web Library to use in the browser. This is not the guide for NodeJS usage.

You can install our @toolbird/web package on NPM to easily add Toolbird Analytics to your website.

Installation

Use your favourite package manager to install the @toolbird/web package:

npm install @toolbird/web

Usage

After installing the library you shall initialise it and it will begin tracking automatically. You initialise it using toolbird.init(options). You can read about the API on NPM.

Initialise Toolbird:

import toolbird from '@toolbird/web'

toolbird.init({
    domain: 'yourdomain.com
})

Start capturing custom events with properties:

// Basic Event Tracking
toolbird.track("Sign up")

// Include properties
toolbird.track("cta_clicked", {
    position: "hero",
    color: "purple"
})

// Maybe affilate tracking?
toolbird.track("affiliate_link", {
    affliateId: "EHJ42HD"
})

Start identifying users to get better insights

When identifying users, you are no longer privacy-friendly and will need to ask for explicit permission though something like Cookie Banners to keep being compliant with GDPR.

const user = {
    id: "dcedab1d-1d61-407c-a2e8-5a3bcd6a9656",
    email: 'johnsmith@gmail.com',
    firstName: "John",
    avatarURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Default_pfp.svg/1200px-Default_pfp.svg.png"
}

toolbird.identify(user.id, {
    email: user.email,
    name: user.firstName,
    avatar: user.avatarURL
})

The first parameter is userId, this should be a unique id to reflect this specific user. You can pass as many keys in the second parameter. There are 3 reserved keys, email, name and avatar. These are used to display basic information on the Dashboard. It is recommended to add these 3 keys. Other than that, you can add whatever you want like mrr, subscription or other data you would want to display in the Toolbird Dashboard.

Last updated