diff --git a/README.md b/README.md index 0a210aa..b8650c0 100755 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ cordova plugin add cordova-plugin-mparticle **Install the SDK** using CocoaPods: ```bash -$ # Update your Podfile to depend on 'mParticle-Apple-SDK' version 7.2.0 or later +$ # Update your Podfile to depend on 'mParticle-Apple-SDK' version 8.5.2 or later $ pod install ``` diff --git a/plugin/src/android/build.gradle b/plugin/src/android/build.gradle index a41ba98..f9b8c68 100644 --- a/plugin/src/android/build.gradle +++ b/plugin/src/android/build.gradle @@ -21,5 +21,5 @@ dependencies { testCompile 'org.json:json:20080701' testCompile "org.mockito:mockito-core:1.+" provided 'org.apache.cordova:framework:7.1.0' - provided 'com.mparticle:android-core:5.16.5' + provided 'com.mparticle:android-core:5.24.0' } diff --git a/plugin/src/android/src/main/java/com/mparticle/cordova/MParticleCordovaPlugin.java b/plugin/src/android/src/main/java/com/mparticle/cordova/MParticleCordovaPlugin.java index b37d117..9707676 100644 --- a/plugin/src/android/src/main/java/com/mparticle/cordova/MParticleCordovaPlugin.java +++ b/plugin/src/android/src/main/java/com/mparticle/cordova/MParticleCordovaPlugin.java @@ -86,6 +86,14 @@ public void logEvent(final JSONArray args) throws JSONException { MParticle.getInstance().logEvent(event); } + public void logMPEvent(final JSONArray args) throws JSONException { + final JSONObject map = args.getJSONObject(0); + if (map != null) { + MPEvent event = ConvertMPEvent(map); + MParticle.getInstance().logEvent(event); + } + } + public void logCommerceEvent(final JSONArray args) throws JSONException { final JSONObject map = args.getJSONObject(0); if (map != null) { @@ -327,6 +335,41 @@ private static IdentityApiRequest ConvertIdentityAPIRequest(JSONObject map) thro return identityRequest.build(); } + private static MPEvent ConvertMPEvent(ReadableMap map) throws JSONException { + if ((map.hasKey("name")) && (map.hasKey("type"))) { + String name = map.getString("name"); + Integer type = map.getInt("type"); + MPEvent.Builder builder = new MPEvent.Builder(name, ConvertEventType(type)); + if (map.hasKey("category")) { + builder.category(map.getString("category")); + } + if (map.hasKey("duration")) { + builder.duration(map.getDouble("duration")); + } + if (map.hasKey("info")) { + ReadableMap customInfoMap = map.getMap("info"); + Map customInfo = ConvertStringMap(customInfoMap); + builder.info(customInfo); + } + if (map.hasKey("customFlags")) { + ReadableMap customFlagsMap = map.getMap("customFlags"); + Map customFlags = ConvertStringMap(customFlagsMap); + for (Map.Entry entry : customFlags.entrySet()) + { + builder.addCustomFlag(entry.getKey(), entry.getValue()); + } + } + + if (map.hasKey("shouldUploadEvent")) { + builder.shouldUploadEvent(map.getBoolean("shouldUploadEvent")); + } + + return builder.build(); + } + Log.e(LOG_TAG, "Invalid event:" + map.toString()); + return null; + } + private static CommerceEvent ConvertCommerceEvent(JSONObject map) throws JSONException { Boolean isProductAction = map.has("productActionType"); Boolean isPromotion = map.has("promotionActionType"); @@ -382,6 +425,10 @@ else if (isPromotion) { } } + if (map.hasKey("shouldUploadEvent")) { + builder.shouldUploadEvent(map.getBoolean("shouldUploadEvent")); + } + return builder.build(); } diff --git a/plugin/src/ios/CDVMParticle.m b/plugin/src/ios/CDVMParticle.m index f4a4017..eaf907c 100644 --- a/plugin/src/ios/CDVMParticle.m +++ b/plugin/src/ios/CDVMParticle.m @@ -19,13 +19,26 @@ - (void)logEvent:(CDVInvokedUrlCommand*)command { }]; } +- (void)logMPEvent:(CDVInvokedUrlCommand*)command { + [self.commandDelegate runInBackground:^{ + NSString *serializedEvent = [command.arguments objectAtIndex:0]; + + MPEvent *event = [CDVMParticle MPEvent:serializedEvent]; + + [[MParticle sharedInstance] logEvent:event]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; +} + - (void)logCommerceEvent:(CDVInvokedUrlCommand*)command { [self.commandDelegate runInBackground:^{ NSString *serializedCommerceEvent = [command.arguments objectAtIndex:0]; MPCommerceEvent *commerceEvent = [CDVMParticle MPCommerceEvent:serializedCommerceEvent]; - [[MParticle sharedInstance] logCommerceEvent:commerceEvent]; + [[MParticle sharedInstance] logEvent:commerceEvent]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; @@ -350,6 +363,9 @@ + (MPCommerceEvent *)MPCommerceEvent:(id)json { commerceEvent.checkoutStep = [json[@"checkoutStep"] intValue]; } commerceEvent.nonInteractive = [json[@"nonInteractive"] boolValue]; + if (json[@"shouldUploadEvent"] != nil) { + commerceEvent.shouldUploadEvent = [json[@"shouldUploadEvent"] boolValue]; + } NSMutableArray *products = [NSMutableArray array]; NSArray *jsonProducts = json[@"products"]; @@ -428,10 +444,13 @@ + (MPEvent *)MPEvent:(id)json { event.category = json[@"category"]; event.duration = json[@"duration"]; event.endTime = json[@"endTime"]; - event.info = json[@"info"]; + event.customAttributes = json[@"info"]; event.name = json[@"name"]; event.startTime = json[@"startTime"]; event.type = [json[@"type"] integerValue]; + if (json[@"shouldUploadEvent"] != nil) { + event.shouldUploadEvent = [json[@"shouldUploadEvent"] boolValue]; + } NSDictionary *jsonFlags = json[@"customFlags"]; for (NSString *key in jsonFlags) { diff --git a/plugin/www/mparticle.js b/plugin/www/mparticle.js index 96725a0..df0b2cb 100644 --- a/plugin/www/mparticle.js +++ b/plugin/www/mparticle.js @@ -93,6 +93,10 @@ var mparticle = { exec('logEvent', [eventName, type, attributes]) }, + logMPEvent: function (event) { + exec('logMPEvent', [event]) + }, + logCommerceEvent: function (commerceEvent) { exec('logCommerceEvent', [commerceEvent]) }, @@ -183,6 +187,45 @@ var mparticle = { } }, + Event: function () { + this.setCategory = function (category) { + this.category = category + return this + } + this.setDuration = function (duration) { + this.duration = duration + return this + } + this.setEndTime = function (endTime) { + this.endTime = endTime + return this + } + this.setInfo = function (info) { + this.info = info + return this + } + this.setName = function (name) { + this.name = name + return this + } + this.setStartTime = function (startTime) { + this.startTime = startTime + return this + } + this.setType = function (type) { + this.type = type + return this + } + this.setShouldUploadEvent = function (shouldUploadEvent) { + this.shouldUploadEvent = shouldUploadEvent + return this + } + this.setCustomFlags = function (customFlags) { + this.customFlags = customFlags + return this + } + }, + CommerceEvent: function () { this.setTransactionAttributes = function (transactionAttributes) { this.transactionAttributes = transactionAttributes @@ -253,6 +296,11 @@ var mparticle = { this.nonInteractive = nonInteractive return this } + + this.setShouldUploadEvent = function (shouldUploadEvent) { + this.shouldUploadEvent = shouldUploadEvent + return this + } }, User: function (userId) {