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

Commit 7d1c506

Browse files
vitaliy-bobrovgortok
authored andcommitted
Issue #1228 - google analytics (#1247)
* Add key param check * Tests fix * Tests fix
1 parent de9e36a commit 7d1c506

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/plugins/googleAnalytics.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,13 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
5656

5757
addCustomDimension: function (key, value) {
5858
var d = $q.defer();
59+
var parsedKey = parseInt(key, 10);
5960

60-
$window.analytics.addCustomDimension(key, value, function () {
61+
if (isNaN(parsedKey)) {
62+
d.reject('Parameter "key" must be an integer.');
63+
}
64+
65+
$window.analytics.addCustomDimension(parsedKey, value, function () {
6166
d.resolve();
6267
}, function (error) {
6368
d.reject(error);

test/plugins/googleAnalytics.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ describe('Service: $cordovaGoogleAnalytics', function() {
192192
});
193193

194194
$cordovaGoogleAnalytics
195-
.addCustomDimension('dimension1', 'Level 1')
195+
.addCustomDimension(1, 'Level 1')
196196
.then(function (response) {
197197
result = 'success';
198198
});
199199

200200
$rootScope.$digest();
201201

202202
expect(result).toBe('success');
203-
expect($window.analytics.addCustomDimension.calls.argsFor(0)[0]).toBe('dimension1');
203+
expect($window.analytics.addCustomDimension.calls.argsFor(0)[0]).toBe(1);
204204
expect($window.analytics.addCustomDimension.calls.argsFor(0)[1]).toBe('Level 1');
205205
});
206206

@@ -210,7 +210,7 @@ describe('Service: $cordovaGoogleAnalytics', function() {
210210

211211
spyOn($window.analytics, 'addCustomDimension')
212212
.and.callFake(function (key, value, successCb, errorCb) {
213-
errorCb('Expected one non-empty string argument');
213+
errorCb('Parameter "key" must be an integer.');
214214
});
215215

216216
$cordovaGoogleAnalytics.addCustomDimension()
@@ -220,7 +220,7 @@ describe('Service: $cordovaGoogleAnalytics', function() {
220220

221221
$rootScope.$digest();
222222

223-
expect(result).toBe('Expected one non-empty string argument');
223+
expect(result).toBe('Parameter "key" must be an integer.');
224224
});
225225

226226
it('should call $window\'s analytics.trackEvent method', function() {

0 commit comments

Comments
 (0)