The Hackle SDK provides a feature to send user events to Hackle. By utilizing this feature at points where user behavior changes, you can gather meaningful data about user actions, enabling you to analyze user behavior.
You can send user events using the
Track() method by providing an event and a user. If necessary, you can include a numeric value in the
value when sending user events.
valuecan only be of type number.
Let's assume you want to collect an event key called "purchase" when a user clicks the "purchase" button. In this case, you may also want to collect the purchase amount. You can include the purchase amount in the
value in such cases.
import "github.com/hackle-io/hackle-go-sdk/hackle" // Sending an event called "purchase" generated by a user with the identifier "ae2182e0" // Example 1: Sending only the event key user := hackle.NewUserBuilder().ID("ae2182e0").Build() event := hackle.NewEvent("purchase") hackleClient.Track(event, user) /* Example 2: Sending the event key along with a numeric value */ user := hackle.NewUserBuilder().ID("ae2182e0").Build() event = hackle.NewEventBuilder("purchase"). Value(13200). // Include the numeric value to be collected along with the event key in the value Build() hackleClient.Track(event, user)
In Example 1, only the event key is sent. In Example 2, a case is shown where the purchase amount is included in the
value to collect it.
The Hackle SDK supports adding properties to the Event object.
- Properties must be sent as key-value pairs.
- You can add up to a maximum of 64 properties to an event object.
- It is recommended to create key names like regular variable names but make them easy to identify.
- The character limit for keys is 64 characters.
- Case is not sensitive. For example, "amount" and "AMOUNT" are recognized as the same key.
- Values can be boolean, string, or number types.
- For string types, the character limit is 64 characters.
- For number types, the maximum integer length is 15 digits, and the maximum decimal length is 6 digits.
In the example below, three properties (
is_discount) are added:
import "github.com/hackle-io/hackle-go-sdk/hackle" event = hackle.NewEventBuilder("purchase"). Property("pay_method", "CARD"). Property("discount_amount", 800). Property("is_discount", true). Build() hackleClient.Track(event, user)
Updated 2 months ago