Track
Tracks a custom analytics event with optional attributes.
Description
Superfans.track sends a custom analytics or marketing event from a custom block.
Pass an object with a required eventName and optional attributes.
This is a core SDK method, not Superfans.actions.track.
Function Signature
await Superfans.track({
eventName: "event_name",
attributes: {
key: "value"
}
});| Parameter | Type | Required | Description |
|---|---|---|---|
| eventName | String | Yes | Non-empty name of the event to track. |
| attributes | Object | No | JSON object of event properties. Must be an object if provided, not an array. |
Structure of Response
| Status | Response |
|---|---|
| Success | { "status": "success", "message": "Event tracked successfully" } |
| Invalid Params | { "status": "error", "errorId": 400, "errorHandle": "invalid-params", "message": "Event name should be provided." } |
| Unexpected Error | { "status": "error", "errorId": 500, "errorHandle": "unknown-error", "message": "Something unexpected happened" } |
Example Usage
try {
await Superfans.track({
eventName: "event_name",
attributes: {
key: "value"
}
});
} catch (error) {
await Superfans.actions.showToast({
title: "Something went wrong",
message: "Please try again."
});
}Best Practices
- Use a stable
eventNamestring. Do not send an empty string. - Keep
attributesas a JSON object of primitive or nested values. Do not pass an array. - Track after the user action succeeds, not before.
Caveats
- Call
Superfans.track({ eventName, attributes }). This is not available asSuperfans.actions.track. eventNameis required.attributesis optional, but must be a JSON object when provided.
Updated about 7 hours ago
Did this page help you?