Node.js
Use the server library to track events and users as they perform events from your backend systems and APIs.

Installation

Add the official Lucky Orange package to your project via NPM:
1
$ npm i @luckyorange/server
Copied!

Usage

After installation, the first step to using Lucky Orange is initializing it with your unique site ID.
1
const LuckyOrange = require('@luckyorange/server')
2
const luckyorange = new LuckyOrange({ siteId: 'YOUR-SITE-ID' })
Copied!

Track events

The track() method accepts three arguments. The first is the name of the event you wish to track. The second is any arbitrary metadata that you want to associate with the event. Finally, you can send a context object. This allows the event to be associated with a particular user that you have identified or a session created by the Lucky Orange browser library.
1
luckyorange.events.track(
2
'Account Created',
3
{ acceptedTerms: true },
4
{ userId: 'test-user-123' }
5
)
Copied!

Identify users

In order to connect user accounts and their properties in your system with visitor profiles in Lucky Orange, use identify(). You must provide a unique ID that will then become an alias for a visitor created internally by Lucky Orange. If you also use identify() in the browser tracking code, the same user's behavior will be combined into one profile.
1
luckyorange.visitors.identify('test-user-123', { email: '[email protected]' })
Copied!
Last modified 6mo ago