Ionic: GoogleAnalytics plugin Error: ts: Cannot find name 'GoogleAnalytics'

717 Views Asked by At

I am trying to use Google Analytics plugin on Ionic, the documentation code is not applicable as when I use:

constructor(private ga: GoogleAnalytics)

the editor says "ts: Cannot find name 'GoogleAnalytics'" however it can see some Object GoogleAnalyticsOriginal instead which compiles but does not work (gives error on runtime).

These are system specs ionic (Ionic CLI) : 4.5.0

Ionic Framework : ionic-angular 3.9.2

@ionic/app-scripts : 3.2.1

Cordova: cordova (Cordova CLI) : 8.1.2 ([email protected])

Cordova Platforms : android 7.1.4

Cordova Plugins : cordova-plugin-ionic-webview 1.1.1, (and 15 other plugins) System:

NodeJS : v10.13.0 (C:\Program Files\nodejs\node.exe)

npm : 6.5.0

1

There are 1 best solutions below

0
On BEST ANSWER

You installed the latest @ionic-native/google-analytics (v5+).

Then you should import GoogleAnalytics from @ionic-native/google-analytics/ngx

import { GoogleAnalytics } from '@ionic-native/google-analytics/ngx';

Or else install @ionic-native/google-analytics with v4+, then you can import GoogleAnalytics from @ionic-native/google-analytics

import { GoogleAnalytics } from '@ionic-native/google-analytics';