Leanbase Help Center

Your Guide to Building Products Customers Love

Home How to capture Node.js event?

How to capture Node.js event?

Sending custom events

You can send custom events using the capture method.

Example — Node.js

client.capture({
distinctId: 'distinct_id_of_the_user',
event: 'user signed up',
});

💡 Tip: Use the [object] [verb] naming convention for event names, where object represents the entity and verb represents the action.
Examples: project created, user signed up, invite sent.


Adding event properties

You can include additional details with an event by adding a properties object:

client.capture({
distinctId: 'distinct_id_of_the_user',
event: 'user signed up',
properties: {
login_type: 'email',
is_free_trial: true,
},
});


Capturing pageviews

If you’re implementing Leanbase only on the backend and not sending events from your frontend, you can still send $pageview events manually:

client.capture({
distinctId: 'distinct_id_of_the_user',
event: '$pageview',
properties: {
$current_url: 'https://example.com',
},
});


Event ingestion

Leanbase prioritizes fast ingestion — events are typically processed and ready for analysis within a few minutes after being sent.


Anonymous vs. Identified events

Leanbase supports two types of events:

Identified events

These events are linked to specific users and can include person properties.
They’re best suited for logged-in users or environments where you need user-level insights.

Use cases:

  • Tracking logged-in users in B2B/B2C SaaS apps

  • Running user-segmented product analysis

  • Understanding the full conversion lifecycle for growth and marketing teams


Anonymous events

These events do not include identifiable user data and are ideal for general analytics.

Use cases:

  • Tracking marketing websites

  • Monitoring content-heavy pages

  • B2C apps without user login

Under the hood, identified events create a user profile in Leanbase, while anonymous events do not.

Note: Anonymous events are up to 4x cheaper to process.
Capture identified events only when needed.


Capturing anonymous events

In the JavaScript SDK, anonymous events are captured by default.
This behavior depends on the personProfiles setting when initializing Leanbase:

leanbase.init('lbp_your_api_key_here', {
api_host: 'https://us.i.leanbase.com',
person_profiles: 'identified_only', // default, recommended
});

Options:

  • person_profiles: 'identified_only' — captures anonymous events by default; creates profiles only for identified users.

  • person_profiles: 'always' — captures identified events for all users.


Capturing identified events

If personProfiles is set to identified_only (default), anonymous events are sent by default.
To capture identified events, call one of the following functions:

leanbase.identify('user_123');
leanbase.alias('user_123', 'temp_id');
leanbase.group('team', 'team_456');
leanbase.setPersonProperties({ plan: 'Pro' });
leanbase.setPersonPropertiesForFlags({ region: 'US' });
leanbase.setGroupPropertiesForFlags({ industry: 'Fintech' });

When any of these functions are called, Leanbase creates a person profile for the user.
All subsequent events from that user will be tracked as identified events.

Alternatively, set person_profiles: 'always' in your configuration to treat all events as identified by default.