Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit 5cd6110

Browse files
gazaretgortok
authored andcommitted
Update google-analytics-plugin (#1309)
* Update google-analytics-plugin * add test * revert dist/* folders
1 parent 17c7152 commit 5cd6110

File tree

4 files changed

+374
-64
lines changed

4 files changed

+374
-64
lines changed

src/mocks/googleAnalytics.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ngCordovaMocks.factory('$cordovaGoogleAnalytics', ['$q', function ($q) {
1313
/**
1414
* @ngdoc property
1515
* @name throwsError
16-
* @propertyOf ngCordovaMocks.cordovaGeolocation
16+
* @propertyOf ngCordovaMocks.cordovaGoogleAnalytics
1717
*
1818
* @description
1919
* A flag that signals whether a promise should be rejected or not.
@@ -24,14 +24,19 @@ ngCordovaMocks.factory('$cordovaGoogleAnalytics', ['$q', function ($q) {
2424
var methodsName = [
2525
'startTrackerWithId',
2626
'setUserId',
27+
'setAppVersion',
2728
'debugMode',
2829
'trackView',
2930
'addCustomDimension',
3031
'trackEvent',
32+
'trackMetric',
3133
'trackException',
3234
'trackTiming',
3335
'addTransaction',
34-
'addTransactionItem'
36+
'addTransactionItem',
37+
'setAnonymizeIp',
38+
'setAllowIDFACollection',
39+
'enableUncaughtExceptionReporting'
3540
];
3641

3742
methodsName.forEach(function (funcName) {

src/plugins/googleAnalytics.js

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
99
startTrackerWithId: function (id) {
1010
var d = $q.defer();
1111

12-
$window.analytics.startTrackerWithId(id, function (response) {
12+
$window.ga.startTrackerWithId(id, function (response) {
1313
d.resolve(response);
1414
}, function (error) {
1515
d.reject(error);
@@ -21,7 +21,19 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
2121
setUserId: function (id) {
2222
var d = $q.defer();
2323

24-
$window.analytics.setUserId(id, function (response) {
24+
$window.ga.setUserId(id, function (response) {
25+
d.resolve(response);
26+
}, function (error) {
27+
d.reject(error);
28+
});
29+
30+
return d.promise;
31+
},
32+
33+
setAppVersion: function (version) {
34+
var d = $q.defer();
35+
36+
$window.ga.setAppVersion(version, function (response) {
2537
d.resolve(response);
2638
}, function (error) {
2739
d.reject(error);
@@ -33,7 +45,7 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
3345
debugMode: function () {
3446
var d = $q.defer();
3547

36-
$window.analytics.debugMode(function (response) {
48+
$window.ga.debugMode(function (response) {
3749
d.resolve(response);
3850
}, function () {
3951
d.reject();
@@ -45,7 +57,7 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
4557
trackView: function (screenName) {
4658
var d = $q.defer();
4759

48-
$window.analytics.trackView(screenName, function (response) {
60+
$window.ga.trackView(screenName, function (response) {
4961
d.resolve(response);
5062
}, function (error) {
5163
d.reject(error);
@@ -62,7 +74,7 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
6274
d.reject('Parameter "key" must be an integer.');
6375
}
6476

65-
$window.analytics.addCustomDimension(parsedKey, value, function () {
77+
$window.ga.addCustomDimension(parsedKey, value, function () {
6678
d.resolve();
6779
}, function (error) {
6880
d.reject(error);
@@ -74,7 +86,19 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
7486
trackEvent: function (category, action, label, value) {
7587
var d = $q.defer();
7688

77-
$window.analytics.trackEvent(category, action, label, value, function (response) {
89+
$window.ga.trackEvent(category, action, label, value, function (response) {
90+
d.resolve(response);
91+
}, function (error) {
92+
d.reject(error);
93+
});
94+
95+
return d.promise;
96+
},
97+
98+
trackMetric: function (key, value) {
99+
var d = $q.defer();
100+
101+
$window.ga.trackMetric(key, value, function (response) {
78102
d.resolve(response);
79103
}, function (error) {
80104
d.reject(error);
@@ -86,7 +110,7 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
86110
trackException: function (description, fatal) {
87111
var d = $q.defer();
88112

89-
$window.analytics.trackException(description, fatal, function (response) {
113+
$window.ga.trackException(description, fatal, function (response) {
90114
d.resolve(response);
91115
}, function (error) {
92116
d.reject(error);
@@ -98,7 +122,7 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
98122
trackTiming: function (category, milliseconds, variable, label) {
99123
var d = $q.defer();
100124

101-
$window.analytics.trackTiming(category, milliseconds, variable, label, function (response) {
125+
$window.ga.trackTiming(category, milliseconds, variable, label, function (response) {
102126
d.resolve(response);
103127
}, function (error) {
104128
d.reject(error);
@@ -110,7 +134,7 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
110134
addTransaction: function (transactionId, affiliation, revenue, tax, shipping, currencyCode) {
111135
var d = $q.defer();
112136

113-
$window.analytics.addTransaction(transactionId, affiliation, revenue, tax, shipping, currencyCode, function (response) {
137+
$window.ga.addTransaction(transactionId, affiliation, revenue, tax, shipping, currencyCode, function (response) {
114138
d.resolve(response);
115139
}, function (error) {
116140
d.reject(error);
@@ -122,7 +146,43 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
122146
addTransactionItem: function (transactionId, name, sku, category, price, quantity, currencyCode) {
123147
var d = $q.defer();
124148

125-
$window.analytics.addTransactionItem(transactionId, name, sku, category, price, quantity, currencyCode, function (response) {
149+
$window.ga.addTransactionItem(transactionId, name, sku, category, price, quantity, currencyCode, function (response) {
150+
d.resolve(response);
151+
}, function (error) {
152+
d.reject(error);
153+
});
154+
155+
return d.promise;
156+
},
157+
158+
setAnonymizeIp: function (anonymize) {
159+
var d = $q.defer();
160+
161+
$window.ga.setAnonymizeIp(anonymize, function (response) {
162+
d.resolve(response);
163+
}, function (error) {
164+
d.reject(error);
165+
});
166+
167+
return d.promise;
168+
},
169+
170+
setAllowIDFACollection: function (enable) {
171+
var d = $q.defer();
172+
173+
$window.ga.setAllowIDFACollection(enable, function (response) {
174+
d.resolve(response);
175+
}, function (error) {
176+
d.reject(error);
177+
});
178+
179+
return d.promise;
180+
},
181+
182+
enableUncaughtExceptionReporting: function (enable) {
183+
var d = $q.defer();
184+
185+
$window.ga.enableUncaughtExceptionReporting(enable, function (response) {
126186
d.resolve(response);
127187
}, function (error) {
128188
d.reject(error);

test/mocks/googleAnalytics.spec.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ describe('ngCordovaMocks', function() {
3131
$timeout.flush();
3232
};
3333

34-
it('should start tracker', function () {
34+
it('should start tracker', function() {
3535
testPromises('startTrackerWithId');
3636
});
3737

3838
it('should set User Id.', function() {
3939
testPromises('setUserId');
4040
});
4141

42+
it('should set App version', function() {
43+
testPromises('setAppVersion');
44+
});
45+
4246
it('should set debug mode.', function() {
4347
testPromises('debugMode');
4448
});
@@ -55,6 +59,10 @@ describe('ngCordovaMocks', function() {
5559
testPromises('trackEvent');
5660
});
5761

62+
it('should track metric', function() {
63+
testPromises('trackMetric');
64+
});
65+
5866
it('should track exception.', function() {
5967
testPromises('trackException');
6068
});
@@ -70,5 +78,17 @@ describe('ngCordovaMocks', function() {
7078
it('should add add a transaction item.', function() {
7179
testPromises('addTransactionItem');
7280
});
81+
82+
it('should set Anonymize Ip', function() {
83+
testPromises('setAnonymizeIp');
84+
});
85+
86+
it('should set Allow IDFA Collection', function() {
87+
testPromises('setAllowIDFACollection');
88+
});
89+
90+
it('should enable Uncaught Exception Reporting', function() {
91+
testPromises('enableUncaughtExceptionReporting');
92+
});
7393
});
7494
})

0 commit comments

Comments
 (0)