From 8f46a5b3c11c58bb21127def968eced22263405b Mon Sep 17 00:00:00 2001 From: AdityaS Date: Mon, 24 Apr 2023 13:31:24 +0530 Subject: [PATCH 01/18] added viber channel support --- src/android/WebEngagePlugin.java | 21 +++++++++++++++++++++ www/WebEngagePlugin.js | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/android/WebEngagePlugin.java b/src/android/WebEngagePlugin.java index 7eff317..2df7790 100644 --- a/src/android/WebEngagePlugin.java +++ b/src/android/WebEngagePlugin.java @@ -267,6 +267,27 @@ 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]."); + } + } } return true; diff --git a/www/WebEngagePlugin.js b/www/WebEngagePlugin.js index 4cea6f5..5200cc9 100644 --- a/www/WebEngagePlugin.js +++ b/www/WebEngagePlugin.js @@ -136,11 +136,14 @@ WebEngageUserChannel.prototype.setAttribute = function(key, value) { } }; - WebEngageUserChannel.prototype.setDevicePushOptIn = function(optIn) { exec(null, null, "WebEngagePlugin", "setDevicePushOptIn", [optIn]); }; +WebEngageUserChannel.prototype.setUserOptIn = function(channel, optIn) { + exec(null, null, "WebEngagePlugin", "setUserOptIn", [channel, optIn]); +}; + function isValidJavascriptObject(val) { return val !== undefined && val != null && typeof val === 'object' && Object.prototype.toString.call(val) === '[object Object]'; From befce0c3ccd91e673faba1ab3de67d0dda85cb8c Mon Sep 17 00:00:00 2001 From: AdityaS Date: Mon, 24 Apr 2023 19:18:01 +0530 Subject: [PATCH 02/18] added import for CHANNEL --- src/android/WebEngagePlugin.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/android/WebEngagePlugin.java b/src/android/WebEngagePlugin.java index 2df7790..010f78c 100644 --- a/src/android/WebEngagePlugin.java +++ b/src/android/WebEngagePlugin.java @@ -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 { @@ -271,17 +272,17 @@ public boolean execute(String action, JSONArray args, final CallbackContext call 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)) { + if ("PUSH".equalsIgnoreCase(channel)) { WebEngage.get().user().setOptIn(Channel.PUSH, status); - } else if (SMS.equalsIgnoreCase(channel)) { + } else if ("SMS".equalsIgnoreCase(channel)) { WebEngage.get().user().setOptIn(Channel.SMS, status); - } else if (EMAIL.equalsIgnoreCase(channel)) { + } else if ("EMAIL".equalsIgnoreCase(channel)) { WebEngage.get().user().setOptIn(Channel.EMAIL, status); - } else if (IN_APP.equalsIgnoreCase(channel)) { + } else if ("IN_APP".equalsIgnoreCase(channel)) { WebEngage.get().user().setOptIn(Channel.IN_APP, status); - } else if (WHATSAPP.equalsIgnoreCase(channel)) { + } else if ("WHATSAPP".equalsIgnoreCase(channel)) { WebEngage.get().user().setOptIn(Channel.WHATSAPP, status); - } else if (VIBER.equalsIgnoreCase(channel)) { + } else if ("VIBER".equalsIgnoreCase(channel)) { WebEngage.get().user().setOptIn(Channel.VIBER, status); } else { From 599475b533ea6e76938463ccc01ea1ae2f285e8f Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 22 Sep 2023 13:10:35 +0530 Subject: [PATCH 03/18] Version tracking implemented --- plugin.xml | 15 ++++++++++++- src/android/WebEngagePlugin.gradle | 35 ++++++++++++++++++++++++++++++ src/android/version.properties | 3 +++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/android/version.properties diff --git a/plugin.xml b/plugin.xml index 17ea9db..36c90e5 100644 --- a/plugin.xml +++ b/plugin.xml @@ -30,7 +30,7 @@ - + @@ -45,6 +45,14 @@ + + + + + + + diff --git a/src/android/WebEngagePlugin.gradle b/src/android/WebEngagePlugin.gradle index 05d87be..1d49158 100644 --- a/src/android/WebEngagePlugin.gradle +++ b/src/android/WebEngagePlugin.gradle @@ -5,6 +5,41 @@ buildscript { } } +android { + compileSdkVersion 33 + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 33 + manifestPlaceholders = [io_version: readVersion()] + versionCode 1 + versionName "1.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(); diff --git a/src/android/version.properties b/src/android/version.properties new file mode 100644 index 0000000..10ec7d5 --- /dev/null +++ b/src/android/version.properties @@ -0,0 +1,3 @@ +major=1 +minor=0 +patch=0 \ No newline at end of file From 9d9246b3529198af4c26eb489abc1fa301d1b59d Mon Sep 17 00:00:00 2001 From: Shubham Naidu Date: Fri, 6 Oct 2023 18:33:25 +0530 Subject: [PATCH 04/18] sdk version tracking added. --- src/ios/WebEngagePlugin.h | 2 ++ src/ios/WebEngagePlugin.m | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ios/WebEngagePlugin.h b/src/ios/WebEngagePlugin.h index 23adef9..4da740e 100644 --- a/src/ios/WebEngagePlugin.h +++ b/src/ios/WebEngagePlugin.h @@ -10,6 +10,8 @@ + (WebEngagePlugin *)webEngagePlugin; +- (void)initialiseWEGVersions; + - (void)handlePushNotificationPendingDeepLinks; diff --git a/src/ios/WebEngagePlugin.m b/src/ios/WebEngagePlugin.m index ad97c76..b94b778 100644 --- a/src/ios/WebEngagePlugin.m +++ b/src/ios/WebEngagePlugin.m @@ -14,6 +14,7 @@ #define WE_COMPANY @"we_company" #define WE_HASHED_EMAIL @"we_hashed_email" #define WE_HASHED_PHONE @"we_hashed_phone" +#define WEGPluginVersion @"1.0.0" @interface WebEngagePlugin() @@ -34,7 +35,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"]]; @@ -50,6 +53,11 @@ - (void)pluginInitialize { self.birthDateFormatter = birthDateFormatter; } +- (void) initialiseWEGVersions { + WegVersionKey key = WegVersionKeyIO; + [[WebEngage sharedInstance] setVersionForChildSDK:WEGPluginVersion forKey:key];; +} + - (void)handlePushNotificationPendingDeepLinks { AppDelegate* appDelegate = [AppDelegate sharedInstance]; From 6c383afbcce8242eeba764457cceb6745e2f3b06 Mon Sep 17 00:00:00 2001 From: Shubham Naidu Date: Fri, 6 Oct 2023 18:35:11 +0530 Subject: [PATCH 05/18] refactor code --- src/ios/WebEngagePlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/WebEngagePlugin.m b/src/ios/WebEngagePlugin.m index b94b778..8a22432 100644 --- a/src/ios/WebEngagePlugin.m +++ b/src/ios/WebEngagePlugin.m @@ -55,7 +55,7 @@ - (void)pluginInitialize { - (void) initialiseWEGVersions { WegVersionKey key = WegVersionKeyIO; - [[WebEngage sharedInstance] setVersionForChildSDK:WEGPluginVersion forKey:key];; + [[WebEngage sharedInstance] setVersionForChildSDK:WEGPluginVersion forKey:key]; } - (void)handlePushNotificationPendingDeepLinks { From 6930c706f39502612fe5fb11b478528c4538d684 Mon Sep 17 00:00:00 2001 From: Shubham Naidu Date: Fri, 6 Oct 2023 18:36:51 +0530 Subject: [PATCH 06/18] version updated --- src/ios/WebEngagePlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/WebEngagePlugin.m b/src/ios/WebEngagePlugin.m index 8a22432..7914780 100644 --- a/src/ios/WebEngagePlugin.m +++ b/src/ios/WebEngagePlugin.m @@ -14,7 +14,7 @@ #define WE_COMPANY @"we_company" #define WE_HASHED_EMAIL @"we_hashed_email" #define WE_HASHED_PHONE @"we_hashed_phone" -#define WEGPluginVersion @"1.0.0" +#define WEGPluginVersion @"1.1.0" @interface WebEngagePlugin() From 169f345c9640d34fb72fdaccbfbf8d0aec56a426 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 25 Oct 2023 14:20:06 +0530 Subject: [PATCH 07/18] Updated version property --- src/android/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/version.properties b/src/android/version.properties index 10ec7d5..c0b591f 100644 --- a/src/android/version.properties +++ b/src/android/version.properties @@ -1,3 +1,3 @@ major=1 -minor=0 +minor=1 patch=0 \ No newline at end of file From 369949ec2820d25ae3a77232d5d01dba2839307c Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 25 Oct 2023 18:41:11 +0530 Subject: [PATCH 08/18] version tracking added with new changes to support mutliple versions within application --- plugin.xml | 8 +------- src/android/WebEngagePlugin.gradle | 4 ++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/plugin.xml b/plugin.xml index 36c90e5..b8a802d 100644 --- a/plugin.xml +++ b/plugin.xml @@ -45,13 +45,7 @@ - - - + diff --git a/src/android/WebEngagePlugin.gradle b/src/android/WebEngagePlugin.gradle index 1d49158..97b9321 100644 --- a/src/android/WebEngagePlugin.gradle +++ b/src/android/WebEngagePlugin.gradle @@ -11,7 +11,7 @@ android { defaultConfig { minSdkVersion 21 targetSdkVersion 33 - manifestPlaceholders = [io_version: readVersion()] + manifestPlaceholders.io_version = readVersion() versionCode 1 versionName "1.0" } @@ -47,5 +47,5 @@ allprojects { } } dependencies { - api 'com.webengage:android-sdk:[3,)' + api 'com.webengage:android-sdk:[4,)' } From d7e396958721ada93cc4617bd07261dcdd82367f Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 30 Oct 2023 17:40:06 +0530 Subject: [PATCH 09/18] Added login functionality for login with secure token --- src/android/WebEngagePlugin.java | 4 ++++ www/WebEngagePlugin.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/android/WebEngagePlugin.java b/src/android/WebEngagePlugin.java index 010f78c..1048463 100644 --- a/src/android/WebEngagePlugin.java +++ b/src/android/WebEngagePlugin.java @@ -261,6 +261,10 @@ public boolean execute(String action, JSONArray args, final CallbackContext call } 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(0) == null) { + 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 ("logout".equals(action)) { WebEngage.get().user().logout(); diff --git a/www/WebEngagePlugin.js b/www/WebEngagePlugin.js index 5200cc9..532486a 100644 --- a/www/WebEngagePlugin.js +++ b/www/WebEngagePlugin.js @@ -120,8 +120,8 @@ WebEngageNotificationChannel.prototype.onCallbackReceived = function(type, notif function WebEngageUserChannel() { } -WebEngageUserChannel.prototype.login = function(userId) { - exec(null, null, "WebEngagePlugin", "login", [userId]); +WebEngageUserChannel.prototype.login = function(userId, secureToken = null) { + exec(null, null, "WebEngagePlugin", "login", [userId, secureToken]); }; WebEngageUserChannel.prototype.logout = function() { From 78103543d9250c8819f447325e381ac0174fc529 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 24 Nov 2023 15:13:12 +0530 Subject: [PATCH 10/18] GAID tracking added for Android --- src/android/WebEngagePlugin.java | 8 +- www/WebEngagePlugin.js | 237 ++++++++++++++++++------------- 2 files changed, 146 insertions(+), 99 deletions(-) diff --git a/src/android/WebEngagePlugin.java b/src/android/WebEngagePlugin.java index 010f78c..259da29 100644 --- a/src/android/WebEngagePlugin.java +++ b/src/android/WebEngagePlugin.java @@ -142,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); @@ -290,6 +293,9 @@ public boolean execute(String action, JSONArray args, final CallbackContext call } } } + else if("startGAIDTracking".equals(action)){ + WebEngage.get().startGAIDTracking(); + } return true; } @@ -507,4 +513,4 @@ private static JSONObject mergeJson(JSONObject jsonObject1, JSONObject jsonObjec } return jsonObject1; } -} +} \ No newline at end of file diff --git a/www/WebEngagePlugin.js b/www/WebEngagePlugin.js index 5200cc9..58c54a5 100644 --- a/www/WebEngagePlugin.js +++ b/www/WebEngagePlugin.js @@ -1,32 +1,31 @@ -var exec = require('cordova/exec'); +var exec = require("cordova/exec"); function WebEngagePlugin() { - this.push = new WebEngagePushChannel(); - this.notification = new WebEngageNotificationChannel(); - this.user = new WebEngageUserChannel(); - this._options = {}; + this.push = new WebEngagePushChannel(); + this.notification = new WebEngageNotificationChannel(); + this.user = new WebEngageUserChannel(); + this._options = {}; } -WebEngagePlugin.prototype.engage = function(config) { - if (config) { - exec(null, null, "WebEngagePlugin", "engage", [config]); - } else { - exec(null, null, "WebEngagePlugin", "engage", []); - } -} +WebEngagePlugin.prototype.engage = function (config) { + if (config) { + exec(null, null, "WebEngagePlugin", "engage", [config]); + } else { + exec(null, null, "WebEngagePlugin", "engage", []); + } +}; -WebEngagePlugin.prototype.options = function(key, value) { - this._options[key] = value; - exec(null, null, "WebEngagePlugin", "globalOptions", [key, value]); +WebEngagePlugin.prototype.options = function (key, value) { + this._options[key] = value; + exec(null, null, "WebEngagePlugin", "globalOptions", [key, value]); }; -WebEngagePlugin.prototype.track = function(eventName, attributes) { - if (attributes === undefined) { - exec(null, null, "WebEngagePlugin", "track", [eventName]); - } else { - exec(null, null, "WebEngagePlugin", "track", [eventName, attributes]); +WebEngagePlugin.prototype.startGAIDTracking = function() { + if(cordova.platformId === "android"){ + exec(null, null, "WebEngagePlugin", "startGAIDTracking",[]); } -} +}; + WebEngagePlugin.prototype.screen = function(screenName, screenData) { if (screenName !== undefined && (typeof screenName === 'string' || screenName instanceof String)) { @@ -42,118 +41,160 @@ WebEngagePlugin.prototype.screen = function(screenName, screenData) { } } -function WebEngagePushChannel () { - //this.clickCallback = function(){}; - this._options = {}; +WebEngagePlugin.prototype.track = function (eventName, attributes) { + if (attributes === undefined) { + exec(null, null, "WebEngagePlugin", "track", [eventName]); + } else { + exec(null, null, "WebEngagePlugin", "track", [eventName, attributes]); + } +}; + +WebEngagePlugin.prototype.screen = function (screenName, screenData) { + if ( + screenName !== undefined && + (typeof screenName === "string" || screenName instanceof String) + ) { + if (screenData === undefined) { + exec(null, null, "WebEngagePlugin", "screenNavigated", [screenName]); + } else { + exec(null, null, "WebEngagePlugin", "screenNavigated", [ + screenName, + screenData, + ]); + } + } else if (screenName !== undefined && isValidJavascriptObject(screenName)) { + exec(null, null, "WebEngagePlugin", "screenNavigated", [null, screenName]); + } else { + console.err("Invalid arguments provided to screen plugin call"); + } +}; + +function WebEngagePushChannel() { + //this.clickCallback = function(){}; + this._options = {}; } WebEngagePushChannel.prototype.options = function (key, value) { - this._options[key] = value; - exec(null, null, "WebEngagePlugin", "pushOptions", [key, value]); + this._options[key] = value; + exec(null, null, "WebEngagePlugin", "pushOptions", [key, value]); }; WebEngagePushChannel.prototype.onClick = function (callback) { - this.clickCallback = callback; -} - + this.clickCallback = callback; +}; -WebEngagePushChannel.prototype.onCallbackReceived = function(type, uri, customData) { - if (type) { - switch(type) { - case 'shown': - break; - case 'click': - this.clickCallback(uri, customData); - break; - case 'dismiss' : - break; - } - } +WebEngagePushChannel.prototype.onCallbackReceived = function ( + type, + uri, + customData +) { + if (type) { + switch (type) { + case "shown": + break; + case "click": + this.clickCallback(uri, customData); + break; + case "dismiss": + break; + } + } }; -function WebEngageNotificationChannel () { - this.shownCallback = function(){}; - this.clickCallback = function(){}; - this.dismissCallback = function(){}; - this.preparedCallback = function(){}; - this._options = {}; +function WebEngageNotificationChannel() { + this.shownCallback = function () {}; + this.clickCallback = function () {}; + this.dismissCallback = function () {}; + this.preparedCallback = function () {}; + this._options = {}; } -WebEngageNotificationChannel.prototype.options = function(key, value) { - this._options[key] = value; - exec(null, null, "WebEngagePlugin", "inappOptions", [key, value]); +WebEngageNotificationChannel.prototype.options = function (key, value) { + this._options[key] = value; + exec(null, null, "WebEngagePlugin", "inappOptions", [key, value]); }; WebEngageNotificationChannel.prototype.onShown = function (callback) { - this.shownCallback = callback; + this.shownCallback = callback; }; WebEngageNotificationChannel.prototype.onClick = function (callback) { - this.clickCallback = callback; -} + this.clickCallback = callback; +}; -WebEngageNotificationChannel.prototype.onDismiss = function(callback) { - this.dismissCallback = callback; -}; -WebEngageNotificationChannel.prototype.onPrepared = function(callback) { - this.preparedCallback = callback; -}; - -WebEngageNotificationChannel.prototype.onCallbackReceived = function(type, notificationData, actionId) { - if (type) { - switch(type) { - case 'shown' : - this.shownCallback(notificationData); - break; - case 'click' : - this.clickCallback(notificationData, actionId); - break; - case 'dismiss' : - this.dismissCallback(notificationData); - case 'prepared': - this.preparedCallback(notificationData); - break; - } - } +WebEngageNotificationChannel.prototype.onDismiss = function (callback) { + this.dismissCallback = callback; +}; +WebEngageNotificationChannel.prototype.onPrepared = function (callback) { + this.preparedCallback = callback; }; -function WebEngageUserChannel() { -} +WebEngageNotificationChannel.prototype.onCallbackReceived = function ( + type, + notificationData, + actionId +) { + if (type) { + switch (type) { + case "shown": + this.shownCallback(notificationData); + break; + case "click": + this.clickCallback(notificationData, actionId); + break; + case "dismiss": + this.dismissCallback(notificationData); + case "prepared": + this.preparedCallback(notificationData); + break; + } + } +}; + +function WebEngageUserChannel() {} -WebEngageUserChannel.prototype.login = function(userId) { - exec(null, null, "WebEngagePlugin", "login", [userId]); +WebEngageUserChannel.prototype.login = function (userId) { + exec(null, null, "WebEngagePlugin", "login", [userId]); }; -WebEngageUserChannel.prototype.logout = function() { - exec(null, null, "WebEngagePlugin", "logout",[]); +WebEngageUserChannel.prototype.logout = function () { + exec(null, null, "WebEngagePlugin", "logout", []); }; -WebEngageUserChannel.prototype.setAttribute = function(key, value) { - if (value === undefined && isValidJavascriptObject(key)) { - exec(null, null, "WebEngagePlugin", "setAttribute", [key]); - } else if (key && isValidString(key) && value !== undefined) { - exec(null, null, "WebEngagePlugin", "setAttribute", [key, value]); - } +WebEngageUserChannel.prototype.setAttribute = function (key, value) { + if (value === undefined && isValidJavascriptObject(key)) { + exec(null, null, "WebEngagePlugin", "setAttribute", [key]); + } else if (key && isValidString(key) && value !== undefined) { + exec(null, null, "WebEngagePlugin", "setAttribute", [key, value]); + } }; -WebEngageUserChannel.prototype.setDevicePushOptIn = function(optIn) { - exec(null, null, "WebEngagePlugin", "setDevicePushOptIn", [optIn]); +WebEngageUserChannel.prototype.setDevicePushOptIn = function (optIn) { + exec(null, null, "WebEngagePlugin", "setDevicePushOptIn", [optIn]); }; -WebEngageUserChannel.prototype.setUserOptIn = function(channel, optIn) { - exec(null, null, "WebEngagePlugin", "setUserOptIn", [channel, optIn]); +WebEngageUserChannel.prototype.setUserOptIn = function (channel, optIn) { + exec(null, null, "WebEngagePlugin", "setUserOptIn", [channel, optIn]); }; function isValidJavascriptObject(val) { - return val !== undefined && val != null && typeof val === 'object' - && Object.prototype.toString.call(val) === '[object Object]'; + return ( + val !== undefined && + val != null && + typeof val === "object" && + Object.prototype.toString.call(val) === "[object Object]" + ); } function isValidString(val) { - return val !== undefined && val != null && (typeof val === 'string' || val instanceof String); + return ( + val !== undefined && + val != null && + (typeof val === "string" || val instanceof String) + ); } -if (typeof module != 'undefined' && module.exports) { - var WebEngagePlugin = new WebEngagePlugin(); - module.exports = WebEngagePlugin; +if (typeof module != "undefined" && module.exports) { + var WebEngagePlugin = new WebEngagePlugin(); + module.exports = WebEngagePlugin; } From ec99db3e7f667210e763fb3ed6a58d154c6fa642 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 6 Dec 2023 18:29:15 +0530 Subject: [PATCH 11/18] userOptIn changes added in plugin - viber --- plugin.xml | 5 +-- src/android/WebEngagePlugin.gradle | 6 +++- src/ios/WebEngagePlugin.h | 2 +- src/ios/WebEngagePlugin.m | 55 +++++++++++++++++++++++++++--- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/plugin.xml b/plugin.xml index 17ea9db..ad2d3aa 100644 --- a/plugin.xml +++ b/plugin.xml @@ -30,7 +30,7 @@ - + @@ -55,7 +55,8 @@ - + + diff --git a/src/android/WebEngagePlugin.gradle b/src/android/WebEngagePlugin.gradle index 05d87be..9d0f775 100644 --- a/src/android/WebEngagePlugin.gradle +++ b/src/android/WebEngagePlugin.gradle @@ -12,5 +12,9 @@ allprojects { } } 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' } diff --git a/src/ios/WebEngagePlugin.h b/src/ios/WebEngagePlugin.h index 23adef9..4175818 100644 --- a/src/ios/WebEngagePlugin.h +++ b/src/ios/WebEngagePlugin.h @@ -22,7 +22,7 @@ - (void)logout:(CDVInvokedUrlCommand *)command; - (void)track:(CDVInvokedUrlCommand *)command; - (void)setAttribute:(CDVInvokedUrlCommand *)command; - +- (void)setUserOptIn:(CDVInvokedUrlCommand *)command; + (void)evaluateJavaScript:(NSString *)script onWebView:(id)webView completionHandler:(void (^ _Nullable)(NSString * _Nullable response, NSError * _Nullable error))completionHandler; @end diff --git a/src/ios/WebEngagePlugin.m b/src/ios/WebEngagePlugin.m index ad97c76..cc3b84e 100644 --- a/src/ios/WebEngagePlugin.m +++ b/src/ios/WebEngagePlugin.m @@ -14,6 +14,12 @@ #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" @interface WebEngagePlugin() @@ -223,16 +229,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]; @@ -448,4 +456,43 @@ + (void) evaluateJavaScript:(NSString *)script onWebView:(id)webView } } -@end +- (void)setUserOptIn:(CDVInvokedUrlCommand *)command { + CDVPluginResult* pluginResult = nil; + 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]; + +} + +@end \ No newline at end of file From 045fd7100681196fa17aed6fd1999b3a895eb60f Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 12 Dec 2023 15:48:15 +0530 Subject: [PATCH 12/18] Revert "Added login functionality for login with secure token" This reverts commit d7e396958721ada93cc4617bd07261dcdd82367f. --- src/android/WebEngagePlugin.java | 4 ---- www/WebEngagePlugin.js | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/android/WebEngagePlugin.java b/src/android/WebEngagePlugin.java index 1048463..010f78c 100644 --- a/src/android/WebEngagePlugin.java +++ b/src/android/WebEngagePlugin.java @@ -261,10 +261,6 @@ public boolean execute(String action, JSONArray args, final CallbackContext call } 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(0) == null) { - 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 ("logout".equals(action)) { WebEngage.get().user().logout(); diff --git a/www/WebEngagePlugin.js b/www/WebEngagePlugin.js index 532486a..5200cc9 100644 --- a/www/WebEngagePlugin.js +++ b/www/WebEngagePlugin.js @@ -120,8 +120,8 @@ WebEngageNotificationChannel.prototype.onCallbackReceived = function(type, notif function WebEngageUserChannel() { } -WebEngageUserChannel.prototype.login = function(userId, secureToken = null) { - exec(null, null, "WebEngagePlugin", "login", [userId, secureToken]); +WebEngageUserChannel.prototype.login = function(userId) { + exec(null, null, "WebEngagePlugin", "login", [userId]); }; WebEngageUserChannel.prototype.logout = function() { From 96367926e477771412bb4938388f0b6559b26e6c Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 12 Dec 2023 17:15:49 +0530 Subject: [PATCH 13/18] Revert "Added login functionality for login with secure token" This reverts commit d7e396958721ada93cc4617bd07261dcdd82367f. --- www/WebEngagePlugin.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/www/WebEngagePlugin.js b/www/WebEngagePlugin.js index 58c54a5..3c9d290 100644 --- a/www/WebEngagePlugin.js +++ b/www/WebEngagePlugin.js @@ -150,6 +150,12 @@ WebEngageNotificationChannel.prototype.onCallbackReceived = function ( } } }; +function WebEngageUserChannel() { +} + +WebEngageUserChannel.prototype.login = function(userId) { + exec(null, null, "WebEngagePlugin", "login", [userId]); +}; function WebEngageUserChannel() {} From 6eeacc99623e84e91bb1c638cd0fd40a4e7169f6 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 12 Dec 2023 17:16:03 +0530 Subject: [PATCH 14/18] removed aar file --- plugin.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 1e5eceb..5c04cdd 100644 --- a/plugin.xml +++ b/plugin.xml @@ -62,7 +62,6 @@ - From ec767c493072bd6c730750e0e00ff0b21dec2d03 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 12 Dec 2023 17:45:50 +0530 Subject: [PATCH 15/18] removed duplicate line --- src/ios/WebEngagePlugin.m | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ios/WebEngagePlugin.m b/src/ios/WebEngagePlugin.m index 21ee0c9..425614a 100644 --- a/src/ios/WebEngagePlugin.m +++ b/src/ios/WebEngagePlugin.m @@ -465,7 +465,6 @@ + (void) evaluateJavaScript:(NSString *)script onWebView:(id)webView } - (void)setUserOptIn:(CDVInvokedUrlCommand *)command { - CDVPluginResult* pluginResult = nil; CDVPluginResult* pluginResult = nil; BOOL status = nil; From 14dc2f5887f7717ad0910d70f09950daf41c5b8f Mon Sep 17 00:00:00 2001 From: Milind Keni Date: Fri, 22 Dec 2023 17:03:59 +0530 Subject: [PATCH 16/18] presentInAppController will bring top view to top of top view controller --- src/ios/AppDelegate+WebEngagePlugin.h | 2 +- src/ios/AppDelegate+WebEngagePlugin.m | 34 ++++++++++++++++++++++++++- src/ios/WebEngagePlugin.h | 1 + src/ios/WebEngagePlugin.m | 6 +++++ www/WebEngagePlugin.js | 8 +++++++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/ios/AppDelegate+WebEngagePlugin.h b/src/ios/AppDelegate+WebEngagePlugin.h index 11bb54c..c9d8a45 100644 --- a/src/ios/AppDelegate+WebEngagePlugin.h +++ b/src/ios/AppDelegate+WebEngagePlugin.h @@ -5,5 +5,5 @@ + (instancetype)sharedInstance; - (BOOL)isFreshLaunch; - (void)setFreshLaunch:(BOOL)freshLaunch; - +- (void)presentInAppController; @end diff --git a/src/ios/AppDelegate+WebEngagePlugin.m b/src/ios/AppDelegate+WebEngagePlugin.m index c004aab..5e692d7 100644 --- a/src/ios/AppDelegate+WebEngagePlugin.m +++ b/src/ios/AppDelegate+WebEngagePlugin.m @@ -1,6 +1,6 @@ #import #import "AppDelegate+WebEngagePlugin.h" - +#import "MainViewController.h" @interface WebEngagePluginUtils : NSObject + (instancetype)sharedInstance; @@ -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 diff --git a/src/ios/WebEngagePlugin.h b/src/ios/WebEngagePlugin.h index 23adef9..0901186 100644 --- a/src/ios/WebEngagePlugin.h +++ b/src/ios/WebEngagePlugin.h @@ -22,6 +22,7 @@ - (void)logout:(CDVInvokedUrlCommand *)command; - (void)track:(CDVInvokedUrlCommand *)command; - (void)setAttribute:(CDVInvokedUrlCommand *)command; +- (void)presentInAppController:(CDVInvokedUrlCommand *)command; + (void)evaluateJavaScript:(NSString *)script onWebView:(id)webView completionHandler:(void (^ _Nullable)(NSString * _Nullable response, NSError * _Nullable error))completionHandler; diff --git a/src/ios/WebEngagePlugin.m b/src/ios/WebEngagePlugin.m index ad97c76..f729342 100644 --- a/src/ios/WebEngagePlugin.m +++ b/src/ios/WebEngagePlugin.m @@ -448,4 +448,10 @@ + (void) evaluateJavaScript:(NSString *)script onWebView:(id)webView } } +-(void)presentInAppController:(CDVInvokedUrlCommand *)command{ + AppDelegate* appDelegate = [AppDelegate sharedInstance]; + [appDelegate presentInAppController]; +} + + @end diff --git a/www/WebEngagePlugin.js b/www/WebEngagePlugin.js index 4cea6f5..d685e37 100644 --- a/www/WebEngagePlugin.js +++ b/www/WebEngagePlugin.js @@ -154,3 +154,11 @@ if (typeof module != 'undefined' && module.exports) { var WebEngagePlugin = new WebEngagePlugin(); module.exports = WebEngagePlugin; } + +WebEngageUserChannel.prototype.presentInAppController = function () { + if (typeof cordova !== 'undefined' && cordova.platformId === 'ios') { + exec(null, null, "WebEngagePlugin", "presentInAppController", []); + } else { + console.log("presentInAppController is not supported on this platform."); + } +} \ No newline at end of file From 947b686ca27adb49feb0bdffa9d4e9f3ca2ac651 Mon Sep 17 00:00:00 2001 From: Milind Keni Date: Tue, 26 Dec 2023 14:11:50 +0530 Subject: [PATCH 17/18] version updated to 1.2.0 --- package.json | 2 +- src/android/WebEngagePlugin.gradle | 4 ++-- src/android/version.properties | 2 +- src/ios/WebEngagePlugin.m | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7bcc2e1..3411049 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/android/WebEngagePlugin.gradle b/src/android/WebEngagePlugin.gradle index a4f3028..820a90e 100644 --- a/src/android/WebEngagePlugin.gradle +++ b/src/android/WebEngagePlugin.gradle @@ -12,8 +12,8 @@ android { minSdkVersion 21 targetSdkVersion 33 manifestPlaceholders.io_version = readVersion() - versionCode 1 - versionName "1.0" + versionCode 2 + versionName "1.2.0" } lintOptions { abortOnError false diff --git a/src/android/version.properties b/src/android/version.properties index c0b591f..126cb2c 100644 --- a/src/android/version.properties +++ b/src/android/version.properties @@ -1,3 +1,3 @@ major=1 -minor=1 +minor=2 patch=0 \ No newline at end of file diff --git a/src/ios/WebEngagePlugin.m b/src/ios/WebEngagePlugin.m index b773867..a999311 100644 --- a/src/ios/WebEngagePlugin.m +++ b/src/ios/WebEngagePlugin.m @@ -20,7 +20,7 @@ #define IN_APP @"in_app" #define WHATSAPP @"whatsapp" #define VIBER @"viber" -#define WEGPluginVersion @"1.1.0" +#define WEGPluginVersion @"1.2.0" @interface WebEngagePlugin() From eccce3eb6bd2ff29285b4ac7493f29ed115b7d29 Mon Sep 17 00:00:00 2001 From: Milind Keni Date: Tue, 26 Dec 2023 14:45:53 +0530 Subject: [PATCH 18/18] added end in file --- src/ios/WebEngagePlugin.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ios/WebEngagePlugin.m b/src/ios/WebEngagePlugin.m index f729342..20faf8c 100644 --- a/src/ios/WebEngagePlugin.m +++ b/src/ios/WebEngagePlugin.m @@ -453,5 +453,9 @@ -(void)presentInAppController:(CDVInvokedUrlCommand *)command{ [appDelegate presentInAppController]; } +<<<<<<< Updated upstream @end +======= +@end +>>>>>>> Stashed changes