I have an Angular app build with AngularFire and hosted on Firebase. How should I be using Analytics SDK to set the user ID, track page loads and log custom events?
Asked
Active
Viewed 1.2k times
20

Thierry Falvo
- 5,892
- 2
- 21
- 39

Alexander Zhidkov
- 531
- 1
- 5
- 16
-
This blog could be helpful: https://arunraj6.medium.com/angular8-10-with-firebase-analytics-7667bf63c6b1 – Arun Raj R May 10 '22 at 17:07
2 Answers
45
AngularFire is now supporting Firebase Analytics since version 5.3.0.
You can update your dependencies :
"@angular/fire": "^5.2.3",
"firebase": "^7.8.0"
As mentioned by AngularFire Docs, you just have to add AngularFireAnalyticsModule
:
import { AngularFireAnalyticsModule } from '@angular/fire/analytics';
@NgModule({
imports: [
AngularFireModule.initializeApp(environment.firebase),
AngularFireAnalyticsModule
]
})
export class AppModule { }
Be sure to add your appId
and measurementId
to your config file. (retrieve from Firebase Console, after enabling Analytics).

Thierry Falvo
- 5,892
- 2
- 21
- 39
-
Run npm -v @angular/fire and nom -v firebase to check your current version installed – Sébastien REMY Feb 12 '20 at 06:34
-
4In later versions of AngularFire `AngularFireAnalyticsModule` moved to `@angular/fire/compat/analytics`. – Mike Poole Jan 15 '22 at 09:09
-
@MikePoole do you know if there is none compat import that we should be using instead now? I see there is a `import { AnalyticsModule } from "@angular/fire/analytics";` available now. – Zaffer Apr 10 '23 at 12:28
3
Support for Firebase Analytics is coming to AngularFire https://github.com/angular/angularfire/issues/2178

Alexander Zhidkov
- 531
- 1
- 5
- 16