Error Implementing Google Analytics into Ionic 2

≡放荡痞女 提交于 2020-01-12 10:12:52

问题


Trying to integrate Google Analytics ( http://ionicframework.com/docs/v2/native/google-analytics/ ) into my app, followed this tutorial as the docs didn't really have any sort of implementation instructions: https://www.thepolyglotdeveloper.com/2016/03/use-google-analytics-in-an-ionic-2-android-and-ios-app/

However, when I run my app in Simulator I get the following error while compiling:

TypeScript error: app/app.ts(21,14): Error TS2339: Property 'analytics' does not exist on type 'Window'.

Any ideas?


回答1:


the sample you are using is not using typescript or the ionic-native module.

here is a project you can look at https://github.com/aaronksaunders/GAProject

in app.ts

import {StatusBar, GoogleAnalytics} from 'ionic-native';

also you should access the module this way

import {Component} from '@angular/core';
import {Platform, ionicBootstrap} from 'ionic-angular';
import {StatusBar, GoogleAnalytics} from 'ionic-native';
import {HomePage} from './pages/home/home';


@Component({
  template: '<ion-nav [root]="rootPage"></ion-nav>'
})
export class MyApp {
  rootPage: any = HomePage;

  constructor(platform: Platform) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.styleDefault();

      // google
      GoogleAnalytics.debugMode()
      GoogleAnalytics.startTrackerWithId("YOUR_GOOGLE_ID");

      GoogleAnalytics.enableUncaughtExceptionReporting(true)
        .then((_success) => {
          console.log(_success)
        }).catch((_error) => {
          console.log(_error)
        })

    });
  }
}


来源:https://stackoverflow.com/questions/38104609/error-implementing-google-analytics-into-ionic-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!