@daffodil/analytics
Advanced tools
Comparing version 0.68.0 to 0.68.1
@@ -11,4 +11,31 @@ import { InjectionToken } from '@angular/core'; | ||
} | ||
/** | ||
* A function that tracks analytics events. | ||
*/ | ||
export type DaffAnalyticsTrackerFunction = (event: DaffAnalyticsEvent) => Observable<unknown>; | ||
/** | ||
* The tracker type. | ||
* | ||
* Trackers can either be classes: | ||
* | ||
* ```ts | ||
* export class MyTracker implements DaffAnalyticsTracker { | ||
* track(event: DaffAnalyticsEvent) { | ||
* return of(true); | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* or functions: | ||
* | ||
* ```ts | ||
* export const trackThis = (event: DaffAnalyticsEvent) => { | ||
* return of(true); | ||
* } | ||
* ``` | ||
*/ | ||
export type DaffAnalyticsTracker = DaffAnalyticsTrackerFunction | DaffAnalyticsTrackerClass; | ||
/** | ||
* An injection token representing all of the different analytics trackers. | ||
*/ | ||
export declare const DaffAnalyticsServices: InjectionToken<DaffAnalyticsTracker[]>; |
@@ -5,2 +5,9 @@ import { ModuleWithProviders, Provider } from '@angular/core'; | ||
import * as i1 from "@ngrx/effects"; | ||
/** | ||
* Sets up providers necessary to enable analytics tracking functionality for the application. | ||
* Allows to configure a set of trackers as well as additional configuration details like "analyzeableActions". | ||
* | ||
* See {@link DaffAnalyticsConfigInterface} for further configuration options. | ||
* See {@link DaffAnalyticsTracker} for tracker documentation. | ||
*/ | ||
export declare class DaffAnalyticsModule { | ||
@@ -7,0 +14,0 @@ static forRoot(services?: Provider[], config?: DaffAnalyticsConfigInterface): ModuleWithProviders<DaffAnalyticsModule>; |
@@ -8,5 +8,14 @@ import { InjectionToken } from '@angular/core'; | ||
export declare const defaultConfig: DaffAnalyticsConfigInterface; | ||
/** | ||
* Allows you to provide configuration to the `@daffodil/analytics` package. | ||
*/ | ||
export interface DaffAnalyticsConfigInterface { | ||
/** | ||
* A set of actions that will be available for analysis by trackers. | ||
*/ | ||
analyzableActions: string[]; | ||
} | ||
/** | ||
* Allows you to provide configuration to the `@daffodil/analytics` package. | ||
*/ | ||
export declare const DaffAnalyticsConfig: InjectionToken<DaffAnalyticsConfigInterface>; |
@@ -14,5 +14,4 @@ import { Actions } from '@ngrx/effects'; | ||
/** | ||
* Tracks events in external services. Importantly, this allows for there to be multiple analytics services | ||
* in the event multiple are in use, or, more importantly, in the event | ||
* there needs to be a transition from one service to another (Universal Analytics to GA4 for example). | ||
* Tracks events in external services. Importantly, this allows for there to | ||
* be multiple analytics services that subscribe to the same event. | ||
*/ | ||
@@ -19,0 +18,0 @@ trackAnalyticsEvent$: import("rxjs").Observable<unknown[]> & import("@ngrx/effects").CreateEffectMetadata; |
/** | ||
* A generalized event that happens to collide nicely with the Actions of packages like | ||
* Redux and @ngrx/store. | ||
* A generalized event that happens to collide nicely with the Action interface | ||
* of packages like Redux and @ngrx/store. | ||
*/ | ||
export interface DaffAnalyticsEvent { | ||
/** | ||
* The type of the event to track. Used to deterrmine whether or not an action is analyzeable. | ||
*/ | ||
type: string; | ||
} |
@@ -1,1 +0,1 @@ | ||
{"name":"@daffodil/analytics","nx":{"targets":{"build":{"outputs":["{workspaceRoot}/dist/analytics"]}}},"version":"0.68.0","description":"General package for piping ngrx actions into provided external analytics services.","repository":{"type":"git","url":"https://github.com/graycoreio/daffodil"},"author":"Graycore LLC","license":"MIT","bugs":{"url":"https://github.com/graycoreio/daffodil/issues"},"peerDependencies":{"@angular/common":"^17.0.0","@angular/core":"^17.0.0","rxjs":"7.8.1","@ngrx/store":"^17.0.0","@ngrx/effects":"^17.0.0"},"module":"fesm2022/daffodil-analytics.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2022":"./esm2022/daffodil-analytics.mjs","esm":"./esm2022/daffodil-analytics.mjs","default":"./fesm2022/daffodil-analytics.mjs"}},"sideEffects":false,"dependencies":{"tslib":"^2.3.0"}} | ||
{"name":"@daffodil/analytics","nx":{"targets":{"build":{"outputs":["{workspaceRoot}/dist/analytics"]}}},"version":"0.68.1","description":"General package for piping ngrx actions into provided external analytics services.","repository":{"type":"git","url":"https://github.com/graycoreio/daffodil"},"author":"Graycore LLC","license":"MIT","bugs":{"url":"https://github.com/graycoreio/daffodil/issues"},"peerDependencies":{"@angular/common":"^17.0.0","@angular/core":"^17.0.0","rxjs":"7.8.1","@ngrx/store":"^17.0.0","@ngrx/effects":"^17.0.0"},"module":"fesm2022/daffodil-analytics.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2022":"./esm2022/daffodil-analytics.mjs","esm":"./esm2022/daffodil-analytics.mjs","default":"./fesm2022/daffodil-analytics.mjs"}},"sideEffects":false,"dependencies":{"tslib":"^2.3.0"}} |
@@ -1,45 +0,52 @@ | ||
# Analytics Actions Mapping | ||
# @daffodil/analytics | ||
## VIEW_ITEM_LIST | ||
## Overview | ||
- DaffCategoryLoadSuccess | ||
- DaffCategoryPageLoadSuccess | ||
- DaffProductPageLoadSuccess (upsell/related) | ||
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`](https://ngrx.io/api/store/Action) from [`@ngrx/store`](https://ngrx.io/guide/store), rather than browser events. Additionally, the package includes testing utilities tailored for analytics event tracking in Angular applications. | ||
## VIEW_ITEM | ||
## Features | ||
- ["Opt-in" action tracking](./docs/configuration.md#configuring-analyzeableactions) | ||
- DaffProductPageLoadSuccess | ||
## Usage | ||
## ADD_TO_CART | ||
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. | ||
- DaffAddToCartSuccess | ||
### Define a tracking service | ||
## REMOVE_FROM_CART | ||
```ts | ||
import { Injectable } from '@angular/core'; | ||
import { DaffAnalyticsTrackerClass } from '@daffodil/analytics'; | ||
import { Action } from '@ngrx/store'; | ||
import { Observable, of } from 'rxjs'; | ||
- DaffRemoveFromCartSuccess | ||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class MyAnalyticsService implements DaffAnalyticsTrackerClass { | ||
## VIEW_CART | ||
track(action: Action): Observable<unknown> { | ||
// Your custom logic for tracking analytics events based on the provided action | ||
// Return an observable, for example, indicating whether the tracking was successful | ||
return of(true); | ||
} | ||
} | ||
``` | ||
- RouterAction | ||
### Import DaffAnalyticsModule in Your Application | ||
## BEGIN_CHECKOUTS | ||
```ts | ||
import { DaffAnalyticsModule } from '@daffodil/analytics'; | ||
- RouterAction | ||
// Import your custom analytics service(s) | ||
import { MyAnalyticsService } from './path/to/my-analytics.service'; | ||
## ADD_SHIPPING_INFO | ||
- DaffApplyShippingMethodSuccess | ||
## ADD_PAYMENT_INFO | ||
- DaffApplyPaymentMethodSuccessAction | ||
## PURCHASE | ||
- DaffPlaceOrderSuccessMessage | ||
## PAGEVIEW | ||
- DaffProductPageLoadSuccess | ||
- DaffCategoryPageLoadSuccess | ||
@NgModule({ | ||
imports: [ | ||
// Initialize Daffodil Analytics Module with custom analytics service(s) | ||
DaffAnalyticsModule.forRoot([MyAnalyticsService]), | ||
// ... other modules | ||
], | ||
// ... other module metadata | ||
}) | ||
export class YourAppModule { } | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38250
312
53