Skip to content

Commit

Permalink
Merge pull request #252 from bottleboy/master
Browse files Browse the repository at this point in the history
added method setAllowIDFACollection
  • Loading branch information
victorsosa authored Jul 17, 2016
2 parents f67fd47 + 5e7c969 commit 87f2464
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions android/UniversalAnalyticsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class UniversalAnalyticsPlugin extends CordovaPlugin {
public static final String ADD_TRANSACTION = "addTransaction";
public static final String ADD_TRANSACTION_ITEM = "addTransactionItem";

public static final String SET_ALLOW_IDFA_COLLECTION = "setAllowIDFACollection";
public static final String SET_USER_ID = "setUserId";
public static final String SET_ANONYMIZE_IP = "setAnonymizeIp";
public static final String SET_APP_VERSION = "setAppVersion";
Expand Down Expand Up @@ -112,6 +113,8 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
callbackContext);
}
return true;
} else if (SET_ALLOW_IDFA_COLLECTION.equals(action)) {
this.setAllowIDFACollection(args.getBoolean(0), callbackContext);
} else if (SET_USER_ID.equals(action)) {
String userId = args.getString(0);
this.setUserId(userId, callbackContext);
Expand Down Expand Up @@ -331,6 +334,16 @@ private void addTransactionItem(String id, String name, String sku, String categ
}
}

private void setAllowIDFACollection(Boolean enable, CallbackContext callbackContext) {
if (! trackerStarted ) {
callbackContext.error("Tracker not started");
return;
}

tracker.enableAdvertisingIdCollection(enable);
callbackContext.success("Enable Advertising Id Collection: " + enable);
}

private void debugMode(CallbackContext callbackContext) {
GoogleAnalytics.getInstance(this.cordova.getActivity()).getLogger().setLogLevel(LogLevel.VERBOSE);

Expand Down
1 change: 1 addition & 0 deletions ios/UniversalAnalyticsPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}

- (void) startTrackerWithId: (CDVInvokedUrlCommand*)command;
- (void) setAllowIDFACollection: (CDVInvokedUrlCommand*) command;
- (void) setUserId: (CDVInvokedUrlCommand*)command;
- (void) setAppVersion: (CDVInvokedUrlCommand*)command;
- (void) debugMode: (CDVInvokedUrlCommand*)command;
Expand Down
13 changes: 13 additions & 0 deletions ios/UniversalAnalyticsPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ - (void) startTrackerWithId: (CDVInvokedUrlCommand*)command
/* NSLog(@"successfully started GAI tracker"); */
}

- (void) setAllowIDFACollection: (CDVInvokedUrlCommand*) command
{
CDVPluginResult* pluginResult = nil;
if ( ! _trackerStarted) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Tracker not started"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
tracker.allowIDFACollection = [[command argumentAtIndex:0 withDefault:@(NO)] boolValue];
}

- (void) addCustomDimensionsToTracker: (id<GAITracker>)tracker
{
if (_customDimensions) {
Expand Down
4 changes: 4 additions & 0 deletions www/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ UniversalAnalyticsPlugin.prototype.startTrackerWithId = function(id, success, er
cordova.exec(success, error, 'UniversalAnalytics', 'startTrackerWithId', [id]);
};

UniversalAnalyticsPlugin.prototype.setAllowIDFACollection = function(bool, success, error) {
cordova.exec(success, error, 'UniversalAnalytics', 'setAllowIDFACollection', [bool]);
};

UniversalAnalyticsPlugin.prototype.setUserId = function(id, success, error) {
cordova.exec(success, error, 'UniversalAnalytics', 'setUserId', [id]);
};
Expand Down

0 comments on commit 87f2464

Please sign in to comment.