From 88b46ed5065e24ab2455423cd1308de6d0e69f8c Mon Sep 17 00:00:00 2001 From: Martin Moss Date: Mon, 28 Nov 2016 19:25:11 +0000 Subject: [PATCH 01/11] Check Value of custom dimension before calling cordova.exec --- www/analytics.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/www/analytics.js b/www/analytics.js index 5cd3782c..33ac613b 100644 --- a/www/analytics.js +++ b/www/analytics.js @@ -46,6 +46,9 @@ UniversalAnalyticsPlugin.prototype.trackView = function(screen, campaingUrl, new }; UniversalAnalyticsPlugin.prototype.addCustomDimension = function(key, value, success, error) { + if (typeof key !== "number") { + throw Error("key must be a valid integer"); + } cordova.exec(success, error, 'UniversalAnalytics', 'addCustomDimension', [key, value]); }; From d173ac6247ac1fa6e173d793b8088b5a54b570d7 Mon Sep 17 00:00:00 2001 From: Martin Moss Date: Mon, 28 Nov 2016 19:41:16 +0000 Subject: [PATCH 02/11] Add some debugging logging --- www/analytics.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/analytics.js b/www/analytics.js index 33ac613b..1daade9e 100644 --- a/www/analytics.js +++ b/www/analytics.js @@ -46,6 +46,7 @@ UniversalAnalyticsPlugin.prototype.trackView = function(screen, campaingUrl, new }; UniversalAnalyticsPlugin.prototype.addCustomDimension = function(key, value, success, error) { + console.log('[addCustomDimension]', typeof key, key, typeof values, value, ); if (typeof key !== "number") { throw Error("key must be a valid integer"); } From b734c1bc11420927cef828e78a9754449b8e9024 Mon Sep 17 00:00:00 2001 From: Martin Moss Date: Mon, 28 Nov 2016 20:33:23 +0000 Subject: [PATCH 03/11] Add checking for number type in addCustomDimension --- www/analytics.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/www/analytics.js b/www/analytics.js index 1daade9e..8fc10a5f 100644 --- a/www/analytics.js +++ b/www/analytics.js @@ -46,9 +46,8 @@ UniversalAnalyticsPlugin.prototype.trackView = function(screen, campaingUrl, new }; UniversalAnalyticsPlugin.prototype.addCustomDimension = function(key, value, success, error) { - console.log('[addCustomDimension]', typeof key, key, typeof values, value, ); if (typeof key !== "number") { - throw Error("key must be a valid integer"); + throw Error("key must be a valid integer not '" + typeof key + "'"); } cordova.exec(success, error, 'UniversalAnalytics', 'addCustomDimension', [key, value]); }; From 35134e0ea165e21167ac7db25e868016998c9c2b Mon Sep 17 00:00:00 2001 From: Martin Moss Date: Mon, 28 Nov 2016 21:18:43 +0000 Subject: [PATCH 04/11] Change addCustomDimension call NSNumber for key. aligned with Java function. --- ios/UniversalAnalyticsPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/UniversalAnalyticsPlugin.m b/ios/UniversalAnalyticsPlugin.m index dd4937e7..3156af05 100644 --- a/ios/UniversalAnalyticsPlugin.m +++ b/ios/UniversalAnalyticsPlugin.m @@ -159,7 +159,7 @@ - (void) enableUncaughtExceptionReporting: (CDVInvokedUrlCommand*)command - (void) addCustomDimension: (CDVInvokedUrlCommand*)command { CDVPluginResult* pluginResult = nil; - NSString* key = [command.arguments objectAtIndex:0]; + NSNumber* key = [command.arguments objectAtIndex:0]; NSString* value = [command.arguments objectAtIndex:1]; if ( ! _customDimensions) { From 172da83e977dc8f590188622a2d276657cb5f39a Mon Sep 17 00:00:00 2001 From: Martin Moss Date: Mon, 28 Nov 2016 22:21:06 +0000 Subject: [PATCH 05/11] NSString for dictionary, and convert back to NSNumber for SDK call --- ios/UniversalAnalyticsPlugin.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/UniversalAnalyticsPlugin.m b/ios/UniversalAnalyticsPlugin.m index 3156af05..681392fb 100644 --- a/ios/UniversalAnalyticsPlugin.m +++ b/ios/UniversalAnalyticsPlugin.m @@ -52,11 +52,11 @@ - (void) setAllowIDFACollection: (CDVInvokedUrlCommand*) command - (void) addCustomDimensionsToTracker: (id)tracker { if (_customDimensions) { - for (NSNumber *key in _customDimensions) { + for (NSString *key in _customDimensions) { NSString *value = [_customDimensions objectForKey:key]; /* NSLog(@"Setting tracker dimension slot %@: <%@>", key, value); */ - [tracker set:[GAIFields customDimensionForIndex:[key intValue]] + [tracker set:[GAIFields customDimensionForIndex:[key.intValue]] value:value]; } } @@ -166,7 +166,7 @@ - (void) addCustomDimension: (CDVInvokedUrlCommand*)command _customDimensions = [[NSMutableDictionary alloc] init]; } - _customDimensions[key] = value; + _customDimensions[key.stringValue] = value; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; From a633b72dae51d7c3bcb7908c3c4d53fe59f7c1a5 Mon Sep 17 00:00:00 2001 From: Martin Moss Date: Mon, 28 Nov 2016 22:44:30 +0000 Subject: [PATCH 06/11] add identifier --- ios/UniversalAnalyticsPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/UniversalAnalyticsPlugin.m b/ios/UniversalAnalyticsPlugin.m index 681392fb..5b9f00c8 100644 --- a/ios/UniversalAnalyticsPlugin.m +++ b/ios/UniversalAnalyticsPlugin.m @@ -56,7 +56,7 @@ - (void) addCustomDimensionsToTracker: (id)tracker NSString *value = [_customDimensions objectForKey:key]; /* NSLog(@"Setting tracker dimension slot %@: <%@>", key, value); */ - [tracker set:[GAIFields customDimensionForIndex:[key.intValue]] + [tracker set:[GAIFields customDimensionForIndex:[NSNumber key.intValue]] value:value]; } } From 19bf12ef85e5004afe5da81f89ccaa88d748bb64 Mon Sep 17 00:00:00 2001 From: Martin Moss Date: Mon, 28 Nov 2016 23:03:54 +0000 Subject: [PATCH 07/11] Add a Number formatter to convert string to Number --- ios/UniversalAnalyticsPlugin.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ios/UniversalAnalyticsPlugin.m b/ios/UniversalAnalyticsPlugin.m index 5b9f00c8..b71cc7c7 100644 --- a/ios/UniversalAnalyticsPlugin.m +++ b/ios/UniversalAnalyticsPlugin.m @@ -55,8 +55,12 @@ - (void) addCustomDimensionsToTracker: (id)tracker for (NSString *key in _customDimensions) { NSString *value = [_customDimensions objectForKey:key]; + NSNumberFormatter *f = [[NSNumberFormatter alloc] init]; + f.numberStyle = NSNumberFormatterDecimalStyle; + NSNumber *myKey = [f numberFromString:@"42"]; + /* NSLog(@"Setting tracker dimension slot %@: <%@>", key, value); */ - [tracker set:[GAIFields customDimensionForIndex:[NSNumber key.intValue]] + [tracker set:[GAIFields customDimensionForIndex:myKey] value:value]; } } From 4eccea833f400053af2242835bf65d380dafcfeb Mon Sep 17 00:00:00 2001 From: Caribe 1999 Date: Wed, 30 Nov 2016 19:49:33 +0100 Subject: [PATCH 08/11] Improve javascript compatibility There was some problems with olders Android and even with current iOS browsers. With a little more verbose syntax everything works fine. --- browser/UniversalAnalyticsProxy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/UniversalAnalyticsProxy.js b/browser/UniversalAnalyticsProxy.js index 42429b61..7cc76112 100644 --- a/browser/UniversalAnalyticsProxy.js +++ b/browser/UniversalAnalyticsProxy.js @@ -156,7 +156,7 @@ UniversalAnalyticsProxy.prototype = { }); }, - _ensureEcommerce() { + _ensureEcommerce: function() { if (this._isEcommerceRequired) return; this._ga('require', 'ecommerce'); this._isEcommerceRequired = true; @@ -185,7 +185,7 @@ function send(fn) { } function bindAll(that, names) { - names.forEach((name) => { + names.forEach(function(name) { if (typeof that[name] === 'function') { that[name] = that[name].bind(that); } From 0c0ba5f9b30c32c7fbdbadbc2489d8c398fb4e2c Mon Sep 17 00:00:00 2001 From: Martin Moss Date: Sat, 3 Dec 2016 23:23:38 +0000 Subject: [PATCH 09/11] iterate through keys, not the dict itself, possible fix for Mutate error --- ios/UniversalAnalyticsPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/UniversalAnalyticsPlugin.m b/ios/UniversalAnalyticsPlugin.m index b71cc7c7..0bd81643 100644 --- a/ios/UniversalAnalyticsPlugin.m +++ b/ios/UniversalAnalyticsPlugin.m @@ -52,7 +52,7 @@ - (void) setAllowIDFACollection: (CDVInvokedUrlCommand*) command - (void) addCustomDimensionsToTracker: (id)tracker { if (_customDimensions) { - for (NSString *key in _customDimensions) { + for (NSString *key in _customDimensions.allKeys) { NSString *value = [_customDimensions objectForKey:key]; NSNumberFormatter *f = [[NSNumberFormatter alloc] init]; From 278a3b5153bc1a65f0ecc48ad4da827906d1efc7 Mon Sep 17 00:00:00 2001 From: Martin Moss Date: Mon, 5 Dec 2016 09:54:06 +0000 Subject: [PATCH 10/11] Add/Remove Debug or minor tweak --- ios/UniversalAnalyticsPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/UniversalAnalyticsPlugin.m b/ios/UniversalAnalyticsPlugin.m index 0bd81643..80569964 100644 --- a/ios/UniversalAnalyticsPlugin.m +++ b/ios/UniversalAnalyticsPlugin.m @@ -60,7 +60,7 @@ - (void) addCustomDimensionsToTracker: (id)tracker NSNumber *myKey = [f numberFromString:@"42"]; /* NSLog(@"Setting tracker dimension slot %@: <%@>", key, value); */ - [tracker set:[GAIFields customDimensionForIndex:myKey] + [tracker set:[GAIFields customDimensionForIndex:myKey.unsignedIntegerValue] value:value]; } } From b2fd0b8f01563482af12b526e10df0ca5068fdf7 Mon Sep 17 00:00:00 2001 From: vince Date: Tue, 6 Dec 2016 13:31:30 +0100 Subject: [PATCH 11/11] fix: remove extra/undesired logging --- browser/UniversalAnalyticsProxy.js | 1 - 1 file changed, 1 deletion(-) diff --git a/browser/UniversalAnalyticsProxy.js b/browser/UniversalAnalyticsProxy.js index 7cc76112..5b40a29c 100644 --- a/browser/UniversalAnalyticsProxy.js +++ b/browser/UniversalAnalyticsProxy.js @@ -195,7 +195,6 @@ function bindAll(that, names) { function loadGoogleAnalytics(name) { window['GoogleAnalyticsObject'] = name; window[name] = window[name] || function () { - console.log(arguments); (window[name].q = window[name].q || []).push(arguments) }; var script = document.createElement('script');