Leanbase Help Center

Your Guide to Building Products Customers Love

Home How to capture Ruby events?

How to capture Ruby events?

Sending Custom Events

You can send custom events using capture:

Ruby

leanbase.capture({
  distinct_id: 'distinct_id_of_the_user',
  event: 'user_signed_up'
})

💡 Tip: Use the [object] [verb] format for your event names —
where object is the entity being acted upon, and verb is the action.
Examples: project created, user signed_up, invite sent.


Setting Event Properties

Optionally, you can attach additional information to your event with a properties object:

Ruby

leanbase.capture({
  distinct_id: 'distinct_id_of_the_user',
  event: 'user_signed_up',
  properties: {
    login_type: 'email',
    is_free_trial: true
  }
})

Sending Page Views

If you're implementing Leanbase only on the backend and not tracking events from your frontend,
you can still record page views directly from your backend:

Ruby

leanbase.capture({
  distinct_id: 'distinct_id_of_the_user',
  event: '$pageview',
  properties: {
    '$current_url': 'https://example.com'
  }
})

Event Ingestion

Leanbase ensures events are processed and stored as quickly as possible.
In most cases, events become available for queries within just a few minutes.


Anonymous vs. Identified Events

Leanbase supports two types of event tracking:

Identified Events

Used to associate actions with specific users and their attributes.
Ideal for logged-in users or personalized experiences.

Common use cases:

  • Tracking logged-in users in B2B and B2C SaaS products

  • Performing segmented user analysis

  • Tracking user conversion and lifecycle for growth teams

Anonymous Events

Do not include identifiable user data — suitable for tracking general traffic and usage.

Common use cases:

  • Marketing and content websites

  • B2C apps with no login or signup

  • Anonymous analytics and behavioral tracking

⚙️ Key difference:
Identified events create a person profile, while anonymous events do not.

💰 Note:
Anonymous events are up to 4× cheaper to process than identified ones.
Capture identified events only when necessary.


Capturing Anonymous Events

In web implementations, the Leanbase JavaScript SDK captures anonymous events by default.
This behavior depends on your person_profiles configuration when initializing Leanbase:

  • person_profiles: 'identified_only' (default, recommended)
    → Captures anonymous events by default. Identified events are tracked only when a user profile exists.

  • person_profiles: 'always'
    → Captures identified events for all events.

Example (Web):

leanbase.init('lbk_your_project_key', {
  api_host: 'https://api.leanbase.io',
  person_profiles: 'always'
});

Capturing Identified Events

If you’ve configured personProfiles: 'identified_only' (default), anonymous events are captured automatically.
To record identified events, call any of these methods:

identify()
alias()
group()
setPersonProperties()
setPersonPropertiesForFlags()
setGroupPropertiesForFlags()

When one of these functions is called, Leanbase creates a user profile for that individual.
All subsequent events from that user will then be captured as identified events.

Alternatively, you can configure:

personProfiles: 'always'

to capture identified events by default.