@daffodil/analytics
Overview
The Daffodil Analytics Module is a lightweight Angular package that helps integrate analytics providers into your Angular applications, supporting multiple analytics services. It simplifies event tracking and provides configuration options, such as defining analyzable actions. Notably, this module focuses on handling state-related events and operates specifically on Actions
from @ngrx/store
, rather than browser events. Additionally, the package includes testing utilities tailored for analytics event tracking in Angular applications.
Features
Usage
In this example, MyAnalyticsService
implements the DaffAnalyticsTrackerClass
interface, providing a track method. Inside the track method, you can define your custom logic for tracking analytics events based on the provided action. The service returns an observable, indicating the success of the tracking operation. Replace the logic inside the track method with your actual analytics tracking implementation.
Define a tracking service
import { Injectable } from '@angular/core';
import { DaffAnalyticsTrackerClass } from '@daffodil/analytics';
import { Action } from '@ngrx/store';
import { Observable, of } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class MyAnalyticsService implements DaffAnalyticsTrackerClass {
track(action: Action): Observable<unknown> {
return of(true);
}
}
Import DaffAnalyticsModule in Your Application
import { DaffAnalyticsModule } from '@daffodil/analytics';
import { MyAnalyticsService } from './path/to/my-analytics.service';
@NgModule({
imports: [
DaffAnalyticsModule.forRoot([MyAnalyticsService]),
],
})
export class YourAppModule { }