【问题标题】:Tracking all screens using Google Analytics in Ionic 3 project在 Ionic 3 项目中使用 Google Analytics 跟踪所有屏幕
【发布时间】:2018-02-26 07:13:32
【问题描述】:

我正在完成 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)
        });
      });
    });
  }

【问题讨论】:

  • 您是否已经有一个用于初始化谷歌分析插件的服务?如果是这样,您能否将其添加到您的问题中?这样我就可以使用该代码并添加答案:)
  • @sebaferreras 我更新了问题以包含代码
  • 好的,所以看起来只是将它添加到 app.module.ts 文件是不够的。当我在每一页上初始化它时,我似乎得到了更好的结果。不过我仍在测试中

标签: ionic-framework ionic2 ionic3


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2013-09-15
    相关资源
    最近更新 更多