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"
  }
});
ParameterTypeRequiredDescription
eventNameStringYesNon-empty name of the event to track.
attributesObjectNoJSON object of event properties. Must be an object if provided, not an array.

Structure of Response

StatusResponse
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

  1. Use a stable eventName string. Do not send an empty string.
  2. Keep attributes as a JSON object of primitive or nested values. Do not pass an array.
  3. Track after the user action succeeds, not before.

Caveats

  1. Call Superfans.track({ eventName, attributes }). This is not available as Superfans.actions.track.
  2. eventName is required. attributes is optional, but must be a JSON object when provided.

Did this page help you?