-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* Angular Google Analytics - Easy tracking for your AngularJS application | ||
* @version v0.0.10 - 2015-01-22 | ||
* @version v0.0.11 - 2015-02-26 | ||
* @link http://github.com/revolunet/angular-google-analytics | ||
* @author Julien Bouquillon <[email protected]> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
|
@@ -26,7 +26,8 @@ angular.module('angular-google-analytics', []) | |
ignoreFirstPageLoad = false, | ||
crossDomainLinker = false, | ||
crossLinkDomains, | ||
linkerConfig = {'allowLinker': true}; | ||
linkerConfig = {'allowLinker': true}, | ||
trackUrlParams = false; | ||
|
||
this._logs = []; | ||
|
||
|
@@ -110,14 +111,19 @@ angular.module('angular-google-analytics', []) | |
return true; | ||
}; | ||
|
||
this.trackUrlParams = function (val) { | ||
trackUrlParams = !!val; | ||
return true; | ||
}; | ||
|
||
/** | ||
* Public Service | ||
*/ | ||
this.$get = ['$document', '$location', '$log', '$rootScope', '$window', function ($document, $location, $log, $rootScope, $window) { | ||
var me = this; | ||
|
||
var getUrl = function () { | ||
var url = $location.path(); | ||
var url = trackUrlParams ? $location.url() : $location.path(); | ||
return removeRegExp ? url.replace(removeRegExp, '') : url; | ||
}; | ||
|
||
|
@@ -301,9 +307,10 @@ angular.module('angular-google-analytics', []) | |
https://developers.google.com/analytics/devguides/collection/analyticsjs/pages | ||
* @param url | ||
* @param title | ||
* @param custom | ||
* @private | ||
*/ | ||
this._trackPage = function (url, title) { | ||
this._trackPage = function (url, title, custom) { | ||
var that = this, args = arguments; | ||
url = url ? url : getUrl(); | ||
title = title ? title : $document[0].title; | ||
|
@@ -314,18 +321,19 @@ angular.module('angular-google-analytics', []) | |
that._log('_trackPageview', url, title, args); | ||
}); | ||
_analyticsJs(function () { | ||
var opt_fieldObject = { | ||
'page': trackPrefix + url, | ||
'title': title | ||
}; | ||
if (angular.isObject(custom)) { | ||
angular.extend(opt_fieldObject, custom); | ||
} | ||
if (angular.isArray(accountId)) { | ||
accountId.forEach(function (trackerObj) { | ||
$window.ga(_generateCommandName('send', trackerObj), 'pageview', { | ||
'page': trackPrefix + url, | ||
'title': title | ||
}); | ||
$window.ga(_generateCommandName('send', trackerObj), 'pageview', opt_fieldObject); | ||
}); | ||
} else { | ||
$window.ga('send', 'pageview', { | ||
'page': trackPrefix + url, | ||
'title': title | ||
}); | ||
$window.ga('send', 'pageview', opt_fieldObject); | ||
} | ||
that._log('pageview', url, title, args); | ||
}); | ||
|
@@ -340,23 +348,31 @@ angular.module('angular-google-analytics', []) | |
* @param label | ||
* @param value | ||
* @param noninteraction | ||
* @param custom | ||
* @private | ||
*/ | ||
this._trackEvent = function (category, action, label, value, noninteraction) { | ||
this._trackEvent = function (category, action, label, value, noninteraction, custom) { | ||
var that = this, args = arguments; | ||
_gaJs(function () { | ||
$window._gaq.push(['_trackEvent', category, action, label, value, !!noninteraction]); | ||
that._log('trackEvent', args); | ||
}); | ||
_analyticsJs(function () { | ||
var opt_fieldObject = {}; | ||
if (angular.isDefined(noninteraction)) { | ||
opt_fieldObject['nonInteraction'] = !!noninteraction; | ||
} | ||
if (angular.isObject(custom)) { | ||
angular.extend(opt_fieldObject, custom); | ||
} | ||
if (angular.isArray(accountId)) { | ||
accountId.forEach(function (trackerObj) { | ||
if (_checkOption('trackEvent', trackerObj)) { | ||
$window.ga(_generateCommandName('send', trackerObj), 'event', category, action, label, value); | ||
$window.ga(_generateCommandName('send', trackerObj), 'event', category, action, label, value, opt_fieldObject); | ||
} | ||
}); | ||
} else { | ||
$window.ga('send', 'event', category, action, label, value); | ||
$window.ga('send', 'event', category, action, label, value, opt_fieldObject); | ||
} | ||
that._log('event', args); | ||
}); | ||
|
@@ -759,11 +775,11 @@ angular.module('angular-google-analytics', []) | |
enhancedEcommerceEnabled: function () { | ||
return me._enhancedEcommerceEnabled(); | ||
}, | ||
trackPage: function (url, title) { | ||
me._trackPage(url, title); | ||
trackPage: function (url, title, custom) { | ||
me._trackPage(url, title, custom); | ||
}, | ||
trackEvent: function (category, action, label, value, noninteraction) { | ||
me._trackEvent(category, action, label, value, noninteraction); | ||
trackEvent: function (category, action, label, value, noninteraction, custom) { | ||
me._trackEvent(category, action, label, value, noninteraction, custom); | ||
}, | ||
addTrans: function (transactionId, affiliation, total, tax, shipping, city, state, country, currency) { | ||
me._addTrans(transactionId, affiliation, total, tax, shipping, city, state, country, currency); | ||
|
Oops, something went wrong.