Skip to content

Commit

Permalink
fix issue danwilson#274 startTrackerWithId() is using runInBackground
Browse files Browse the repository at this point in the history
  • Loading branch information
victorsosa committed Aug 8, 2016
1 parent 58b01fc commit a98a733
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
40 changes: 22 additions & 18 deletions ios/UniversalAnalyticsPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ - (void) pluginInitialize

- (void) startTrackerWithId: (CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = nil;
NSString* accountId = [command.arguments objectAtIndex:0];
[self.commandDelegate runInBackground:^{
CDVPluginResult* pluginResult = nil;
NSString* accountId = [command.arguments objectAtIndex:0];

[GAI sharedInstance].dispatchInterval = 10;
[GAI sharedInstance].dispatchInterval = 10;

[[GAI sharedInstance] trackerWithTrackingId:accountId];
[[GAI sharedInstance] trackerWithTrackingId:accountId];

_trackerStarted = true;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
_trackerStarted = true;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
/* NSLog(@"successfully started GAI tracker"); */
}

Expand Down Expand Up @@ -159,22 +161,24 @@ - (void) trackMetric: (CDVInvokedUrlCommand*)command
return;
}

NSNumber *key = nil;
NSNumber *value = nil;
[self.commandDelegate runInBackground:^{
NSNumber *key = nil;
NSNumber *value = nil;

if ([command.arguments count] > 0)
key = [command.arguments objectAtIndex:0];
if ([command.arguments count] > 0)
key = [command.arguments objectAtIndex:0];

if ([command.arguments count] > 1)
value = [command.arguments objectAtIndex:1];
if ([command.arguments count] > 1)
value = [command.arguments objectAtIndex:1];

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

[tracker set:[GAIFields customMetricForIndex:key]
value:[[NSNumber numberWithInt:value] stringValue]];
[tracker set:[GAIFields customMetricForIndex:key]
value:[[NSNumber numberWithInt:value] stringValue]];

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

- (void) trackEvent: (CDVInvokedUrlCommand*)command
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-google-analytics",
"version": "1.5.4",
"version": "1.5.5",
"description": "Google Universal Analytics Plugin",
"cordova": {
"id": "cordova-plugin-google-analytics",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-google-analytics"
version="1.5.4">
version="1.5.5">
<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
Expand Down

0 comments on commit a98a733

Please sign in to comment.