Skip to content

Commit

Permalink
[fixes danwilson#55] added support for enableAdvertisingIdCollection(…
Browse files Browse the repository at this point in the history
…boolean) to support display advertisement features

Conflicts:
	android/UniversalAnalyticsPlugin.java
	ios/UniversalAnalyticsPlugin.h
	ios/UniversalAnalyticsPlugin.m
  • Loading branch information
mediavrog authored and snakehopper committed Mar 12, 2016
1 parent 6e90154 commit 3280812
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.DS_Store
.DS_Store

# IDE
.idea
*.iml
21 changes: 18 additions & 3 deletions android/UniversalAnalyticsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class UniversalAnalyticsPlugin extends CordovaPlugin {

public static final String SET_USER_ID = "setUserId";
public static final String DEBUG_MODE = "debugMode";
public static final String ENABLE_AD_ID_COLLECTION = "enableAdvertisingIdCollection";
public static final String ENABLE_UNCAUGHT_EXCEPTION_REPORTING = "enableUncaughtExceptionReporting";

public Boolean trackerStarted = false;
Expand Down Expand Up @@ -108,6 +109,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (ENABLE_UNCAUGHT_EXCEPTION_REPORTING.equals(action)) {
Boolean enable = args.getBoolean(0);
this.enableUncaughtExceptionReporting(enable, callbackContext);
} else if(ENABLE_AD_ID_COLLECTION.equals(action)) {
Boolean isEnabled = args.getBoolean(0);
this.enableAdIdCollection(isEnabled, callbackContext);
}
return false;
}
Expand Down Expand Up @@ -311,14 +315,25 @@ private void setUserId(String userId, CallbackContext callbackContext) {
tracker.set("&uid", userId);
callbackContext.success("Set user id" + userId);
}

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

tracker.enableExceptionReporting(enable);
callbackContext.success((enable ? "Enabled" : "Disabled") + " uncaught exception reporting");
}

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

tracker.enableExceptionReporting(enable);
callbackContext.success((enable ? "Enabled" : "Disabled") + " uncaught exception reporting");
Tracker tracker = GoogleAnalytics.getInstance(this.cordova.getActivity()).getDefaultTracker();
tracker.enableAdvertisingIdCollection(isEnabled);
callbackContext.success((isEnabled ? "En" : "Dis")+ "abled ad id collection for Display Advertisement");
}
}
1 change: 1 addition & 0 deletions ios/UniversalAnalyticsPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- (void) setUserId: (CDVInvokedUrlCommand*)command;
- (void) debugMode: (CDVInvokedUrlCommand*)command;
- (void) enableUncaughtExceptionReporting: (CDVInvokedUrlCommand*)command;
- (void) enableAdvertisingIdCollection: (CDVInvokedUrlCommand*)command;
- (void) addCustomDimension: (CDVInvokedUrlCommand*)command;
- (void) trackEvent: (CDVInvokedUrlCommand*)command;
- (void) trackTiming: (CDVInvokedUrlCommand*)command;
Expand Down
18 changes: 18 additions & 0 deletions ios/UniversalAnalyticsPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ - (void) setUserId: (CDVInvokedUrlCommand*)command
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void) enableAdvertisingIdCollection: (CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = nil;
bool isEnabled = [[command.arguments objectAtIndex:0] boolValue];

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 = isEnabled ? YES : NO;

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

- (void) enableUncaughtExceptionReporting: (CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = nil;
Expand Down
8 changes: 8 additions & 0 deletions www/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ UniversalAnalyticsPlugin.prototype.debugMode = function(success, error) {
cordova.exec(success, error, 'UniversalAnalytics', 'debugMode', []);
};

/**
* Enable/Disable ad id collection to support display advertisement
* @see https://support.google.com/analytics/answer/2444872/
*/
UniversalAnalyticsPlugin.prototype.enableAdvertisingIdCollection = function(enabled, success, error) {
cordova.exec(success, error, 'UniversalAnalytics', 'enableAdvertisingIdCollection', [enabled]);
};

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

0 comments on commit 3280812

Please sign in to comment.