在 Ionic 2 中实施 Google 分析时出错
Error Implementing Google Analytics into Ionic 2
尝试集成 Google 分析(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/
但是,当我在模拟器中 运行 我的应用程序时,我在编译时遇到以下错误:
TypeScript 错误:app/app.ts(21,14):错误 TS2339:属性 'analytics' 在类型 'Window' 上不存在。
有什么想法吗?
您使用的示例未使用打字稿或 ionic-native module。
这是一个你可以看看的项目https://github.com/aaronksaunders/GAProject
在app.ts
import {StatusBar, GoogleAnalytics} from 'ionic-native';
你也应该这样访问模块
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)
})
});
}
}
尝试集成 Google 分析(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/
但是,当我在模拟器中 运行 我的应用程序时,我在编译时遇到以下错误:
TypeScript 错误:app/app.ts(21,14):错误 TS2339:属性 'analytics' 在类型 'Window' 上不存在。
有什么想法吗?
您使用的示例未使用打字稿或 ionic-native module。
这是一个你可以看看的项目https://github.com/aaronksaunders/GAProject
在app.ts
import {StatusBar, GoogleAnalytics} from 'ionic-native';
你也应该这样访问模块
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)
})
});
}
}