Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(analytics): add installation docs and move usage docs within guides folder #3006

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { }
```
Loading