trackEvent method
Logs a custom event with the provided name.
Events are cached locally and automatically flushed to the server:
- Every
kEventFlushIntervalMinutes
minutes - When manually calling flushEvents
- When the device comes back online after being offline
- When the number of cached events reaches
kEventBatchSize
Parameters:
name
: The name of the event to track
Example:
await SuperFCM.instance.trackEvent('begin_checkout');
Implementation
Future<void> trackEvent(String name) async {
return _queueOrExecute("trackEvent", () async {
logger.i('Tracking event: $name');
await CacheManager.instance.addItem("events", {
'name': name,
'subscriptionId': subscription?.id,
});
final cachedEvents = await CacheManager.instance.getItems('events');
if (cachedEvents.length >= kEventBatchSize) {
logger.d('Event batch size reached, triggering flush');
await flushEvents();
}
logger.v('Successfully tracked event: $name');
});
}