Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/plugins/googleAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ angular.module('ngCordova.plugins.googleAnalytics', [])

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

$window.analytics.addCustomDimension(key, value, function () {
if (isNaN(parsedKey)) {
d.reject('Parameter "key" must be an integer.');
}

$window.analytics.addCustomDimension(parsedKey, value, function () {
d.resolve();
}, function (error) {
d.reject(error);
Expand Down
8 changes: 4 additions & 4 deletions test/plugins/googleAnalytics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ describe('Service: $cordovaGoogleAnalytics', function() {
});

$cordovaGoogleAnalytics
.addCustomDimension('dimension1', 'Level 1')
.addCustomDimension(1, 'Level 1')
.then(function (response) {
result = 'success';
});

$rootScope.$digest();

expect(result).toBe('success');
expect($window.analytics.addCustomDimension.calls.argsFor(0)[0]).toBe('dimension1');
expect($window.analytics.addCustomDimension.calls.argsFor(0)[0]).toBe(1);
expect($window.analytics.addCustomDimension.calls.argsFor(0)[1]).toBe('Level 1');
});

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

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

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

$rootScope.$digest();

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

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