Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
MilindWebEngage committed Jul 6, 2024
2 parents 4875351 + 91a7da9 commit 9aab9f2
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 63 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-webengage",
"version": "1.2.0",
"version": "1.3.0",
"description": "WebEngage Plugin that integrates with WebEngage native SDKs(Android & iOS) to provide engagement capabilities for hybrid applications built with PhoneGap/Cordova",
"main": "WebEngagePlugin.js",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-webengage" version="1.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="cordova-plugin-webengage" version="1.3.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>WebEngagePlugin</name>
<js-module name="WebEngagePlugin" src="www/WebEngagePlugin.js">
<clobbers target="webengage" />
Expand Down
16 changes: 7 additions & 9 deletions src/android/WebEngagePlugin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ buildscript {
}

android {
compileSdkVersion 33
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33

defaultConfig {
minSdkVersion 21
targetSdkVersion 33
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
manifestPlaceholders.io_version = readVersion()
versionCode 2
versionName "1.2.0"
versionName "1.3.0"
}
lintOptions {
abortOnError false
Expand Down Expand Up @@ -47,9 +47,7 @@ allprojects {
}
}
dependencies {
implementation 'com.webengage:android-sdk:4.+'
implementation platform('com.google.firebase:firebase-bom:25.12.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging:20.2.1'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.webengage:android-sdk:4.+'
implementation platform('com.google.firebase:firebase-bom:33.1.1')
implementation 'com.google.firebase:firebase-messaging:24.0.0'
}
48 changes: 47 additions & 1 deletion src/android/WebEngagePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
import com.webengage.sdk.android.UserProfile;
import com.webengage.sdk.android.utils.Gender;
import com.webengage.sdk.android.Channel;
import com.webengage.sdk.android.callbacks.WESecurityCallback;


public class WebEngagePlugin extends CordovaPlugin implements PushNotificationCallbacks, InAppNotificationCallbacks {
public class WebEngagePlugin extends CordovaPlugin implements PushNotificationCallbacks, InAppNotificationCallbacks, WESecurityCallback {
private static final String TAG = "WebEngagePlugin";
private static CordovaWebView webView;

Expand Down Expand Up @@ -82,13 +83,23 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
Log.d(TAG, "Intialized");
}

@Override
public void onSecurityException(Map<String, Object> errorDetails) {
Log.e(TAG, "onSecurityException triggered ");
if (errorDetails != null) {
JSONObject errorObject = new JSONObject(errorDetails);
webView.sendJavascript("javascript:webengage.jwtManager.onCallbackReceived('expired', " + errorObject + ");");
}
}

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
Logger.v(TAG, "Execute: " + action);

if ("engage".equals(action)) {
WebEngage.registerPushNotificationCallback(this);
WebEngage.registerInAppNotificationCallback(this);
WebEngage.registerWESecurityCallback(this);

if (args != null && args.length() > 0 && args.get(0) instanceof JSONObject) {
// Dynamic config
Expand Down Expand Up @@ -261,9 +272,44 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
}
}
}
} else if("sendFcmToken".equals(action)){
if (args.length() > 0 && !args.isNull(0)) {
String fcmToken = null;
fcmToken = args.getString(0);
Logger.d(TAG, fcmToken + " " + fcmToken);
if (fcmToken != null) {
WebEngage.get().setRegistrationID(fcmToken);
}
}
} else if("onMessageReceived".equals(action)){
if (args.length() > 0 && !args.isNull(0)) {
Map<String, Object> payload = null;
if (args.length() == 1 && args.get(0) instanceof JSONObject) {
try {
payload = (Map<String, Object>) fromJSON(args.getJSONObject(1));
Map<String, String> data = (Map<String, String>) payload.get("data");
if(data != null) {
if(data.containsKey("source") && "webengage".equals(data.get("source"))) {
WebEngage.get().receive(data);
}
}
} catch (JSONException e) {
Logger.d(TAG, "Exception occurred onMessageReceived " + e.getMessage());
}
}

}
} else if ("login".equals(action)) {
if (args.length() == 1 && args.get(0) instanceof String) {
WebEngage.get().user().login(args.getString(0));
} else if (args.length() == 2 && args.get(0) instanceof String && (args.get(1) == null || "null".equals(args.getString(1)))) {
WebEngage.get().user().login(args.getString(0));
} else if (args.length() == 2 && args.get(0) instanceof String && args.get(1) instanceof String) {
WebEngage.get().user().login(args.getString(0), args.getString(1));
}
} else if("setSecureToken".equals(action)) {
if (args.length() == 2 && args.get(0) instanceof String && args.get(1) instanceof String) {
WebEngage.get().setSecurityToken(args.getString(0), args.getString(1));
}
} else if ("logout".equals(action)) {
WebEngage.get().user().logout();
Expand Down
2 changes: 1 addition & 1 deletion src/android/version.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
major=1
minor=2
minor=3
patch=0
1 change: 0 additions & 1 deletion src/ios/AppDelegate+WebEngagePlugin.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#import <WebEngage/WebEngage.h>
#import "AppDelegate+WebEngagePlugin.h"
#import "MainViewController.h"
@interface WebEngagePluginUtils : NSObject

+ (instancetype)sharedInstance;
Expand Down
3 changes: 2 additions & 1 deletion src/ios/WebEngagePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
- (void)initialiseWEGVersions;

- (void)handlePushNotificationPendingDeepLinks;

- (void)registerSDKSecurityCallback;

//Public APIs
//This one's for debugging
//-(void) pushReceived:(CDVInvokedUrlCommand*)command;

- (void)engage:(CDVInvokedUrlCommand *)command;
- (void)login:(CDVInvokedUrlCommand *)command;
- (void)setSecureToken:(CDVInvokedUrlCommand *)command;
- (void)logout:(CDVInvokedUrlCommand *)command;
- (void)track:(CDVInvokedUrlCommand *)command;
- (void)setAttribute:(CDVInvokedUrlCommand *)command;
Expand Down
101 changes: 67 additions & 34 deletions src/ios/WebEngagePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define IN_APP @"in_app"
#define WHATSAPP @"whatsapp"
#define VIBER @"viber"
#define WEGPluginVersion @"1.2.0"
#define WEGPluginVersion @"1.3.0"

@interface WebEngagePlugin()

Expand All @@ -41,7 +41,6 @@ - (void)pluginInitialize {
[super pluginInitialize];
webEngagePlugin = self;
self.pendingDeepLinkCallback = nil;

[webEngagePlugin initialiseWEGVersions];

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
Expand All @@ -55,7 +54,8 @@ - (void)pluginInitialize {
[birthDateFormatter setDateFormat:@"yyyy-MM-dd"];
[birthDateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[birthDateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"gb"]];


[webEngagePlugin registerSDKSecurityCallback];
self.birthDateFormatter = birthDateFormatter;
}

Expand Down Expand Up @@ -237,18 +237,16 @@ - (void)track:(CDVInvokedUrlCommand *)command {
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

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

if (screenName != nil && screenName.length > 0) {
id screenData = command.arguments && command.arguments.count>1 ? [command.arguments objectAtIndex:1] : nil;
if (screenData && [screenData isKindOfClass:[NSDictionary class]]) {
[[WebEngage sharedInstance].analytics
trackEventWithName:screenName
andValue:[self convertISODateStringValuesToNSDate:screenData]];
[[WebEngage sharedInstance].analytics navigatingToScreenWithName:screenName andData:[self convertISODateStringValuesToNSDate:screenData]];
} else {
[[WebEngage sharedInstance].analytics trackEventWithName:screenName];
[[WebEngage sharedInstance].analytics navigatingToScreenWithName:screenName];
}

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
Expand All @@ -270,9 +268,29 @@ - (void)screenNavigated:(CDVInvokedUrlCommand *)command {
- (void)login:(CDVInvokedUrlCommand *)command {
CDVPluginResult* pluginResult = nil;
NSString* userId = command.arguments && command.arguments.count>0 ? [command.arguments objectAtIndex:0] : nil;
NSString* jwtToken = command.arguments && command.arguments.count>0 ? [command.arguments objectAtIndex:1] : nil;

if ((userId != nil && userId != (id)[NSNull null] && userId.length > 0) && (jwtToken != nil && jwtToken != (id)[NSNull null] && jwtToken.length > 0)) {
[[WebEngage sharedInstance].user login:userId jwtToken:jwtToken];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else if (userId != nil && userId.length > 0) {
[[WebEngage sharedInstance].user login: userId];

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}

if (userId != nil && userId.length > 0) {
[[WebEngage sharedInstance].user loggedIn: userId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)setSecureToken:(CDVInvokedUrlCommand *)command{
CDVPluginResult* pluginResult = nil;
NSString* userId = command.arguments && command.arguments.count>0 ? [command.arguments objectAtIndex:0] : nil;
NSString* jwtToken = command.arguments && command.arguments.count>0 ? [command.arguments objectAtIndex:1] : nil;

if ((userId != nil && userId != (id)[NSNull null] && userId.length > 0) && (jwtToken != nil && jwtToken != (id)[NSNull null] && jwtToken.length > 0)) {
[[WebEngage sharedInstance].user setSecureToken:userId jwtToken:jwtToken];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
Expand Down Expand Up @@ -468,38 +486,41 @@ - (void)setUserOptIn:(CDVInvokedUrlCommand *)command {
CDVPluginResult* pluginResult = nil;
BOOL status = nil;

NSString* ch = command.arguments && command.arguments.count>0 ? [command.arguments objectAtIndex:0] : nil;
NSString* ch = command.arguments && command.arguments.count > 0 ? [command.arguments objectAtIndex:0] : nil;
if (command.arguments && command.arguments.count > 1) {
status = [[command.arguments objectAtIndex:1] boolValue];
}
if(status == nil && ch == nil){
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];

if (ch != nil) {
ch = [ch lowercaseString]; // Convert ch to lowercase
}
else
{if ([ch isEqualToString:PUSH]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelPush status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else if ([ch isEqualToString:SMS]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelSMS status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else if ([ch isEqualToString:EMAIL]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelEmail status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else if ([ch isEqualToString:IN_APP]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelInApp status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else if ([ch isEqualToString:WHATSAPP]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelWhatsapp status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
}else if ([ch isEqualToString:VIBER]) {

if (status == nil && ch == nil) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
} else {
if ([ch isEqualToString:[PUSH lowercaseString]]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelPush status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else if ([ch isEqualToString:[SMS lowercaseString]]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelSMS status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else if ([ch isEqualToString:[EMAIL lowercaseString]]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelEmail status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else if ([ch isEqualToString:[IN_APP lowercaseString]]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelInApp status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else if ([ch isEqualToString:[WHATSAPP lowercaseString]]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelWhatsapp status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else if ([ch isEqualToString:[VIBER lowercaseString]]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelViber status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

}

-(void)presentInAppController:(CDVInvokedUrlCommand *)command{
Expand All @@ -508,5 +529,17 @@ -(void)presentInAppController:(CDVInvokedUrlCommand *)command{
}


- (void) registerSDKSecurityCallback{
WEGJWTManager.shared.tokenInvalidatedCallback = ^(void){
NSDictionary *errorResponse = @{
@"errorResponse" : @"401"
};
NSData *data = [NSJSONSerialization dataWithJSONObject:errorResponse options:NSJSONWritingPrettyPrinted error:nil];
NSString *errorMessage = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[self.commandDelegate evalJs:
[NSString stringWithFormat: @"webengage.jwtManager.onCallbackReceived('expired', %@)",errorMessage]];
};
}

@end

Loading

0 comments on commit 9aab9f2

Please sign in to comment.