Skip to content

Latest commit

 

History

History
61 lines (47 loc) · 1.76 KB

File metadata and controls

61 lines (47 loc) · 1.76 KB

AngularFireDeveloper Guide ❱ Analytics

Analytics

Google Analytics is an app measurement solution, available at no charge, that provides insight on app usage and user engagement.

Learn more

Dependency Injection

As a prerequisite, ensure that AngularFire has been added to your project via

ng add @angular/fire

Provide a Google Analytics instance in the application's NgModule (app.module.ts):

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...
    // App initialization
    provideFirebaseApp(() => initializeApp(environment.firebase)),
    provideAnalytics(() => getAnalytics())
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

In your component class, for example user-profile.component.ts import and inject Firestore:

import { Component, inject } from '@angular/core';
import { Analytics } from '@angular/fire/analytics';

@Component({
    standalone: true,
    selector: 'app-user-profile',
    ...
})
export class UserProfileComponent {
    private analytics: Analytics = inject(Analytics);
    ...
}

Firebase API

AngularFire wraps the Firebase JS SDK to ensure proper functionality in Angular, while providing the same API.

Update the imports from import { ... } from 'firebase/analytics' to import { ... } from '@angular/fire/analytics' and follow the official documentation.

Getting Started | API Reference