Skip to content

Commit

Permalink
docs(analytics): add installation docs and move usage docs within gui…
Browse files Browse the repository at this point in the history
…des folder (#3006)
  • Loading branch information
xelaint authored Aug 20, 2024
1 parent 91bbe0f commit 81e649c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 39 deletions.
51 changes: 12 additions & 39 deletions libs/analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,21 @@
`@daffodil/analytics` is a lightweight Angular package that helps integrate analytics providers into your Angular applications, supporting multiple analytics services.

## Overview
It simplifies event tracking and provides configuration options, such as defining analyzable actions. Notably, `@daffodil/analytics` 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.
It simplifies event tracking and provides configuration options, such as defining analyzable actions. Notably, `@daffodil/analytics` 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, it includes testing utilities tailored for analytics event tracking in Angular applications.

## Features
- ["Opt-in" action tracking](/libs/analytics/guides/configuration.md#configuring-analyzeableactions)

## 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
```ts
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 {
## Installation
To install `@daffodil/analytics` and its required dependencies, use the following commands in the terminal.

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);
}
}
Install with npm:
```bash
npm install @daffodil/auth @angular/common @angular/core @ngrx/store @ngrx/effects rxjs --save
```

### Set up the root component
```ts
import { DaffAnalyticsModule } from '@daffodil/analytics';
Install with yarn:

// Import your custom analytics service(s)
import { MyAnalyticsService } from './path/to/my-analytics.service';

@NgModule({
imports: [
// Initialize Daffodil Analytics Module with custom analytics service(s)
DaffAnalyticsModule.forRoot([MyAnalyticsService]),
// ... other modules
],
// ... other module metadata
})
export class YourAppModule { }
```bash
yarn add @daffodil/auth @angular/common @angular/core @ngrx/store @ngrx/effects rxjs
```

## Features
- ["Opt-in" action tracking](/libs/analytics/guides/configuration.md#configuring-analyzeableactions)
41 changes: 41 additions & 0 deletions libs/analytics/guides/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Usage

## Define a tracking service
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.

```ts
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> {
// 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);
}
}
```

## Set up the root component
```ts
import { DaffAnalyticsModule } from '@daffodil/analytics';

// Import your custom analytics service(s)
import { MyAnalyticsService } from './path/to/my-analytics.service';

@NgModule({
imports: [
// Initialize Daffodil Analytics Module with custom analytics service(s)
DaffAnalyticsModule.forRoot([MyAnalyticsService]),
// ... other modules
],
// ... other module metadata
})
export class YourAppModule { }
```

0 comments on commit 81e649c

Please sign in to comment.