opensas opensas - 1 month ago 14
AngularJS Question

tracking href click with angular.js and google analytics

I have a web application which lets users download files. I dynamically generate the a


I've already seen this article explaining how to track routes with Angular:

How can I also track each file downloaded by the users?


You want to use ng-click for this. I would also use GA's event tracking to track this metric. Here's an example:

<a href="#" ng-click="logDownload()">Download</a>

$scope.logDownload = function () {
    $'send', 'event', 'Download', 'File Name'); //This would log a GA Event
    $location.path('your path to download the file'); //use this if you are linking to an angular route

Make use to inject $window and $location into your controller. Use $window to keep your code testable.