Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added method setAllowIDFACollection #252

Merged
merged 2 commits into from
Jul 17, 2016
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
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_APP_VERSION = "setAppVersion";
public static final String DEBUG_MODE = "debugMode";
Expand Down Expand Up @@ -111,6 +112,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 @@ -327,6 +330,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