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

[fixes #55] added support for enableAdvertisingIdCollection(boolean) #63

Closed
Closed
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
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
15 changes: 15 additions & 0 deletions android/UniversalAnalyticsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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 Boolean trackerStarted = false;
public Boolean debugModeEnabled = false;
Expand Down Expand Up @@ -103,6 +104,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
this.setUserId(userId, callbackContext);
} else if (DEBUG_MODE.equals(action)) {
this.debugMode(callbackContext);
} else if(ENABLE_AD_ID_COLLECTION.equals(action)) {
Boolean isEnabled = args.getBoolean(0);
this.enableAdIdCollection(isEnabled, callbackContext);
}
return false;
}
Expand Down Expand Up @@ -272,4 +276,15 @@ private void setUserId(String userId, CallbackContext callbackContext) {
tracker.set("&uid", userId);
callbackContext.success("Set user id" + userId);
}

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

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 @@ -14,6 +14,7 @@
- (void) startTrackerWithId: (CDVInvokedUrlCommand*)command;
- (void) setUserId: (CDVInvokedUrlCommand*)command;
- (void) debugMode: (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) addCustomDimension: (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