@getvero/tracking
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

@getvero/tracking

NPM Version npm bundle size

Vero is an email marketing platform that allows you to engage and re-engage your customer base based on the actions they perform in your software.

This NPM package is the official JavaScript/TypeScript library that allows you to interact with Vero's tracking API from your JavaScript application with ease.

This library works in both Node.js and browser environments.

Usage

To get started with this library, you'll need to obtain your tracking API key from the Vero Settings page for your project.

There are two methods to reference this library in your project:

Method 1: <script> Tag

This is the simplest way to use this library in your project if you want to track events and user properties on the client-side of your website.

Insert the following code into your <head> section of your HTML document:

<script src="https://cdn.jsdelivr.net/npm/@getvero/tracking@2.0.1/dist/index.window.js"></script>
<script>
    vero.tracker.init({
        trackingApiKey: "<YOUR_TRACKING_API_KEY_HERE>"
    })
</script>

When the user logs in, you should call the user.identify method:

vero.tracker.user.identify({
    id: "<USER_ID_HERE>",
    email: "<USER_EMAIL_HERE>"
})

To track an event, you can call the event.track method:

vero.tracker.event.track({
    eventName: "<EVENT_NAME_HERE>",
    data: {
        // Add any additional data you want to track
    }
})

Please make sure you have called user.identify before calling event.track so the event can be attributed to the correct user. Otherwise, the event.track call will throw an error.

When the user logs out, you should call vero.tracker.user.unidentify() so future events will not be accidentally associated with the user.

Method 2: NPM Package

This is the recommended way to use this library on both client-side and server-side of your website.

First, install the @getvero/tracking package:

npm install @getvero/tracking

If you only need one instance of the Tracker class (singleton), this package's default export will work for you:

// Put this in the entry point of your application

import tracker from '@getvero/tracking'

tracker.init({
    trackingApiKey: "<YOUR_TRACKING_API_KEY_HERE>"
})

You can then use the singleton tracker instance to track events and user properties:

import tracker from '@getvero/tracking'

tracker.user.identify({
    id: "<USER_ID_HERE>",
    email: "<USER_EMAIL_HERE>"
})

tracker.event.track({
    // The `identity` is required in Node.js environment as `user.identify` doesn't remember the user's identity 
    // unlike in a browser environment
    identity: {
        userId: "<USER_ID_HERE>",
        email: "<USER_EMAIL_HERE>"
    },
    eventName: "<EVENT_NAME_HERE>",
    data: {
        // Add any additional data you want to track
    }
})

If you need multiple instances of the Tracker class, you can use the named export:

import {Tracker} from '@getvero/tracking'

const tracker = new Tracker({
    trackingApiKey: "<YOUR_TRACKING_API_KEY_HERE>"
})

tracker.user.identify({
    id: "<USER_ID_HERE>",
    email: "<USER_EMAIL_HERE>"
})

tracker.event.track({
    // The `identity` is required in Node.js environment as `user.identify` doesn't remember the user's identity 
    // unlike in a browser environment
    identity: {
        userId: "<USER_ID_HERE>",
        email: "<USER_EMAIL_HERE>"
    },
    eventName: "<EVENT_NAME_HERE>",
    data: {
        // Add any additional data you want to track
    }
})

In browser environments, when the user logs out, you should call user.unidentify() so future events will not be accidentally associated with the user:

tracker.user.unidentify()

For more details about the methods and their usages, please refer to the TypeScript type definitions and the JSDoc comments.

Feedback and Contributions

We welcome feedback and contributions from the community.

If you have any questions or suggestions, please open an issue on GitHub or reach out to us at support@getvero.com.

Pull requests are welcome.

License

This library is distributed under the MIT License. See LICENSE for more information.

Readme

Keywords

none

Package Sidebar

Install

npm i @getvero/tracking

Weekly Downloads

240

Version

2.0.1

License

MIT

Unpacked Size

39.1 kB

Total Files

7

Last publish

Collaborators

  • komatsu
  • getvero-product