diff --git a/CHANGELOG.md b/CHANGELOG.md
index 065e8727..7b8f661d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,22 @@
Change Log
==========
+Version 2.7.2 *(December 5, 2023)*
+-------------------------------------------
+#### New Features
+
+**Android specific**
+* Supports [CleverTap Android SDK v5.2.1](https://github.com/CleverTap/clevertap-android-sdk/releases/tag/corev5.2.1_xpsv1.5.4). This supported version includes support for Custom Proxy Domain functionality. Check usage for cordova android [here](docs/Integrate-Android.md#integrate-custom-proxy-domain).
+
+**iOS specific**
+* Supports [CleverTap iOS SDK v5.2.2](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/5.2.2). This supported version includes support for Custom Proxy Domain functionality. Check usage for cordova ios [here](docs/Integrate-iOS.md#integrate-custom-proxy-domain).
+
+#### Bug Fixes
+* Fixes a crash in iOS 17/Xcode 15 related to alert inapps.
+
+**Common for both android and iOS**
+* Adds new public API `setLocale(String locale)` for in-built support to send the custom locale(i.e.language and country) data to the dashboard.
+* Adds support for Integration Debugger to view errors and events on the dashboard when the debugLevel is set to 3.
+
Version 2.7.1 *(August 17, 2023)*
-------------------------------------------
#### New Features
diff --git a/Samples/Cordova/ExampleProject/config.xml b/Samples/Cordova/ExampleProject/config.xml
index 7bb57f14..d2275d30 100644
--- a/Samples/Cordova/ExampleProject/config.xml
+++ b/Samples/Cordova/ExampleProject/config.xml
@@ -24,8 +24,8 @@
-
-
+
+
diff --git a/Samples/Cordova/ExampleProject/platforms/android/app/src/main/assets/www/js/index.js b/Samples/Cordova/ExampleProject/platforms/android/app/src/main/assets/www/js/index.js
index c481d9db..962e48c7 100644
--- a/Samples/Cordova/ExampleProject/platforms/android/app/src/main/assets/www/js/index.js
+++ b/Samples/Cordova/ExampleProject/platforms/android/app/src/main/assets/www/js/index.js
@@ -16,9 +16,73 @@ function log(param){
}
function setupButtons() {
+ let variables = {
+ 'cordova_var_string': 'cordova_var_string_value',
+ 'cordova_var_map': {
+ cordova_var_map_string: 'cordova_var_map_value',
+ cordova_var_map_float: 10.11,
+ cordova_var_map_nested:{
+ cordova_var_map_nested_float:3.14
+ }
+ },
+ 'cordova_var_int': 6,
+ 'cordova_var_float': 6.9,
+ 'cordova_var_boolean': true
+ };
+
+
let eventsMap = [
+
+ ["title","Android 13 Push Primer"],
+ ["promptPushPrimer",()=> CleverTap.promptPushPrimer({
+ inAppType: 'alert',
+ titleText: 'Get Notified',
+ messageText:
+ 'Please enable notifications on your device to use Push Notifications.',
+ followDeviceOrientation: true,
+ positiveBtnText: 'Allow',
+ negativeBtnText: 'Cancel',
+ backgroundColor: '#FFFFFF',
+ btnBorderColor: '#FF0000',
+ titleTextColor: '#0000FF',
+ messageTextColor: '#000000',
+ btnTextColor: '#FFFFFF',
+ btnBackgroundColor: '#0000FF',
+ btnBorderRadius: '5',
+ imageUrl:"https://icons.iconarchive.com/icons/treetog/junior/64/camera-icon.png",
+ fallbackToSettings: true
+ })
+ ],
+ ["promptForPushPermission",()=> CleverTap.promptForPushPermission(true)],
+ ["isPushPermissionGranted",()=> CleverTap.isPushPermissionGranted(val => log("isPushPermissionGranted value is " + val))],
+
+ ["title","Product Experiences"],
+ ["defineVariables", () => CleverTap.defineVariables(variables)],
+ ["syncVariables", () => CleverTap.syncVariables()],
+ ["syncVariablesinProd", () => CleverTap.syncVariablesinProd()],
+ ["fetchVariables", () => CleverTap.fetchVariables(success => log("fetchVariables success = " + success))],
+ ["getVariable", () => {
+ let key = prompt("Please enter key", "cordova_var_string");
+ CleverTap.getVariable(key,val => log(key+" value is "+JSON.stringify(val)));
+ }
+ ],
+ ["getVariables", () => {
+ CleverTap.getVariables(val => log("getVariables value is "+val.cordova_var_map.cordova_var_map_nested.cordova_var_map_nested_float));
+ }
+ ],
+ ["onVariablesChanged", () => {
+ CleverTap.onVariablesChanged(val => log("onVariablesChanged value is "+JSON.stringify(val)));
+ }
+ ],
+ ["onValueChanged", () => {
+ let key = prompt("Please enter key", "cordova_var_string");
+ CleverTap.onValueChanged(key,val => log("onValueChanged value is "+JSON.stringify(val)));
+ }
+ ],
+
["title","Events"],
["record Event With Name", () => CleverTap.recordEventWithName("foo")],
+ ["set Locale", () => CleverTap.setLocale("en_IN")],
["record Event With NameAndProps", () => CleverTap.recordEventWithNameAndProps("boo", {"bar": "zoo"})],
["record Charged Event With Details And Items", () => CleverTap.recordChargedEventWithDetailsAndItems({
"amount": 300,
@@ -94,14 +158,7 @@ function setupButtons() {
["title","Feature flag"],
["get Feature Flag", () => CleverTap.getFeatureFlag("test", true, val => log("Value is " + val))],
-
- ["title","Product Experiences"],
- ["get Feature Flag", () => CleverTap.getFeatureFlag("test", true, val => log("Value is " + val))],
-
-// defineVariables({
-// "cordova_var_string": "cordova_var_string_value"
-// })],
-
+
["title","Device Identifiers"],
["get CleverTap ID", () => CleverTap.getCleverTapID(val => log("getCleverTapID is " + val))],
@@ -290,8 +347,10 @@ function initListeners() {
CleverTap.deleteInboxMessageForId("messageId")
CleverTap.deleteInboxMessagesForIds(["id1", "id2"])
CleverTap.markReadInboxMessageForId("messageId")
+ CleverTap.markReadInboxMessagesForIds(["id1", "id2"])
CleverTap.pushInboxNotificationViewedEventForId("messageId")
CleverTap.pushInboxNotificationClickedEventForId("messageId")
+ CleverTap.dismissInbox()
}
)
document.addEventListener('onCleverTapInboxMessagesDidUpdate', () => {
@@ -306,7 +365,7 @@ function initListeners() {
)
document.addEventListener('onCleverTapInboxItemClick', e => {
log("onCleverTapInboxItemClick")
- log(e.customExtras)
+ log(JSON.stringify(e))
}
)
@@ -338,6 +397,15 @@ function initListeners() {
log(e.customExtras)
}
)
+ document.addEventListener('onCleverTapPushPermissionResponseReceived', e => {
+ log("onCleverTapPushPermissionResponseReceived")
+ log(e.accepted)
+ })
+
+ document.addEventListener('onCleverTapInAppNotificationShow', e => {
+ log("onCleverTapInAppNotificationShow")
+ log(e.customExtras)
+ })
}
diff --git a/Samples/Cordova/ExampleProject/platforms/android/app/src/main/assets/www/plugins/clevertap-cordova/www/CleverTap.js b/Samples/Cordova/ExampleProject/platforms/android/app/src/main/assets/www/plugins/clevertap-cordova/www/CleverTap.js
index 423025e4..a85b20e8 100644
--- a/Samples/Cordova/ExampleProject/platforms/android/app/src/main/assets/www/plugins/clevertap-cordova/www/CleverTap.js
+++ b/Samples/Cordova/ExampleProject/platforms/android/app/src/main/assets/www/plugins/clevertap-cordova/www/CleverTap.js
@@ -7,6 +7,9 @@ cordova.define("clevertap-cordova.CleverTap", function(require, exports, module)
//
var CleverTap = function () {
+ const libName = 'Cordova';
+ const libVersion = 20702;
+ cordova.exec(null, null, "CleverTapPlugin", "setLibrary", [libName, libVersion]);
}
/*******************
@@ -74,11 +77,6 @@ CleverTap.prototype.setPushHuaweiToken = function (token) {
cordova.exec(null, null, "CleverTapPlugin", "setPushHuaweiTokenAsString", [token]);
}
-// Change xiaomiCredentials
-CleverTap.prototype.changeXiaomiCredentials = function (xiaomiAppID, xiaomiAppKey) {
- cordova.exec(null, null, "CleverTapPlugin", "changeXiaomiCredentials", [xiaomiAppID, xiaomiAppKey]);
-}
-
//Create Notification Channel for Android O
CleverTap.prototype.createNotification = function (extras) {
@@ -455,10 +453,22 @@ CleverTap.prototype.deleteInboxMessageForId = function (messageId) {
cordova.exec(null, null, "CleverTapPlugin", "deleteInboxMessageForId", [messageId]);
}
+CleverTap.prototype.deleteInboxMessagesForIds = function (messageIds) {
+ cordova.exec(null, null, "CleverTapPlugin", "deleteInboxMessagesForIds", [messageIds]);
+}
+
CleverTap.prototype.markReadInboxMessageForId = function (messageId) {
cordova.exec(null, null, "CleverTapPlugin", "markReadInboxMessageForId", [messageId]);
}
+CleverTap.prototype.markReadInboxMessagesForIds = function (messageIds) {
+ cordova.exec(null, null, "CleverTapPlugin", "markReadInboxMessagesForIds", [messageIds]);
+}
+
+CleverTap.prototype.dismissInbox= function () {
+ cordova.exec(null, null, "CleverTapPlugin", "dismissInbox", []);
+}
+
CleverTap.prototype.pushInboxNotificationViewedEventForId = function (messageId) {
cordova.exec(null, null, "CleverTapPlugin", "pushInboxNotificationViewedEventForId", [messageId]);
}
@@ -514,6 +524,9 @@ CleverTap.prototype.pushDisplayUnitClickedEventForID = function(unitId){
/****************************
* Feature Flag methods
****************************/
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.getFeatureFlag = function(name,defaultValue,successCallback){
cordova.exec(successCallback, null, "CleverTapPlugin", "getFeatureFlag", [name,defaultValue]);
}
@@ -521,54 +534,179 @@ CleverTap.prototype.getFeatureFlag = function(name,defaultValue,successCallback)
/****************************
* Product Config methods
****************************/
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.setDefaultsMap = function(jsonMap){
cordova.exec(null, null, "CleverTapPlugin", "setDefaultsMap", [jsonMap]);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.fetch = function(){
cordova.exec(null, null, "CleverTapPlugin", "fetch", []);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.fetchWithMinimumFetchIntervalInSeconds = function(interval){
cordova.exec(null, null, "CleverTapPlugin", "fetchWithMinimumFetchIntervalInSeconds", [interval]);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.activate = function(){
cordova.exec(null, null, "CleverTapPlugin", "activate", []);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.fetchAndActivate = function(){
cordova.exec(null, null, "CleverTapPlugin", "fetchAndActivate", []);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.setMinimumFetchIntervalInSeconds = function(interval){
cordova.exec(null, null, "CleverTapPlugin", "setMinimumFetchIntervalInSeconds", [interval]);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.getLastFetchTimeStampInMillis = function(successCallback){
cordova.exec(successCallback, null, "CleverTapPlugin", "getLastFetchTimeStampInMillis", []);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.getString = function(key,successCallback){
cordova.exec(successCallback, null, "CleverTapPlugin", "getString", [key]);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.getBoolean = function(key,successCallback){
cordova.exec(successCallback, null, "CleverTapPlugin", "getBoolean", [key]);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.getLong = function(key,successCallback){
cordova.exec(successCallback, null, "CleverTapPlugin", "getLong", [key]);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.getDouble = function(key,successCallback){
cordova.exec(successCallback, null, "CleverTapPlugin", "getDouble", [key]);
}
+/**
+ * @deprecated - Since version 2.7.0 and will be removed in the future versions of this SDK.
+ */
CleverTap.prototype.reset = function(){
cordova.exec(null, null, "CleverTapPlugin", "reset", []);
}
+
+/****************************
+ * Product Experiences methods
+ ****************************/
+
+/**
+ Uploads variables to the server. Requires Development/Debug build/configuration.
+*/
+CleverTap.prototype.syncVariables = function(){
+ cordova.exec(null, null, "CleverTapPlugin", "syncVariables", []);
+}
+
+/**
+Uploads variables to the server.
+@param {boolean} isProduction Provide `true` if variables must be sync in Productuon build/configuration.
+*/
+CleverTap.prototype.syncVariablesinProd = function(isProduction){
+ cordova.exec(null, null, "CleverTapPlugin", "syncVariablesinProd", [isProduction]);
+}
+
+/**
+Forces variables to update from the server.
+*/
+CleverTap.prototype.fetchVariables = function(successCallback){
+ cordova.exec(successCallback, null, "CleverTapPlugin", "fetchVariables", []);
+}
+
+/**
+Create variables.
+@param {object} variables The JSON Object specifying the varibles to be created.
+*/
+CleverTap.prototype.defineVariables = function (variables) {
+ cordova.exec(null, null, "CleverTapPlugin", "defineVariables", [variables]);
+}
+
+/**
+Get a variable or a group for the specified name.
+@param {string} name - name.
+*/
+CleverTap.prototype.getVariable = function (name, successCallback) {
+ cordova.exec(successCallback, null, "CleverTapPlugin", "getVariable", [name]);
+}
+
+/**
+Get all variables via a JSON object.
+*/
+CleverTap.prototype.getVariables = function (successCallback) {
+ cordova.exec(successCallback, null, "CleverTapPlugin", "getVariables", []);
+}
+
+ /**
+Adds a callback to be invoked when variables are initialised with server values. Will be called each time new values are fetched.
+@param {function} handler The callback to add
+*/
+CleverTap.prototype.onVariablesChanged = function (handler) {
+ cordova.exec(handler, null, "CleverTapPlugin", "onVariablesChanged", []);
+}
+
+/**
+Called when the value of the variable changes.
+@param {name} string the name of the variable
+@param {function} handler The callback to add
+*/
+CleverTap.prototype.onValueChanged = function (name, handler) {
+ cordova.exec(handler, null, "CleverTapPlugin", "onValueChanged", [name]);
+}
+
+/****************************
+ * Android 13 Push Primer
+ ****************************/
+
+CleverTap.prototype.promptPushPrimer = function(localInAppObject){
+ cordova.exec(null, null, "CleverTapPlugin", "promptPushPrimer", [localInAppObject]);
+}
+
+CleverTap.prototype.promptForPushPermission = function(showFallbackSettings){
+ cordova.exec(null, null, "CleverTapPlugin", "promptForPushPermission", [showFallbackSettings]);
+}
+
+CleverTap.prototype.isPushPermissionGranted = function(successCallback){
+ cordova.exec(successCallback, null, "CleverTapPlugin", "isPushPermissionGranted", []);
+}
+
+// Set Locale
+// locale = string
+CleverTap.prototype.setLocale = function (locale) {
+ cordova.exec(null, null, "CleverTapPlugin", "setLocale", [locale]);
+}
+
function convertDateToEpochInProperties(items){
//Conversion of date object in suitable CleverTap format
diff --git a/Samples/Cordova/ExampleProject/platforms/android/app/src/main/java/com/clevertap/cordova/CleverTapPlugin.java b/Samples/Cordova/ExampleProject/platforms/android/app/src/main/java/com/clevertap/cordova/CleverTapPlugin.java
index 811104bb..a3d8217b 100644
--- a/Samples/Cordova/ExampleProject/platforms/android/app/src/main/java/com/clevertap/cordova/CleverTapPlugin.java
+++ b/Samples/Cordova/ExampleProject/platforms/android/app/src/main/java/com/clevertap/cordova/CleverTapPlugin.java
@@ -16,15 +16,27 @@
import android.util.Log;
import android.location.Location;
+import androidx.annotation.NonNull;
+import com.clevertap.android.sdk.PushPermissionResponseListener;
+import com.clevertap.android.sdk.inapp.CTInAppNotification;
+import com.clevertap.android.sdk.inapp.CTLocalInApp;
import com.clevertap.android.sdk.pushnotification.CTPushNotificationListener;
import com.clevertap.android.sdk.pushnotification.amp.CTPushAmpListener;
+import com.clevertap.android.sdk.variables.CTVariableUtils;
+import com.clevertap.android.sdk.variables.Var;
+import com.clevertap.android.sdk.variables.callbacks.VariableCallback;
+import com.clevertap.android.sdk.variables.callbacks.VariablesChangedCallback;
+import java.util.Objects;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.PluginResult;
+import org.apache.cordova.PluginResult.Status;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -62,12 +74,14 @@
public class CleverTapPlugin extends CordovaPlugin implements SyncListener, InAppNotificationListener, CTInboxListener,
InboxMessageButtonListener, InAppNotificationButtonListener, DisplayUnitListener,
- CTFeatureFlagsListener, CTProductConfigListener, CTPushNotificationListener, CTPushAmpListener, InboxMessageListener {
+ CTFeatureFlagsListener, CTProductConfigListener, CTPushNotificationListener, CTPushAmpListener, InboxMessageListener,
+ PushPermissionResponseListener {
private static final String LOG_TAG = "CLEVERTAP_PLUGIN";
private static String CLEVERTAP_API_ERROR;
private static CleverTapAPI cleverTap;
private boolean callbackDone = false;
+ public static Map variables = new HashMap<>();
@Override
@@ -86,6 +100,7 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
cleverTap.setCTProductConfigListener(this);
cleverTap.setCTPushNotificationListener(this);
cleverTap.setCTPushAmpListener(this);
+ cleverTap.registerPushPermissionNotificationResponseListener(this);
cleverTap.setLibrary("Cordova");
try {
@@ -111,6 +126,10 @@ public void onNewIntent(Intent intent) {
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_VIEW)) {
Uri data = intent.getData();
if (data != null) {
+ if(!isDeepLinkValid(data)){
+ Log.w(LOG_TAG, "Found malicious deep link. Not processing further.");
+ return;
+ }
final String json = "{'deeplink':'" + data.toString() + "'}";
cordova.getActivity().runOnUiThread(new Runnable() {
@@ -255,18 +274,6 @@ public void run() {
}
});
return true;
- } else if (action.equals("changeXiaomiCredentials")) {
- final String xiaomiAppID = args.getString(0);
- final String xiaomiAppKey = args.getString(1);
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- cleverTap.changeXiaomiCredentials(xiaomiAppID, xiaomiAppKey);
- PluginResult _result = new PluginResult(PluginResult.Status.NO_RESULT);
- _result.setKeepCallback(true);
- callbackContext.sendPluginResult(_result);
- }
- });
- return true;
} else if (action.equals("createNotification")) {
final String extras = args.getString(0);
JSONObject json = new JSONObject(extras);
@@ -1396,6 +1403,65 @@ public void run() {
}
});
return true;
+ } else if (action.equals("markReadInboxMessagesForIds")) {
+ JSONArray jsonArray = null;
+ if (args.length() == 1) {
+ jsonArray = args.getJSONArray(0);
+ } else {
+ haveError = true;
+ errorMsg = "Expected 1 argument";
+ }
+ if (!haveError) {
+ final JSONArray finalJsonArray = jsonArray;
+ cordova.getThreadPool().execute(() -> {
+ try {
+ cleverTap.markReadInboxMessagesForIDs((ArrayList) toStringList(finalJsonArray));
+
+ PluginResult _result = new PluginResult(Status.NO_RESULT);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ } catch (Exception e) {
+ PluginResult _result = new PluginResult(Status.ERROR, e.getLocalizedMessage());
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
+ return true;
+ }
+ } else if (action.equals("deleteInboxMessagesForIds")) {
+ JSONArray jsonArray = null;
+ if (args.length() == 1) {
+ jsonArray = args.getJSONArray(0);
+ } else {
+ haveError = true;
+ errorMsg = "Expected 1 argument";
+ }
+ if (!haveError) {
+ final JSONArray finalJsonArray = jsonArray;
+ cordova.getThreadPool().execute(() -> {
+ try {
+ cleverTap.deleteInboxMessagesForIDs((ArrayList) toStringList(finalJsonArray));
+
+ PluginResult _result = new PluginResult(Status.NO_RESULT);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ } catch (Exception e) {
+ PluginResult _result = new PluginResult(Status.ERROR, e.getLocalizedMessage());
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
+ return true;
+ }
+ } else if (action.equals("dismissInbox")) {
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ cleverTap.dismissAppInbox();
+ PluginResult _result = new PluginResult(PluginResult.Status.NO_RESULT);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
} else if (action.equals("pushInboxNotificationViewedEventForId")) {
final String messageId = (args.length() == 1 ? args.getString(0) : "");
@@ -1676,6 +1742,251 @@ public void run() {
}
});
return true;
+ } else if (action.equals("promptPushPrimer")) {
+ JSONObject pushPrimerJsonObject = null;
+ if (args.length() == 1) {
+ if (!args.isNull(0)) {
+ try {
+ pushPrimerJsonObject = processPushPrimerArgument(args.getJSONObject(0));
+ if (pushPrimerJsonObject == null)
+ {
+ haveError = true;
+ errorMsg = "Invalid parameters in push primer config";
+ }
+ } catch (Exception e) {
+ haveError = true;
+ errorMsg = e.getLocalizedMessage();
+ }
+ } else {
+ haveError = true;
+ errorMsg = "object passed to promptPushPrimer can not be null!";
+ }
+ } else {
+ haveError = true;
+ errorMsg = "Expected 1 argument";
+ }
+
+ if (!haveError) {
+ final JSONObject finalPushPrimerJsonObject = pushPrimerJsonObject;
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ cleverTap.promptPushPrimer(finalPushPrimerJsonObject);
+ PluginResult _result = new PluginResult(PluginResult.Status.NO_RESULT);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
+ return true;
+ }
+ } else if (action.equals("promptForPushPermission")) {
+ boolean showFallbackSettings = false;
+
+ if (args.length() == 1) {
+ showFallbackSettings = args.getBoolean(0);
+ } else {
+ haveError = true;
+ errorMsg = "Expected 1 argument";
+ }
+ if (!haveError) {
+ final boolean finalShowFallbackSettings = showFallbackSettings;
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ cleverTap.promptForPushPermission(finalShowFallbackSettings);
+ PluginResult _result = new PluginResult(PluginResult.Status.NO_RESULT);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
+ return true;
+ }
+ } else if (action.equals("isPushPermissionGranted")) {
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ boolean value = cleverTap.isPushPermissionGranted();
+ PluginResult _result = new PluginResult(PluginResult.Status.OK, value);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
+ return true;
+ } else if (action.equals("setLibrary")) {
+ String libName = args.getString(0);
+ int libVersion = args.getInt(1);
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ cleverTap.setCustomSdkVersion(libName,libVersion);
+ PluginResult _result = new PluginResult(PluginResult.Status.NO_RESULT);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
+ return true;
+ } else if (action.equals("syncVariables")) {
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ cleverTap.syncVariables();
+ PluginResult _result = new PluginResult(PluginResult.Status.NO_RESULT);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
+ return true;
+ } else if (action.equals("syncVariablesinProd")) {
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ Log.d(LOG_TAG, "syncVariablesinProd is no-op in Android");
+ PluginResult _result = new PluginResult(PluginResult.Status.NO_RESULT);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
+ return true;
+ } else if (action.equals("fetchVariables")) {
+ cordova.getThreadPool().execute(() -> {
+ cleverTap.fetchVariables(isSuccess -> {
+ PluginResult _result = new PluginResult(PluginResult.Status.OK, isSuccess);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ });
+
+ });
+ return true;
+ } else if (action.equals("defineVariables")) {
+ Map variablesMap = null;
+ if (args.length() == 1) {
+ if (!args.isNull(0)) {
+ try {
+ variablesMap = toMap(args.getJSONObject(0));
+ } catch (Exception e) {
+ haveError = true;
+ errorMsg = e.getLocalizedMessage();
+ }
+ } else {
+ haveError = true;
+ errorMsg = "object passed to defineVariables can not be null!";
+ }
+ } else {
+ haveError = true;
+ errorMsg = "Expected 1 argument";
+ }
+
+ if (!haveError) {
+ final Map finalVariablesJsonObject = variablesMap;
+ cordova.getThreadPool().execute(() -> {
+ for (Map.Entry entry : finalVariablesJsonObject.entrySet()) {
+ String key = entry.getKey();
+ Object value = entry.getValue();
+ variables.put(key, cleverTap.defineVariable(key, value));
+ }
+ PluginResult _result = new PluginResult(PluginResult.Status.NO_RESULT);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ });
+ return true;
+ }
+ } else if (action.equals("getVariable")) {
+ String variableName = null;
+
+ if (args.length() == 1) {
+ variableName = args.getString(0);
+ } else {
+ haveError = true;
+ errorMsg = "Expected 1 argument";
+ }
+
+ if (!haveError) {
+ final String finalVariableName = variableName;
+ cordova.getThreadPool().execute(() -> {
+ try {
+ Object value = getVariableValue(finalVariableName);
+ PluginResult _result = getPluginResult(Status.OK, value);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ } catch (Exception e) {
+ PluginResult _result = new PluginResult(Status.ERROR, e.getLocalizedMessage());
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
+ return true;
+ }
+ } else if (action.equals("getVariables")) {
+ cordova.getThreadPool().execute(() -> {
+ JSONObject jsonVariables = getVariablesAsJson();
+ PluginResult _result = new PluginResult(PluginResult.Status.OK, jsonVariables);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ });
+ return true;
+ } else if (action.equals("onVariablesChanged")) {
+ cordova.getThreadPool().execute(() -> {
+ cleverTap.addVariablesChangedCallback(new VariablesChangedCallback() {
+ @Override
+ public void variablesChanged() {
+ JSONObject jsonVariables = getVariablesAsJson();
+ PluginResult _result = new PluginResult(PluginResult.Status.OK,jsonVariables);
+ _result.setKeepCallback(true);
+ callbackContext.sendPluginResult(_result);
+ }
+ });
+ });
+ return true;
+ } else if (action.equals("onValueChanged")) {
+
+ String variableName = null;
+
+ if (args.length() == 1) {
+ variableName = args.getString(0);
+ } else {
+ haveError = true;
+ errorMsg = "Expected 1 argument";
+ }
+
+ if (!haveError) {
+ final String finalVariableName = variableName;
+ cordova.getThreadPool().execute(() -> {
+ try {
+ if (variables.containsKey(finalVariableName)) {
+ Var