Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 1.67 KB

analytics.md

File metadata and controls

55 lines (39 loc) · 1.67 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 Analytics instance in the application's app.config.ts:

import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { provideAnalytics, getAnalytics } from '@angular/fire/analytics';

export const appConfig: ApplicationConfig = {
  providers: [
    provideFirebaseApp(() => initializeApp({ ... })),
    provideAnalytics(() => getAnalytics()),
    ...
  ],
  ...,
}

Next inject Analytics into your component:

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

@Component({ ... })
export class UserProfileComponent {
    private 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