This library 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
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
Optionally, you can include additional information with the event by including a properties object:
Capturing pageviews
If you're aiming for a backend-only implementation of Leanbase and won't be capturing events from your frontend, you can send pageviews from your backend like so:
Person profiles and properties
For backward compatibility, the Go SDK captures identified events by default. These create person profiles. To set person properties in these profiles, include them when capturing an event:
For more details on the difference between $set and $set_once, see our person properties docs.
To capture anonymous events without person profiles, set the event's $process_person_profile property to false:
Alias
Sometimes, you want to assign multiple distinct IDs to a single user. This is helpful when your primary distinct ID is inaccessible. For example, if a distinct ID used on the frontend is not available in your backend.
In this case, you can use alias to assign another distinct ID to the same user.
We strongly recommend reading our docs on alias to best understand how to correctly use this method.
Overriding GeoIP properties
By default, a user's GeoIP properties are set using the IP address they use to capture events on the frontend. You may want to override the these properties when evaluating feature flags. A common reason to do this is when you're not using Leanbase on your frontend, so the user has no GeoIP properties.
You can override GeoIP properties by including them in the person_properties parameter when evaluating feature flags. This is useful when you're evaluating flags on your backend and want to use the client's location instead of your server's location.
The following GeoIP properties can be overridden:
$geoip_country_code
$geoip_country_name
$geoip_city_name
$geoip_city_confidence
$geoip_continent_code
$geoip_continent_name
$geoip_latitude
$geoip_longitude
$geoip_postal_code
$geoip_subdivision_1_code
$geoip_subdivision_1_name
$geoip_subdivision_2_code
$geoip_subdivision_2_name
$geoip_subdivision_3_code
$geoip_subdivision_3_name
$geoip_time_zone
Simply include any of these properties in the person_properties parameter alongside your other person properties when calling feature flags.
Request timeout
You can configure the FeatureFlagRequestTimeout parameter when initializing your Leanbase client to set a flag request timeout. This helps prevent your code from being blocked in the case when Leanbase's servers are too slow to respond. By default, this is set at 3 seconds.
Error handling
When using the Leanbase SDK, it's important to handle potential errors that may occur during feature flag operations. Here's an example of how to wrap Leanbase SDK methods in an error handler:
Local Evaluation
Evaluating feature flags requires making a request to Leanbase for each flag. However, you can improve performance by evaluating flags locally. Instead of making a request for each flag, Leanbase will periodically request and store feature flag definitions locally, enabling you to evaluate flags without making additional requests.
It is best practice to use local evaluation flags when possible, since this enables you to resolve flags faster and with fewer API calls.
Group analytics
Group analytics allows you to associate an event with a group (e.g. teams, organizations, etc.). Read the Group Analytics guide for more information.
Send an event associated with a group
Update properties on a group
The name is a special property which is used in the Leanbase UI for the name of the group. If you don't specify a name property, the group ID will be used instead.
Thank you
This library is largely based on the analytics-go package.