The “NullInjectorError: No provider for GoogleAnalytics!” error typically occurs when you are trying to use the Google Analytics service in your Ionic app, but the service has not been properly configured or injected into your app.
Error:
NullInjectorError: R3InjectorError(AppModule)[PlatformService -> GoogleAnalytics -> GoogleAnalytics -> GoogleAnalytics]: NullInjectorError: No provider for GoogleAnalytics! at NullInjector.get (core.mjs:8096:27) at R3Injector.get (core.mjs:8546:33) at R3Injector.get (core.mjs:8546:33) at R3Injector.get (core.mjs:8546:33) at injectInjectorOnly (core.mjs:738:33) at ɵɵinject (core.mjs:742:60) at Object.PlatformService_Factory [as factory] (ɵfac.js? [sm]:1:1) at R3Injector.hydrate (core.mjs:8647:35) at R3Injector.get (core.mjs:8535:33)
There are a few common reasons for this error:
You have not imported the Google Analytics service into your app: Make sure that you have imported the Google Analytics service into your app by adding the following line to your app’s module file:
import { GoogleAnalytics } from '@ionic-native/google-analytics/ngx';
You have not added the Google Analytics service to the providers array of your app’s module: Make sure that you have added the Google Analytics service to the providers array of your app’s module file:
providers: [
GoogleAnalytics
]