Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavesh Sarwar committed Dec 26, 2023
2 parents 387a106 + e592989 commit 4875351
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 103 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.1.0",
"version": "1.2.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
8 changes: 7 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<source url="https://github.com/CocoaPods/Specs.git"/>
</config>
<pods use-frameworks="true">
<pod name="WebEngage" spec="~> 5.2.6" />
<pod name="WebEngage"/>
</pods>
</podspec>
</platform>
Expand All @@ -46,6 +46,8 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
</config-file>



<config-file target="AndroidManifest.xml" parent="/manifest/application">
<receiver
android:name="com.webengage.sdk.android.InstallTracker"
Expand All @@ -54,8 +56,12 @@
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<meta-data
android:name="com.webengage.child.io"
android:value="io:${io_version}" />
</config-file>

<resource-file src="src/android/version.properties" target="version.properties" />
<source-file src="src/android/WebEngagePlugin.java" target-dir="src/com/webengage/cordova/"/>
<framework src="src/android/WebEngagePlugin.gradle" custom="true" type="gradleReference"/>
</platform>
Expand Down
41 changes: 40 additions & 1 deletion src/android/WebEngagePlugin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,51 @@ buildscript {
}
}

android {
compileSdkVersion 33

defaultConfig {
minSdkVersion 21
targetSdkVersion 33
manifestPlaceholders.io_version = readVersion()
versionCode 2
versionName "1.2.0"
}
lintOptions {
abortOnError false
}
}

String readVersion() {
def version = new Properties()
def stream
try {
System.out.println("projectDir: " + projectDir)
println("projectDir: " + projectDir)
stream = new FileInputStream(new File(projectDir, './src/main/version.properties'))
version.load(stream)
} catch (FileNotFoundException ignore) {
} finally {
if (stream != null) stream.close()
}
// safety defaults in case file is missing
if(!version['major']) version['major'] = "1"
if(!version['minor']) version['minor'] = "0"
if(!version['patch']) version['patch'] = "0"
return "${version['major']}.${version['minor']}.${version['patch']}"
}


allprojects {
repositories {
mavenCentral();
jcenter();
}
}
dependencies {
api 'com.webengage:android-sdk:[3,)'
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'
}
30 changes: 29 additions & 1 deletion src/android/WebEngagePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.webengage.sdk.android.callbacks.InAppNotificationCallbacks;
import com.webengage.sdk.android.UserProfile;
import com.webengage.sdk.android.utils.Gender;
import com.webengage.sdk.android.Channel;


public class WebEngagePlugin extends CordovaPlugin implements PushNotificationCallbacks, InAppNotificationCallbacks {
Expand Down Expand Up @@ -141,6 +142,9 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
if (!androidConfig.isNull("pushProjectNumber")) {
configBuilder.setGCMProjectNumber(androidConfig.optString("pushProjectNumber"));
}
if(!androidConfig.isNull("autoGAIDTracking") && androidConfig.getBoolean("autoGAIDTracking") == false) {
configBuilder.setAutoGAIDTracking(false);
}
if (!androidConfig.isNull("locationTrackingStrategy")) {
if ("accuracy_best".equals(androidConfig.optString("locationTrackingStrategy"))) {
configBuilder.setLocationTrackingStrategy(LocationTrackingStrategy.ACCURACY_BEST);
Expand Down Expand Up @@ -267,6 +271,30 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
if (args.length() == 1 && args.get(0) instanceof Boolean) {
WebEngage.get().user().setDevicePushOptIn(args.getBoolean(0));
}
} else if ("setUserOptIn".equals(action)) {
if (args.length() == 2 && args.get(0) instanceof String && args.get(1) instanceof Boolean) {
String channel = args.getString(0);
boolean status = args.getBoolean(1);
if ("PUSH".equalsIgnoreCase(channel)) {
WebEngage.get().user().setOptIn(Channel.PUSH, status);
} else if ("SMS".equalsIgnoreCase(channel)) {
WebEngage.get().user().setOptIn(Channel.SMS, status);
} else if ("EMAIL".equalsIgnoreCase(channel)) {
WebEngage.get().user().setOptIn(Channel.EMAIL, status);
} else if ("IN_APP".equalsIgnoreCase(channel)) {
WebEngage.get().user().setOptIn(Channel.IN_APP, status);
} else if ("WHATSAPP".equalsIgnoreCase(channel)) {
WebEngage.get().user().setOptIn(Channel.WHATSAPP, status);
} else if ("VIBER".equalsIgnoreCase(channel)) {
WebEngage.get().user().setOptIn(Channel.VIBER, status);
}
else {
Logger.e("WebEngagePlugin", "Invalid channel: " + channel + ". Must be one of [push, sms, email, in_app, whatsapp, viber].");
}
}
}
else if("startGAIDTracking".equals(action)){
WebEngage.get().startGAIDTracking();
}

return true;
Expand Down Expand Up @@ -485,4 +513,4 @@ private static JSONObject mergeJson(JSONObject jsonObject1, JSONObject jsonObjec
}
return jsonObject1;
}
}
}
3 changes: 3 additions & 0 deletions src/android/version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
major=1
minor=2
patch=0
2 changes: 1 addition & 1 deletion src/ios/AppDelegate+WebEngagePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
+ (instancetype)sharedInstance;
- (BOOL)isFreshLaunch;
- (void)setFreshLaunch:(BOOL)freshLaunch;

- (void)presentInAppController;
@end
34 changes: 33 additions & 1 deletion src/ios/AppDelegate+WebEngagePlugin.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import <WebEngage/WebEngage.h>
#import "AppDelegate+WebEngagePlugin.h"

#import "MainViewController.h"
@interface WebEngagePluginUtils : NSObject

+ (instancetype)sharedInstance;
Expand Down Expand Up @@ -108,4 +108,36 @@ - (void)setFreshLaunch:(BOOL)freshLaunch {
[WebEngagePluginUtils sharedInstance].freshLaunch = freshLaunch;
}



- (void)presentInAppController {

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
UIWindow *window = [UIApplication sharedApplication].windows.firstObject;

if (window) {
WKWebView *lastSubview = (WKWebView *)window.subviews.lastObject;
UIViewController *topViewController = [self topViewController];

if ([lastSubview isKindOfClass:[WKWebView class]] && topViewController) {
[topViewController.view addSubview:lastSubview];
[topViewController.view bringSubviewToFront:lastSubview];
}
}
});

}

- (UIViewController *)topViewController {
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;

while (rootViewController.presentedViewController) {
rootViewController = rootViewController.presentedViewController;
}

return rootViewController;
}



@end
5 changes: 4 additions & 1 deletion src/ios/WebEngagePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

+ (WebEngagePlugin *)webEngagePlugin;

- (void)initialiseWEGVersions;

- (void)handlePushNotificationPendingDeepLinks;


Expand All @@ -22,7 +24,8 @@
- (void)logout:(CDVInvokedUrlCommand *)command;
- (void)track:(CDVInvokedUrlCommand *)command;
- (void)setAttribute:(CDVInvokedUrlCommand *)command;

- (void)setUserOptIn:(CDVInvokedUrlCommand *)command;
- (void)presentInAppController:(CDVInvokedUrlCommand *)command;
+ (void)evaluateJavaScript:(NSString *)script onWebView:(id)webView
completionHandler:(void (^ _Nullable)(NSString * _Nullable response, NSError * _Nullable error))completionHandler;
@end
69 changes: 65 additions & 4 deletions src/ios/WebEngagePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#define WE_COMPANY @"we_company"
#define WE_HASHED_EMAIL @"we_hashed_email"
#define WE_HASHED_PHONE @"we_hashed_phone"
#define PUSH @"push"
#define SMS @"sms"
#define EMAIL @"email"
#define IN_APP @"in_app"
#define WHATSAPP @"whatsapp"
#define VIBER @"viber"
#define WEGPluginVersion @"1.2.0"

@interface WebEngagePlugin()

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


[webEngagePlugin initialiseWEGVersions];

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
Expand All @@ -50,6 +59,11 @@ - (void)pluginInitialize {
self.birthDateFormatter = birthDateFormatter;
}

- (void) initialiseWEGVersions {
WegVersionKey key = WegVersionKeyIO;
[[WebEngage sharedInstance] setVersionForChildSDK:WEGPluginVersion forKey:key];
}

- (void)handlePushNotificationPendingDeepLinks {

AppDelegate* appDelegate = [AppDelegate sharedInstance];
Expand Down Expand Up @@ -223,16 +237,18 @@ - (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 navigatingToScreenWithName:screenName andData:[self convertISODateStringValuesToNSDate:screenData]];
[[WebEngage sharedInstance].analytics
trackEventWithName:screenName
andValue:[self convertISODateStringValuesToNSDate:screenData]];
} else {
[[WebEngage sharedInstance].analytics navigatingToScreenWithName:screenName];
[[WebEngage sharedInstance].analytics trackEventWithName:screenName];
}

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
Expand Down Expand Up @@ -448,4 +464,49 @@ + (void) evaluateJavaScript:(NSString *)script onWebView:(id)webView
}
}

- (void)setUserOptIn:(CDVInvokedUrlCommand *)command {
CDVPluginResult* pluginResult = nil;
BOOL status = 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];
}
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]) {
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelViber status:status];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

}

-(void)presentInAppController:(CDVInvokedUrlCommand *)command{
AppDelegate* appDelegate = [AppDelegate sharedInstance];
[appDelegate presentInAppController];
}


@end

Loading

0 comments on commit 4875351

Please sign in to comment.