Google Analytics事件中的AngularJS表达式

时间:2022-12-04 15:20:06

I would like to add some google analytics events to items inside my ng-repeat. The events fire, i can seen them in the real time event overview, however i get it like this on GA (the actual expression):

我想在我的ng-repeat中添加一些谷歌分析事件。事件发生了,我可以在实时事件概述中看到它们,但是我在GA上得到它(实际表达式):

Event Category / Event Action / Event Label
Click CD Details / {{cd.cdname}} / {{cd.code}}

事件类别/事件操作/事件标签单击CD详细信息/ {{cd.cdname}} / {{cd.code}}

Now this is the string i use:

现在这是我使用的字符串:

ga('send', 'event', 'Click CD details', '{{cd.cdname}}', '{{cd.code})';

How would i be able to change this so GA and get the right information?

我怎样才能改变这个GA并获得正确的信息?

1 个解决方案

#1


0  

UPDATE:

I took a deeper look on this one.

我深入研究了这一个。

It seems like GA is out of the scope so AngularJS can't work inside it. If you don't want to use Angularytics, you should include it in your app.

似乎GA不在范围内,因此AngularJS无法在其中工作。如果您不想使用Angularytics,则应将其包含在您的应用中。

I assume it's a click event, but you can take it anywhere you want.

我认为这是一个点击事件,但你可以把它带到你想要的任何地方。

<body ng-app="windowExample">
  <script>
  angular.module('windowExample', [])
    .controller('ExampleController', ['$scope', '$window', function($scope, $window) {
      $scope.greeting = 'Hello, World!';
      $scope.doGreeting = function(greeting) {
        $window.alert(greeting);
        $window.ga('send', 'event', 'alert box event', 'click', greeting)
      };
    }]);
</script>
<div ng-controller="ExampleController">
  <input type="text" ng-model="greeting" aria-label="greeting" />
  <button ng-click="doGreeting(greeting)">ALERT</button>
</div>
</body>

This example is using Angular's documentation example.

此示例使用Angular的文档示例。

#1


0  

UPDATE:

I took a deeper look on this one.

我深入研究了这一个。

It seems like GA is out of the scope so AngularJS can't work inside it. If you don't want to use Angularytics, you should include it in your app.

似乎GA不在范围内,因此AngularJS无法在其中工作。如果您不想使用Angularytics,则应将其包含在您的应用中。

I assume it's a click event, but you can take it anywhere you want.

我认为这是一个点击事件,但你可以把它带到你想要的任何地方。

<body ng-app="windowExample">
  <script>
  angular.module('windowExample', [])
    .controller('ExampleController', ['$scope', '$window', function($scope, $window) {
      $scope.greeting = 'Hello, World!';
      $scope.doGreeting = function(greeting) {
        $window.alert(greeting);
        $window.ga('send', 'event', 'alert box event', 'click', greeting)
      };
    }]);
</script>
<div ng-controller="ExampleController">
  <input type="text" ng-model="greeting" aria-label="greeting" />
  <button ng-click="doGreeting(greeting)">ALERT</button>
</div>
</body>

This example is using Angular's documentation example.

此示例使用Angular的文档示例。