ionic-framework - 在 Ionic 3 项目中使用 Google Analytics 跟踪所有屏幕

标签 ionic-framework ionic2 ionic3

我正在完成 Ionic 3 构建,并想将 Google Analytics 添加到其中。我成功添加了它,并且可以在 GA(实时)中看到该应用程序正在被使用,但是我想跟踪所有页面/屏幕浏览量。有谁知道这样做的方法吗?

我正在使用以下插件:https://github.com/danwilson/google-analytics-plugin

这是我用来初始化 GA 的代码

 initGoogleAnalytics() {
    var trackingId = 'UA-114720506-2';
    if (/(android)/i.test(navigator.userAgent)) { // for android 
      trackingId = 'UA-114720506-2';
    } else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { // for ios
      trackingId = 'UA-114720506-2';
    }
    //platform is injected in the Constructor
    this.platform.ready().then(() => {
      this.ga.debugMode();
      this.ga.startTrackerWithId(trackingId).then(()=> {
        console.log("GoogleAnalytics Initialized with ****** : " + trackingId);
        this.ga.trackView('schedule');
        this.ga.trackView('speakerList');
        this.ga.trackView('map');
        this.ga.trackView('social');
        this.ga.trackView('exhibitors');
        this.ga.enableUncaughtExceptionReporting(true)
        .then((_success) => {
          console.log("GoogleAnalytics enableUncaughtExceptionReporting Enabled.");
        }).catch((_error) => {
          console.log("GoogleAnalytics Error enableUncaughtExceptionReporting : " + _error)
        });
      });
    });
  }

最佳答案

基本上添加 GA 模块并在我想跟踪的每个页面上使用 ionViewDidEnter 进行初始化就达到了目的。

关于ionic-framework - 在 Ionic 3 项目中使用 Google Analytics 跟踪所有屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48974371/

相关文章:

javascript - Cordova : Can't add new page for my multi-page application

html - 麻烦堆叠 ionic 卡

css - Ionic 2 文本换行字体大小

javascript - Ionic 3 - 使用异步数据更新 Observable

angular - 如何减少 Ionic Cordova Project Start 持续时间?

datetime - ion-datetime 在 ionic2/ionic3 中,我想要弹出对话框显示当前日期,但 ion-datetime 不显示当前日期

ios - Cordova 中是否有关于应用程序即将卸载或更新的事件?

javascript - Angular 自定义验证器不反射(reflect) View 中的更改

angular - 在 FCMPlugin Ionic 2 中调用时 AlertController 不工作

testing - E2E 测试 Jasmine /Protractor 中的 Ionic 3 无限滚动模拟