Skip to content

Commit 4875351

Browse files
author
Bhavesh Sarwar
committed
Merge branch 'release/1.2.0'
2 parents 387a106 + e592989 commit 4875351

10 files changed

+333
-103
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.1.0",
3+
"version": "1.2.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": {

plugin.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<source url="https://github.com/CocoaPods/Specs.git"/>
3131
</config>
3232
<pods use-frameworks="true">
33-
<pod name="WebEngage" spec="~> 5.2.6" />
33+
<pod name="WebEngage"/>
3434
</pods>
3535
</podspec>
3636
</platform>
@@ -46,6 +46,8 @@
4646
<uses-permission android:name="android.permission.WAKE_LOCK" />
4747
</config-file>
4848

49+
50+
4951
<config-file target="AndroidManifest.xml" parent="/manifest/application">
5052
<receiver
5153
android:name="com.webengage.sdk.android.InstallTracker"
@@ -54,8 +56,12 @@
5456
<action android:name="com.android.vending.INSTALL_REFERRER" />
5557
</intent-filter>
5658
</receiver>
59+
<meta-data
60+
android:name="com.webengage.child.io"
61+
android:value="io:${io_version}" />
5762
</config-file>
5863

64+
<resource-file src="src/android/version.properties" target="version.properties" />
5965
<source-file src="src/android/WebEngagePlugin.java" target-dir="src/com/webengage/cordova/"/>
6066
<framework src="src/android/WebEngagePlugin.gradle" custom="true" type="gradleReference"/>
6167
</platform>

src/android/WebEngagePlugin.gradle

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,51 @@ buildscript {
55
}
66
}
77

8+
android {
9+
compileSdkVersion 33
10+
11+
defaultConfig {
12+
minSdkVersion 21
13+
targetSdkVersion 33
14+
manifestPlaceholders.io_version = readVersion()
15+
versionCode 2
16+
versionName "1.2.0"
17+
}
18+
lintOptions {
19+
abortOnError false
20+
}
21+
}
22+
23+
String readVersion() {
24+
def version = new Properties()
25+
def stream
26+
try {
27+
System.out.println("projectDir: " + projectDir)
28+
println("projectDir: " + projectDir)
29+
stream = new FileInputStream(new File(projectDir, './src/main/version.properties'))
30+
version.load(stream)
31+
} catch (FileNotFoundException ignore) {
32+
} finally {
33+
if (stream != null) stream.close()
34+
}
35+
// safety defaults in case file is missing
36+
if(!version['major']) version['major'] = "1"
37+
if(!version['minor']) version['minor'] = "0"
38+
if(!version['patch']) version['patch'] = "0"
39+
return "${version['major']}.${version['minor']}.${version['patch']}"
40+
}
41+
42+
843
allprojects {
944
repositories {
1045
mavenCentral();
1146
jcenter();
1247
}
1348
}
1449
dependencies {
15-
api 'com.webengage:android-sdk:[3,)'
50+
implementation 'com.webengage:android-sdk:4.+'
51+
implementation platform('com.google.firebase:firebase-bom:25.12.0')
52+
implementation 'com.google.firebase:firebase-analytics'
53+
implementation 'com.google.firebase:firebase-messaging:20.2.1'
54+
implementation 'com.google.android.gms:play-services-ads:15.0.1'
1655
}

src/android/WebEngagePlugin.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.webengage.sdk.android.callbacks.InAppNotificationCallbacks;
3939
import com.webengage.sdk.android.UserProfile;
4040
import com.webengage.sdk.android.utils.Gender;
41+
import com.webengage.sdk.android.Channel;
4142

4243

4344
public class WebEngagePlugin extends CordovaPlugin implements PushNotificationCallbacks, InAppNotificationCallbacks {
@@ -141,6 +142,9 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
141142
if (!androidConfig.isNull("pushProjectNumber")) {
142143
configBuilder.setGCMProjectNumber(androidConfig.optString("pushProjectNumber"));
143144
}
145+
if(!androidConfig.isNull("autoGAIDTracking") && androidConfig.getBoolean("autoGAIDTracking") == false) {
146+
configBuilder.setAutoGAIDTracking(false);
147+
}
144148
if (!androidConfig.isNull("locationTrackingStrategy")) {
145149
if ("accuracy_best".equals(androidConfig.optString("locationTrackingStrategy"))) {
146150
configBuilder.setLocationTrackingStrategy(LocationTrackingStrategy.ACCURACY_BEST);
@@ -267,6 +271,30 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
267271
if (args.length() == 1 && args.get(0) instanceof Boolean) {
268272
WebEngage.get().user().setDevicePushOptIn(args.getBoolean(0));
269273
}
274+
} else if ("setUserOptIn".equals(action)) {
275+
if (args.length() == 2 && args.get(0) instanceof String && args.get(1) instanceof Boolean) {
276+
String channel = args.getString(0);
277+
boolean status = args.getBoolean(1);
278+
if ("PUSH".equalsIgnoreCase(channel)) {
279+
WebEngage.get().user().setOptIn(Channel.PUSH, status);
280+
} else if ("SMS".equalsIgnoreCase(channel)) {
281+
WebEngage.get().user().setOptIn(Channel.SMS, status);
282+
} else if ("EMAIL".equalsIgnoreCase(channel)) {
283+
WebEngage.get().user().setOptIn(Channel.EMAIL, status);
284+
} else if ("IN_APP".equalsIgnoreCase(channel)) {
285+
WebEngage.get().user().setOptIn(Channel.IN_APP, status);
286+
} else if ("WHATSAPP".equalsIgnoreCase(channel)) {
287+
WebEngage.get().user().setOptIn(Channel.WHATSAPP, status);
288+
} else if ("VIBER".equalsIgnoreCase(channel)) {
289+
WebEngage.get().user().setOptIn(Channel.VIBER, status);
290+
}
291+
else {
292+
Logger.e("WebEngagePlugin", "Invalid channel: " + channel + ". Must be one of [push, sms, email, in_app, whatsapp, viber].");
293+
}
294+
}
295+
}
296+
else if("startGAIDTracking".equals(action)){
297+
WebEngage.get().startGAIDTracking();
270298
}
271299

272300
return true;
@@ -485,4 +513,4 @@ private static JSONObject mergeJson(JSONObject jsonObject1, JSONObject jsonObjec
485513
}
486514
return jsonObject1;
487515
}
488-
}
516+
}

src/android/version.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
major=1
2+
minor=2
3+
patch=0

src/ios/AppDelegate+WebEngagePlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
+ (instancetype)sharedInstance;
66
- (BOOL)isFreshLaunch;
77
- (void)setFreshLaunch:(BOOL)freshLaunch;
8-
8+
- (void)presentInAppController;
99
@end

src/ios/AppDelegate+WebEngagePlugin.m

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#import <WebEngage/WebEngage.h>
22
#import "AppDelegate+WebEngagePlugin.h"
3-
3+
#import "MainViewController.h"
44
@interface WebEngagePluginUtils : NSObject
55

66
+ (instancetype)sharedInstance;
@@ -108,4 +108,36 @@ - (void)setFreshLaunch:(BOOL)freshLaunch {
108108
[WebEngagePluginUtils sharedInstance].freshLaunch = freshLaunch;
109109
}
110110

111+
112+
113+
- (void)presentInAppController {
114+
115+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
116+
UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
117+
118+
if (window) {
119+
WKWebView *lastSubview = (WKWebView *)window.subviews.lastObject;
120+
UIViewController *topViewController = [self topViewController];
121+
122+
if ([lastSubview isKindOfClass:[WKWebView class]] && topViewController) {
123+
[topViewController.view addSubview:lastSubview];
124+
[topViewController.view bringSubviewToFront:lastSubview];
125+
}
126+
}
127+
});
128+
129+
}
130+
131+
- (UIViewController *)topViewController {
132+
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
133+
134+
while (rootViewController.presentedViewController) {
135+
rootViewController = rootViewController.presentedViewController;
136+
}
137+
138+
return rootViewController;
139+
}
140+
141+
142+
111143
@end

src/ios/WebEngagePlugin.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
+ (WebEngagePlugin *)webEngagePlugin;
1212

13+
- (void)initialiseWEGVersions;
14+
1315
- (void)handlePushNotificationPendingDeepLinks;
1416

1517

@@ -22,7 +24,8 @@
2224
- (void)logout:(CDVInvokedUrlCommand *)command;
2325
- (void)track:(CDVInvokedUrlCommand *)command;
2426
- (void)setAttribute:(CDVInvokedUrlCommand *)command;
25-
27+
- (void)setUserOptIn:(CDVInvokedUrlCommand *)command;
28+
- (void)presentInAppController:(CDVInvokedUrlCommand *)command;
2629
+ (void)evaluateJavaScript:(NSString *)script onWebView:(id)webView
2730
completionHandler:(void (^ _Nullable)(NSString * _Nullable response, NSError * _Nullable error))completionHandler;
2831
@end

src/ios/WebEngagePlugin.m

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
#define WE_COMPANY @"we_company"
1515
#define WE_HASHED_EMAIL @"we_hashed_email"
1616
#define WE_HASHED_PHONE @"we_hashed_phone"
17+
#define PUSH @"push"
18+
#define SMS @"sms"
19+
#define EMAIL @"email"
20+
#define IN_APP @"in_app"
21+
#define WHATSAPP @"whatsapp"
22+
#define VIBER @"viber"
23+
#define WEGPluginVersion @"1.2.0"
1724

1825
@interface WebEngagePlugin()
1926

@@ -34,7 +41,9 @@ - (void)pluginInitialize {
3441
[super pluginInitialize];
3542
webEngagePlugin = self;
3643
self.pendingDeepLinkCallback = nil;
37-
44+
45+
[webEngagePlugin initialiseWEGVersions];
46+
3847
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
3948
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
4049
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
@@ -50,6 +59,11 @@ - (void)pluginInitialize {
5059
self.birthDateFormatter = birthDateFormatter;
5160
}
5261

62+
- (void) initialiseWEGVersions {
63+
WegVersionKey key = WegVersionKeyIO;
64+
[[WebEngage sharedInstance] setVersionForChildSDK:WEGPluginVersion forKey:key];
65+
}
66+
5367
- (void)handlePushNotificationPendingDeepLinks {
5468

5569
AppDelegate* appDelegate = [AppDelegate sharedInstance];
@@ -223,16 +237,18 @@ - (void)track:(CDVInvokedUrlCommand *)command {
223237
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
224238
}
225239

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

230244
if (screenName != nil && screenName.length > 0) {
231245
id screenData = command.arguments && command.arguments.count>1 ? [command.arguments objectAtIndex:1] : nil;
232246
if (screenData && [screenData isKindOfClass:[NSDictionary class]]) {
233-
[[WebEngage sharedInstance].analytics navigatingToScreenWithName:screenName andData:[self convertISODateStringValuesToNSDate:screenData]];
247+
[[WebEngage sharedInstance].analytics
248+
trackEventWithName:screenName
249+
andValue:[self convertISODateStringValuesToNSDate:screenData]];
234250
} else {
235-
[[WebEngage sharedInstance].analytics navigatingToScreenWithName:screenName];
251+
[[WebEngage sharedInstance].analytics trackEventWithName:screenName];
236252
}
237253

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

467+
- (void)setUserOptIn:(CDVInvokedUrlCommand *)command {
468+
CDVPluginResult* pluginResult = nil;
469+
BOOL status = nil;
470+
471+
NSString* ch = command.arguments && command.arguments.count>0 ? [command.arguments objectAtIndex:0] : nil;
472+
if (command.arguments && command.arguments.count > 1) {
473+
status = [[command.arguments objectAtIndex:1] boolValue];
474+
}
475+
if(status == nil && ch == nil){
476+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
477+
}
478+
else
479+
{if ([ch isEqualToString:PUSH]) {
480+
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelPush status:status];
481+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
482+
} else if ([ch isEqualToString:SMS]) {
483+
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelSMS status:status];
484+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
485+
} else if ([ch isEqualToString:EMAIL]) {
486+
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelEmail status:status];
487+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
488+
} else if ([ch isEqualToString:IN_APP]) {
489+
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelInApp status:status];
490+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
491+
} else if ([ch isEqualToString:WHATSAPP]) {
492+
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelWhatsapp status:status];
493+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
494+
}else if ([ch isEqualToString:VIBER]) {
495+
[[WebEngage sharedInstance].user setOptInStatusForChannel:WEGEngagementChannelViber status:status];
496+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
497+
} else {
498+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
499+
}
500+
}
501+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
502+
503+
}
504+
505+
-(void)presentInAppController:(CDVInvokedUrlCommand *)command{
506+
AppDelegate* appDelegate = [AppDelegate sharedInstance];
507+
[appDelegate presentInAppController];
508+
}
509+
510+
451511
@end
512+

0 commit comments

Comments
 (0)