Skip to content

Commit

Permalink
Merge branch 'master' of github.com:danwilson/google-analytics-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
victorsosa committed Dec 7, 2016
2 parents 99b1fe5 + bce495d commit 497cd79
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 2 additions & 3 deletions browser/UniversalAnalyticsProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ UniversalAnalyticsProxy.prototype = {
});
},

_ensureEcommerce() {
_ensureEcommerce: function() {
if (this._isEcommerceRequired) return;
this._ga('require', 'ecommerce');
this._isEcommerceRequired = true;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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');
Expand Down
12 changes: 8 additions & 4 deletions ios/UniversalAnalyticsPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ - (void) setAllowIDFACollection: (CDVInvokedUrlCommand*) command
- (void) addCustomDimensionsToTracker: (id<GAITracker>)tracker
{
if (_customDimensions) {
for (NSNumber *key in _customDimensions) {
for (NSString *key in _customDimensions.allKeys) {
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:[key intValue]]
[tracker set:[GAIFields customDimensionForIndex:myKey.unsignedIntegerValue]
value:value];
}
}
Expand Down Expand Up @@ -159,14 +163,14 @@ - (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) {
_customDimensions = [[NSMutableDictionary alloc] init];
}

_customDimensions[key] = value;
_customDimensions[key.stringValue] = value;

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
Expand Down
3 changes: 3 additions & 0 deletions www/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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 not '" + typeof key + "'");
}
cordova.exec(success, error, 'UniversalAnalytics', 'addCustomDimension', [key, value]);
};

Expand Down

0 comments on commit 497cd79

Please sign in to comment.