将Google Analytics实施到Ionic 2时出错 [英] Error Implementing Google Analytics into Ionic 2

查看:89
本文介绍了将Google Analytics实施到Ionic 2时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试整合Google Analytics( http://ionicframework.com/docs/v2 / native / google-analytics / )进入我的应用程序,遵循本教程,因为文档实际上没有任何实现指令: https://www.thepolyglotdeveloper.com/2016/03/use-google-analytics -in-an-ionic-2-android-and-ios-app /

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错误:app / app.ts(21,14):错误TS2339:类型'Window'上不存在属性'analytics' 。

任何想法?

推荐答案

样本你正在使用的不是使用打字稿或离子原生模块

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

这是一个你可以看看的项目 https://github.com/aaronksaunders/GAProject

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

app.ts

从'ionic-native'导入{StatusBar,GoogleAnalytics};

你也应该这样访问模块

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 Analytics实施到Ionic 2时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆