How to use Google Analytics with AngularFire?
Asked Answered
T

2

20

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?

Titan answered 19/10, 2019 at 7:54 Comment(1)
This blog could be helpful: arunraj6.medium.com/…Solenne
P
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).

Pyrosis answered 3/2, 2020 at 15:47 Comment(3)
Run npm -v @angular/fire and nom -v firebase to check your current version installedToffic
In later versions of AngularFire AngularFireAnalyticsModule moved to @angular/fire/compat/analytics.Titfer
@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.Petitioner
T
3

Support for Firebase Analytics is coming to AngularFire https://github.com/angular/angularfire/issues/2178

Titan answered 19/10, 2019 at 8:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.