Skip to content

Commit 387a106

Browse files
Merge pull request #15 from WebEngage/develop
v1.1.0
2 parents a25f3ea + 6ce61cd commit 387a106

File tree

5 files changed

+47
-32
lines changed

5 files changed

+47
-32
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-webengage",
3-
"version": "1.0.5",
3+
"version": "1.1.0",
44
"description": "WebEngage Plugin that integrates with WebEngage native SDKs(Android & iOS) to provide engagement capabilities for hybrid applications built with PhoneGap/Cordova",
55
"main": "WebEngagePlugin.js",
66
"dependencies": {

src/android/WebEngagePlugin.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ allprojects {
1212
}
1313
}
1414
dependencies {
15-
implementation 'com.webengage:android-sdk:3.18+'
16-
implementation 'com.google.android.gms:play-services-location:10+'
15+
api 'com.webengage:android-sdk:[3,)'
1716
}

src/android/WebEngagePlugin.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@
3636
import com.webengage.sdk.android.actions.render.PushNotificationData;
3737
import com.webengage.sdk.android.actions.render.InAppNotificationData;
3838
import com.webengage.sdk.android.callbacks.InAppNotificationCallbacks;
39-
import com.webengage.sdk.android.callbacks.LifeCycleCallbacks;
4039
import com.webengage.sdk.android.UserProfile;
4140
import com.webengage.sdk.android.utils.Gender;
4241

4342

44-
public class WebEngagePlugin extends CordovaPlugin implements PushNotificationCallbacks, InAppNotificationCallbacks, LifeCycleCallbacks {
43+
public class WebEngagePlugin extends CordovaPlugin implements PushNotificationCallbacks, InAppNotificationCallbacks {
4544
private static final String TAG = "WebEngagePlugin";
4645
private static CordovaWebView webView;
4746

@@ -89,7 +88,6 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
8988
if ("engage".equals(action)) {
9089
WebEngage.registerPushNotificationCallback(this);
9190
WebEngage.registerInAppNotificationCallback(this);
92-
WebEngage.registerLifeCycleCallback(this);
9391

9492
if (args != null && args.length() > 0 && args.get(0) instanceof JSONObject) {
9593
// Dynamic config
@@ -265,6 +263,10 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
265263
}
266264
} else if ("logout".equals(action)) {
267265
WebEngage.get().user().logout();
266+
} else if ("setDevicePushOptIn".equals(action)) {
267+
if (args.length() == 1 && args.get(0) instanceof Boolean) {
268+
WebEngage.get().user().setDevicePushOptIn(args.getBoolean(0));
269+
}
268270
}
269271

270272
return true;
@@ -336,10 +338,21 @@ public PushNotificationData onPushNotificationReceived(Context context, PushNoti
336338
return notificationData;
337339
}
338340

339-
public static void handlePushClick(String uri, Bundle data) {
341+
public static void handlePushClick(String uri, Bundle customData) {
340342
IS_PUSH_CALLBACK_PENDING = true;
341343
PENDING_PUSH_URI = uri;
342-
PENDING_PUSH_CUSTOM_DATA = bundleToJson(data);
344+
JSONObject data = bundleToJson(customData);
345+
JSONObject pushPayload = null;
346+
try {
347+
if (customData != null && customData.containsKey("we_pushPayload")) {
348+
pushPayload = new JSONObject(customData.getString("we_pushPayload"));
349+
data.remove("we_pushPayload");
350+
mergeJson(data, pushPayload);
351+
}
352+
} catch (JSONException e) {
353+
Logger.e(TAG, "error merging json");
354+
}
355+
PENDING_PUSH_CUSTOM_DATA = data;
343356
Logger.d(TAG, "handlePushClick invoked");
344357
}
345358

@@ -354,6 +367,12 @@ public void onPushNotificationShown(Context context, PushNotificationData notifi
354367
public boolean onPushNotificationClicked(Context context, PushNotificationData notificationData) {
355368
String uri = notificationData.getPrimeCallToAction().getAction();
356369
JSONObject customData = bundleToJson(notificationData.getCustomData());
370+
try {
371+
customData = mergeJson(bundleToJson(notificationData.getCustomData()), notificationData.getPushPayloadJSON());
372+
} catch (JSONException e) {
373+
e.printStackTrace();
374+
Logger.e(TAG, "Exception while merging JSON");
375+
}
357376
webView.sendJavascript("javascript:webengage.push.onCallbackReceived( 'click', '" + uri + "'," + customData + ");");
358377
return false;
359378
}
@@ -362,6 +381,12 @@ public boolean onPushNotificationClicked(Context context, PushNotificationData n
362381
public boolean onPushNotificationActionClicked(Context context, PushNotificationData notificationData, String buttonID) {
363382
String uri = notificationData.getCallToActionById(buttonID).getAction();
364383
JSONObject customData = bundleToJson(notificationData.getCustomData());
384+
try {
385+
customData = mergeJson(bundleToJson(notificationData.getCustomData()), notificationData.getPushPayloadJSON());
386+
} catch (JSONException e) {
387+
e.printStackTrace();
388+
Logger.e(TAG, "Exception while merging JSON");
389+
}
365390
webView.sendJavascript("javascript:webengage.push.onCallbackReceived( 'click', '" + uri + "'," + customData + ");");
366391
return false;
367392
}
@@ -396,25 +421,6 @@ public boolean onInAppNotificationClicked(Context context, InAppNotificationData
396421
return false;
397422
}
398423

399-
@Override
400-
public void onGCMRegistered(Context context, String regID) {
401-
Logger.d(TAG, regID);
402-
}
403-
404-
@Override
405-
public void onGCMMessageReceived(Context context, Intent intent) {
406-
Logger.d(TAG, intent.getExtras().toString());
407-
}
408-
409-
@Override
410-
public void onAppInstalled(Context context, Intent intent) {
411-
Logger.d(TAG + "Install Referrer", intent.getExtras().getString("referrer"));
412-
}
413-
414-
@Override
415-
public void onAppUpgraded(Context context, int oldVersion, int newVersion) {
416-
}
417-
418424
private static JSONObject bundleToJson(Bundle bundle) {
419425
if (bundle != null) {
420426
JSONObject result = new JSONObject();
@@ -472,4 +478,11 @@ private List<Object> toList(JSONArray jsonArray) throws JSONException {
472478
return list;
473479
}
474480

481+
private static JSONObject mergeJson(JSONObject jsonObject1, JSONObject jsonObject2) throws JSONException {
482+
for (Iterator<String> it = jsonObject2.keys(); it.hasNext(); ) {
483+
String key = it.next();
484+
jsonObject1.put(key, jsonObject2.get(key));
485+
}
486+
return jsonObject1;
487+
}
475488
}

src/ios/WebEngagePlugin.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,16 @@ - (void)track:(CDVInvokedUrlCommand *)command {
223223
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
224224
}
225225

226-
- (void)screenNavigated:(CDVInvokedUrlCommand *)command {
226+
- (void)screenNavigated:(CDVInvokedUrlCommand *)command {
227227
CDVPluginResult* pluginResult = nil;
228228
NSString *screenName = command.arguments && command.arguments.count>0 ? [command.arguments objectAtIndex:0] : nil;
229229

230230
if (screenName != nil && screenName.length > 0) {
231231
id screenData = command.arguments && command.arguments.count>1 ? [command.arguments objectAtIndex:1] : nil;
232232
if (screenData && [screenData isKindOfClass:[NSDictionary class]]) {
233-
[[WebEngage sharedInstance].analytics
234-
trackEventWithName:screenName
235-
andValue:[self convertISODateStringValuesToNSDate:screenData]];
233+
[[WebEngage sharedInstance].analytics navigatingToScreenWithName:screenName andData:[self convertISODateStringValuesToNSDate:screenData]];
236234
} else {
237-
[[WebEngage sharedInstance].analytics trackEventWithName:screenName];
235+
[[WebEngage sharedInstance].analytics navigatingToScreenWithName:screenName];
238236
}
239237

240238
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];

www/WebEngagePlugin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ WebEngageUserChannel.prototype.setAttribute = function(key, value) {
136136
}
137137
};
138138

139+
140+
WebEngageUserChannel.prototype.setDevicePushOptIn = function(optIn) {
141+
exec(null, null, "WebEngagePlugin", "setDevicePushOptIn", [optIn]);
142+
};
143+
139144
function isValidJavascriptObject(val) {
140145
return val !== undefined && val != null && typeof val === 'object'
141146
&& Object.prototype.toString.call(val) === '[object Object]';

0 commit comments

Comments
 (0)