Leanbase Help Center

Your Guide to Building Products Customers Love

Install .NET SDK

This is an optional library you can install if you're working with .NET Core.
It uses an internal queue to make calls fast and non-blocking.
It also batches requests and flushes asynchronously, making it perfect to use in any part of your web app or other server-side application that needs performance.


Installation

At the moment, ASP.NET Core is the only supported platform for the Leanbase .NET SDK.
However, we do have experimental support for other platforms mentioned later in this document.

In your Program.cs (or Startup.cs for ASP.NET Core 2.x), add the following code:

Make sure to configure Leanbase with your Project API Key, Instance URL, and optional Personal API Key.

Note: If the host is not specified, the default host https://us.i.leanbase.com is used.

Use a secrets manager to store your personal API key.
For local development, you can use the UserSecrets feature:

You can find your Project API Key and Instance Address in your Leanbase project settings.

To see detailed logging, set the log level to Debug or Trace in appsettings.json:


Capturing events

You can send custom events using Capture:

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

Include additional information using the properties argument:


Sending page views

If you're aiming for a backend-only implementation of PostHog and won't be capturing events from your frontend, you can send $pageview events from your backend like so:


Person profiles and properties

The .NET SDK creates person profiles automatically.
To set properties on profiles:

To capture anonymous events without profiles, set the event's $process_person_profile property to false:


Alias

To merge multiple distinct IDs into one user:


Group analytics

To capture an event and associate it with a group, add the groups argument to your Capture call:

Update properties on a group, use the GroupIdentifyAsync method:

The name is a special property which is used in the PostHog UI for the name of the group. If you don't specify a name property, the group ID will be used instead.