Skip to content

Instantly share code, notes, and snippets.

@alduro
Last active December 23, 2015 19:49
Show Gist options
  • Save alduro/6684863 to your computer and use it in GitHub Desktop.
Save alduro/6684863 to your computer and use it in GitHub Desktop.
Changes for google analytics
in client/app/app.coffee add line 19
angular.module('app', [
'app.db',
'app.filters',
'app.directives',
'app.constants',
'app.modules.admin.menu',
'app.modules.admin.dashboard',
'app.modules.admin.users',
'app.modules.quote.edit',
'app.modules.quote.main',
'app.modules.quote.forms',
'app.modules.quote.tables',
'app.modules.quote.view',
'app.modules.quote.shipping',
'app.modules.request-form.request-form',
'infinite-scroll',
'analytics'
])
.config(['$locationProvider', ($locationProvider)->
$locationProvider.html5Mode true
])
.run(['$rootScope', ($rootScope)->
$rootScope.config = ready: false
$rootScope.apply = (fn)->
phase = @$$phase;
if phase == '$apply' or phase == '$digest'
@$eval(fn)
else
@$apply(fn)
])
and create a new file client/app/services.coffee
_gaq = _gaq || []
angular.module('analytics', [])
.run(['$http', ($http) ->
_gaq.push ['_setAccount', 'YOUR GOOGLE ACCOUNT']
_gaq.push(['_trackPageview'])
ga = document.createElement('script')
ga.type = 'text/javascript'
ga.async = true
ga.src = (if 'https:' == document.location.protocol then 'https://ssl' else 'http://www') + '.google-analytics.com/ga.js'
s = document.getElementsByTagName('script')[0]
s.parentNode.insertBefore(ga, s)
])
.service('analytics', ($rootScope, $window, $location, $routeParams) ->
$rootScope.$on('$viewContentLoaded', track);
track = () ->
path = convertPathToQueryString($location.path(), $routeParams)
$window._gaq.push(['_trackPageview', path])
convertPathToQueryString = (path, $routeParams) ->
for key in $routeParams
queryParam = '/' + $routeParams[key]
path = path.replace(queryParam, '')
querystring = decodeURIComponent($.param($routeParams))
if querystring == ''
path
path + "?" + querystring
)
then in client/app/request-form/request-form.coffee add analytics service in line 44
.controller('requestFormController', ['$scope', '$location', '$routeParams', 'db', 'quoteTypes', '$dialog', 'basketService', 'analytics', ($scope, $location, $routeParams, db, quoteTypes, $dialog, basketService, analytics)->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment