From 777cc45fcbd4921fb6fe682786db08c1d1360635 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 17 Dec 2013 15:21:14 -0500 Subject: [PATCH] Add Google Analytics --- static/js/app.js | 2 +- static/lib/angulartics-google-analytics.js | 32 ++++++++++++++++++++++ templates/base.html | 14 ++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 static/lib/angulartics-google-analytics.js diff --git a/static/js/app.js b/static/js/app.js index f2b21c047..5df70ae0e 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -89,7 +89,7 @@ function getMarkedDown(string) { } // Start the application code itself. -quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'angulartics', 'angulartics.mixpanel', '$strap.directives', 'ngCookies'], function($provide) { +quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'angulartics', 'angulartics.mixpanel', 'angulartics.google.analytics', '$strap.directives', 'ngCookies'], function($provide) { $provide.factory('CookieService', ['$cookies', '$cookieStore', function($cookies, $cookieStore) { var cookieService = {}; cookieService.putPermanent = function(name, value) { diff --git a/static/lib/angulartics-google-analytics.js b/static/lib/angulartics-google-analytics.js new file mode 100644 index 000000000..bea8f5be4 --- /dev/null +++ b/static/lib/angulartics-google-analytics.js @@ -0,0 +1,32 @@ +/** + * @license Angulartics v0.8.5 + * (c) 2013 Luis Farzati http://luisfarzati.github.io/angulartics + * Universal Analytics update contributed by http://github.com/willmcclellan + * License: MIT + */ +(function(angular) { +'use strict'; + +/** + * @ngdoc overview + * @name angulartics.google.analytics + * Enables analytics support for Google Analytics (http://google.com/analytics) + */ +angular.module('angulartics.google.analytics', ['angulartics']) +.config(['$analyticsProvider', function ($analyticsProvider) { + + // GA already supports buffered invocations so we don't need + // to wrap these inside angulartics.waitForVendorApi + + $analyticsProvider.registerPageTrack(function (path) { + if (window._gaq) _gaq.push(['_trackPageview', path]); + if (window.ga) ga('send', 'pageview', path); + }); + + $analyticsProvider.registerEventTrack(function (action, properties) { + if (window._gaq) _gaq.push(['_trackEvent', properties.category, action, properties.label, properties.value]); + if (window.ga) ga('send', 'event', properties.category, action, properties.label, properties.value); + }); + +}]); +})(angular); \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index d16b7eefd..84425bb2a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -47,6 +47,7 @@ + @@ -72,6 +73,19 @@ var isProd = document.location.hostname === 'quay.io'; typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.track_charge people.clear_charges people.delete_user".split(" ");for(g=0;g + +