【问题标题】:ionic 1 integrate specific google analytics in specific screensionic 1 在特定屏幕中集成特定的谷歌分析
【发布时间】:2018-11-14 08:55:03
【问题描述】:

我想知道如何将ionic v1google analytics 集成在一起 并跟踪特定屏幕。

例如,我想拥有谷歌分析代码 UA-XXX 并跟踪特定导航(tab1、tab2 等)

【问题讨论】:

    标签: ionic-framework google-analytics event-tracking ionic-v1


    【解决方案1】:

    这个问题太广了,所以我不会介绍每一个细节,但这里是如何将 Google Analytics 集成到 ionic v1 应用的屏幕/选项卡的方法。

    因为这两件事很重要,第一是life cycle events of Ionic Views,第二是谷歌分析的cordova-plugin-google-analytics

    对于每个选项卡应该有一个控制器,并根据您的跟踪要求在该控制器中添加离子视图的生命周期事件。以下是可用的事件:

    首次视图初始化

    View 1 – loaded
    View 1 – beforeEnter
    View 1 – enter
    View 1 – afterEnter
    

    从一个视图到另一个视图的转换

    View 2 – loaded
    View 2 – beforeEnter
    View 1 – beforeLeave
    View 2 – enter
    View 1 – leave
    View 2 – afterEnter
    View 1 – afterLeave
    

    但我认为您可能只遇到以下两个事件,enterleave

    $scope.$on('$ionicView.enter', function(){
      // Your Google Analytic event code of your choice
      window.ga.startTrackerWithId('UA-XXXX-YY', 30);
    });
    
    $scope.$on('$ionicView.leave', function(){
      // Your Google Analytic event code of your choice
      window.ga.startTrackerWithId('UA-XXXX-YY', 30);
    });
    

    参考资料:

    【讨论】:

    • tqvm,我这个周末去看看
    • 我无法让它工作,请您检查代码和输出:dpaste.de/FT1P。 tqvm。它有这个错误:TypeError: Cannot read property 'startTrackerWithId' of undefined
    • @Axil 请仔细阅读文档。没有$cordovaGoogleAnalytics。为什么要添加这个,为什么要这样称呼$cordovaGoogleAnalytics.startTrackerWithId('UA-79154745-1');。再次检查文档并像这样调用window.ga.startTrackerWithId('UA--79154745-1', 30);
    • 我试着做 window.ga.startTrackerWithId('UA--79154745-1', 30);这是同样的问题 - 无法读取未定义的属性“startTrackerWithId”。你以前试过这个吗?另外我只尝试过浏览器,而不是设备上
    • 您是否满足先决条件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多