Skip to main content
Version: Next

AnalyticsEngine

AnalyticsEngine

AnalyticsEngine class for managing analytics providers and tracking events. This class allows you to register a provider, set a filter for events, and track or identify events.

Signature
class AnalyticsEngine {
constructor(commandkit: CommandKit)
setFilter(filter: FilterFunction | null) => ;
registerProvider(provider: AnalyticsProvider) => ;
removeProvider(provider: AnalyticsProvider) => ;
getProvider() => AnalyticsProvider | null;
identify(event: IdentifyEvent) => ;
track(event: AnalyticsEvent) => ;
}

constructor

method
(commandkit: CommandKit) => AnalyticsEngine

Creates an instance of the AnalyticsEngine.

setFilter

method
(filter: FilterFunction | null) =>

Sets a filter function for analytics events. This function will be called before tracking an event to determine if it should be tracked. If the filter returns false, the event will not be tracked. If the filter is set to null, all events will be tracked unless doNotTrack is enabled.

registerProvider

method
(provider: AnalyticsProvider) =>

Registers an analytics provider. This provider will be used to track and identify events. If a provider is already registered, it will be replaced with the new one.

removeProvider

method
(provider: AnalyticsProvider) =>

Removes the currently registered analytics provider.

getProvider

method
() => AnalyticsProvider | null

Retrieves the currently registered analytics provider.

identify

method
(event: IdentifyEvent) =>

Identifies a user with the analytics provider. This method sends an identify event to the provider, which can be used to associate user data with events.

track

method
(event: AnalyticsEvent) =>

Tracks an analytics event with the registered provider. This method sends the event to the provider, which can then process it as needed. If the doNotTrack setting is enabled or if the filter function returns false, the event will not be tracked.