Daily Archives: 11.07.2013
Счётчик от Google Analytics в приложении AngularJS
index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<script type="text/javascript"> // TODO for mamba.ru only var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-...']); _gaq.push(['_setDomainName', '...']); (function () { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> |
app.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
var app = angular.module('my', []).config(); app.run(['$location', function($location) { $rootScope.$on('$locationChangeSuccess', function(e, next, current) { trackPageView(); }); function trackPageView() { if (window._gaq) { // it's optional window._gaq.push(['_setCustomVar', 1, // This custom var is set to slot #1. Required parameter. 'site_version', // The name acts as a kind of category for the user activity. Required parameter. 'my' // This value of the custom variable. Required parameter. ]); window._gaq.push(['_trackPageview'], $location.url()); } } }]); |
https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables http://davidwalsh.name/ajax-analytics