You can send custom events using capture:
client.Enqueue(posthog.Capture{
DistinctId: "distinct_id_of_the_user",
Event: "user_signed_up",
})
Tip: We recommend using a [object] [verb] format for your event names, where [object] is the entity that the behavior relates to, and [verb] is the behavior itself. For example, project created, user signed up, or invite sent.
Setting event properties
Optionally, you can include additional information with the event by including a properties object:
client.Enqueue(leanbase.Capture{
DistinctId: "distinct_id_of_the_user",
Event: "user_signed_up",
Properties: leanbase.NewProperties().
Set("login_type", "email").
Set("is_free_trial", true),
})
Capturing pageviews
If you're aiming for a backend-only implementation of PostHog and won't be capturing events from your frontend, you can send pageviews from your backend like so:
client.Enqueue(leanbase.Capture{
DistinctId: "distinct_id_of_the_user",
Event: "$pageview",
Properties: leanbase.NewProperties().
Set("$current_url", "https://example.com"),
})
Event ingestion
It's a priority for us that events are fully processed and saved as soon as possible. Typically, events will be usable in queries within a few minutes.
Advanced: Anonymous vs identified events
Leanbase captures two types of events: anonymous and identified
Identified events enable you to attribute events to specific users, and attach person properties. They're best suited for logged-in users.
Scenarios where you want to capture identified events are:
Tracking logged-in users in B2B and B2C SaaS apps
Doing user segmented product analysis
Growth and marketing teams wanting to analyze the complete conversion lifecycle
Anonymous events are events without individually identifiable data. They're best suited for web analytics or apps where users aren't logged in.
Scenarios where you want to capture anonymous events are:
Tracking a marketing website
Content-focused sites
B2C apps where users don't sign up or log in
Under the hood, the key difference between identified and anonymous events is that for identified events we create a person profile for the user, whereas for anonymous events we do not.
Important: Due to the reduced cost of processing them, anonymous events can be up to 4x cheaper than identified ones, so we recommended you only capture identified events when needed.
How to capture anonymous events
The JavaScript Web SDK captures anonymous events by default. However, this may change depending on your person_profiles config when initializing Leanbase:
person_profiles: 'identified_only' (recommended) (default) - Anonymous events are captured by default. Leanbase only captures identified events for users where person profiles have already been created.
person_profiles: 'always' - Capture identified events for all events.
For example:
Web
Leanbase.init('phc_CTMqwSYhUFLHhkWWDKZWUkDtFH025P3OwkWfb5h1Y2v', {api_host: 'https://us.i.Leanbase.com',defaults: '2025-05-24',person_profiles: 'always'})Backend
Leanbase's backend SDKs and API capture identified events by default. To capture anonymous events, set the $process_person_profile property to false:
Node.jsPythonPHPRubyGoJavaRustElixirTerminalclient.capture({distinctId: 'distinct_id_of_the_user',event: 'your_event_name',properties: {$process_person_profile: false,},})Android
The Android SDK captures anonymous events by default. However, this may change depending on your personProfiles config when initializing PostHog:
personProfiles = PersonProfiles.IDENTIFIED_ONLY (recommended) (default) - Anonymous events are captured by default. Leanbaseonly captures identified events for users where person profiles have already been created.
personProfiles = PersonProfiles.ALWAYS - Capture identified events for all events.
personProfiles = PersonProfiles.NEVER - Capture anonymous events for all events.
For example:
val config = LeanbaseAndroidConfig(apiKey = Leanbase_API_KEY,host = Leanbase_HOST,).apply {personProfiles = PersonProfiles.IDENTIFIED_ONLY}