-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fixed issue with DbxAnalyticsService not using the config's user source value - added DbxFirebaseAnalyticsUserEventsListener for sending user login/logout analytics events
- Loading branch information
Showing
4 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/dbx-firebase/src/lib/analytics/analytics.user.events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { DbxAnalyticsService, DbxAnalyticsUser, DbxAnalyticsUserProperties, DbxAnalyticsUserSource } from '@dereekb/dbx-analytics'; | ||
import { filterMaybe, SubscriptionObject } from '@dereekb/rxjs'; | ||
import { Destroyable, FactoryWithRequiredInput, Initialized, Maybe } from '@dereekb/util'; | ||
import { BehaviorSubject, map, Observable, of, switchMap, shareReplay, combineLatest, first } from 'rxjs'; | ||
import { AuthUserInfo } from '../auth/auth'; | ||
import { DbxFirebaseAuthService } from '../auth/service/firebase.auth.service'; | ||
import { DbxFirebaseAnalyticsUserSource } from './analytics.user.source'; | ||
|
||
/** | ||
* Service that listens for DbxFirebaseAuthService changes and emits them a user events. | ||
*/ | ||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class DbxFirebaseAnalyticsUserEventsListener implements Initialized, Destroyable { | ||
private _loginSub = new SubscriptionObject(); | ||
private _logoutSub = new SubscriptionObject(); | ||
|
||
constructor(readonly dbxFirebaseAuthService: DbxFirebaseAuthService, readonly dbxFirebaseAnalyticsUserSource: DbxFirebaseAnalyticsUserSource, readonly dbxAnalyticsService: DbxAnalyticsService) {} | ||
|
||
init(): void { | ||
this._loginSub.subscription = this.dbxFirebaseAuthService.onLogIn$.subscribe(() => { | ||
this.dbxFirebaseAnalyticsUserSource.analyticsUser$.pipe(filterMaybe(), first()).subscribe((analyticsUser) => { | ||
this.dbxAnalyticsService.sendUserLoginEvent(analyticsUser); | ||
}); | ||
}); | ||
|
||
this._logoutSub.subscription = this.dbxFirebaseAuthService.onLogOut$.subscribe(() => { | ||
this.dbxAnalyticsService.sendUserLogoutEvent(); | ||
}); | ||
} | ||
|
||
destroy(): void { | ||
this._loginSub.destroy(); | ||
this._logoutSub.destroy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './analytics.user.events'; | ||
export * from './analytics.user.source'; |