【问题标题】:Angulartics and Google Analytics custom reportsAngulartics 和 Google Analytics 自定义报告
【发布时间】:2017-07-20 12:47:57
【问题描述】:

我正在尝试通过 angulartics 向 Google Analytics 发送自定义维度和指标,但报告每次都在特定点上失败。

我需要跟踪国家、页面、产品名称显示(不是在每个页面上)以及价格等一些指标。

这是我的模块和控制器中的代码:

angular.module('app', [
    'ngAnimate', 'ngRoute', 'ngSanitize', 'angular-growl', 'angulartics', 'angulartics.google.analytics',
    'LocalForageModule', 'pascalprecht.translate'
]);

这是我的配置:

app.config([
'$compileProvider', '$httpProvider', '$localForageProvider', '$routeProvider', '$translateProvider',
'$analyticsProvider', 'growlProvider',
function($compileProvider, $httpProvider, $localForageProvider, $routeProvider, $translateProvider, $analyticsProvider, growlProvider) {
    $compileProvider.debugInfoEnabled(configuration.angular.compileProvider.debugInfoEnabled);

    $analyticsProvider.virtualPageviews(false);

这里是我要跟踪数据的控制器示例

controllers.controller('ResultsController', [
'$localForage', '$scope', '$timeout', '$translate', '$analytics', '$rootScope', '$location', '$window',
function($localForage, $scope, $timeout, $translate, $analytics, $rootScope, $location, $window) {
    var logger = log4javascript.getLogger('Results');

$rootScope.$on('$routeChangeSuccess', function () {

        console.log('Route Changed: ' + $location.url());

        $window.ga('send', {
            'hitType': 'pageview',
            'dimension4' : '',
            'page' : $location.url()
        });
    });

这个控制器,关联到 results.html 页面,理论上将维度 4 发送为空(维度 4 是产品名称)。此页面显示产品列表,我让用户必须选择一个。

问题是当用户选择产品并进入产品/ID 页面时。

$rootScope.$on('$routeChangeSuccess', function () {

      console.log('Route Changed: ' + $location.url());

      $window.ga('send', {
            'hitType': 'pageview',
            'dimension4' : data.product.upsPn,
            'page' : $location.url()
      });
 });

路线已更改,此时我想发送用户显示的产品名称(维度 4)。

当我查看 Google Analytics 管理页面上的自定义报告时,页面 products/id 与产品名称相关联,但如果用户在 /products/id 之后访问页面 /contact-us,那么我的自定义报告将显示一行:

country code         page             product name
FR                   /products/id     TOTO56000
FR                   /contact-us      TOTO56000

代替:

country code         page             product name
FR                   /products/id     TOTO56000
FR                   /contact-us      

有人有想法吗?问题可能来自 $localforage 吗?

【问题讨论】:

    标签: angularjs google-analytics angulartics


    【解决方案1】:

    对于那些需要做同样的自定义报告的人,这里是我的解决方案:

    Remove $window, $rootScope and $location from DI
    Remove the $rootScope.on and replace by
    
    $analytics.pageTrack('/results');
    
        $analytics.setUserProperties({
            dimension3: '/results'          
        });
    
        $analytics.setUserProperties({
            dimension4: ' '         
        });
    
        $analytics.setUserProperties({
            metric1: 0      
        });
    

    只需在您不想跟踪的页面上将指标和维度留空即可。 它解决了我的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多