diff --git a/Countly.js b/Countly.js index 1cc731c..8916176 100644 --- a/Countly.js +++ b/Countly.js @@ -7,34 +7,34 @@ Countly.isDebug = false; Countly.isInitCalled = false; if (window.cordova.platformId == "android") { Countly.isAndroid = true; - Countly.messagingMode = {"TEST": "2", "PRODUCTION": "0"}; + Countly.messagingMode = { "TEST": "2", "PRODUCTION": "0" }; } if (window.cordova.platformId == "ios") { Countly.isiOS = true; - Countly.messagingMode = {"TEST": "1", "PRODUCTION": "0", "ADHOC": "2"}; + Countly.messagingMode = { "TEST": "1", "PRODUCTION": "0", "ADHOC": "2" }; } // countly initialization -Countly.init = function(serverUrl,appKey, deviceId){ +Countly.init = function (serverUrl, appKey, deviceId) { var args = []; Countly.serverUrl = serverUrl; Countly.appKey = appKey; args.push(serverUrl || ""); args.push(appKey || ""); - if(deviceId){ + if (deviceId) { args.push(deviceId || ""); }; Countly.isInitCalled = true; - return new Promise((resolve,reject) => { - cordova.exec(resolve,reject,"CountlyCordova","init",args); + return new Promise((resolve, reject) => { + cordova.exec(resolve, reject, "CountlyCordova", "init", args); }); } -Countly.isInitialized = function(){ - return new Promise((resolve,reject) => { - cordova.exec(resolve,reject,"CountlyCordova","isInitialized",[]); +Countly.isInitialized = function () { + return new Promise((resolve, reject) => { + cordova.exec(resolve, reject, "CountlyCordova", "isInitialized", []); }); } @@ -45,84 +45,83 @@ Countly.isInitialized = function(){ * @param {Map} segments - allows to add optional segmentation, * Supported data type for segments values are String, int, double and bool */ -Countly.recordView = function(recordView, segments){ +Countly.recordView = function (recordView, segments) { var args = []; args.push(String(recordView) || ""); - if(!segments){ + if (!segments) { segments = {}; } - for(var key in segments){ + for (var key in segments) { args.push(key); args.push(segments[key]); } - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","recordView",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "recordView", args); }; /** * Set to true if you want to enable countly internal debugging logs * Should be call before Countly init */ -Countly.setLoggingEnabled = function(isDebug = true){ +Countly.setLoggingEnabled = function (isDebug = true) { isDebug = isDebug.toString() == "true" ? true : false; - if(this.isInitCalled) { - if(Countly.isDebug){ + if (this.isInitCalled) { + if (Countly.isDebug) { console.warn("setLoggingEnabled, should be call before init"); } return; } Countly.isDebug = isDebug; var args = [isDebug.toString()]; - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","setLoggingEnabled",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "setLoggingEnabled", args); } // countly sending user data -Countly.setUserData = function(userData){ +Countly.setUserData = function (userData) { var message = null; - if(!userData) { + if (!userData) { message = "User profile data should not be null or undefined"; log("setUserData", message, logLevel.ERROR); return message; } - if(typeof userData !== 'object'){ + if (typeof userData !== 'object') { message = "unsupported data type of user data '" + (typeof userData) + "'"; log("setUserData", message, logLevel.WARNING); return message; } var args = []; - for(var key in userData){ - if (typeof userData[key] != "string" && key.toString() != "byear") - { + for (var key in userData) { + if (typeof userData[key] != "string" && key.toString() != "byear") { message = "skipping value for key '" + key.toString() + "', due to unsupported data type '" + (typeof userData[key]) + "', its data type should be 'string'"; log("setUserData", message, logLevel.WARNING); } - + } - if(userData.org && !userData.organization) { + if (userData.org && !userData.organization) { userData.organization = userData.org; delete userData.org; } - if(userData.byear) { + if (userData.byear) { userData.byear = userData.byear.toString(); } args.push(userData); - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","setuserdata",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "setuserdata", args); } // countly start for android -Countly.start = function(){ - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","start",[]); +Countly.start = function () { + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "start", []); } // countly stop for android -Countly.stop = function(){ - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","stop",[]); +Countly.stop = function () { + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "stop", []); } // countly halt for android -Countly.halt = function(){ - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","halt",[]); +Countly.halt = function () { + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "halt", []); } // countly manualSessionHandling for android @@ -156,8 +155,8 @@ Countly.halt = function(){ * This method will ask for permission, enables push notification and send push token to countly server. * Should be call after Countly init */ -Countly.askForNotificationPermission = function(){ - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","askForNotificationPermission",[]); +Countly.askForNotificationPermission = function () { + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "askForNotificationPermission", []); } /** @@ -165,8 +164,8 @@ Countly.askForNotificationPermission = function(){ * Set callback to receive push notifications * @param {callback listner } callback */ -Countly.onNotification = function(callback){ - cordova.exec(callback,callback,"CountlyCordova","registerForNotification",[]); +Countly.onNotification = function (callback) { + cordova.exec(callback, callback, "CountlyCordova", "registerForNotification", []); } /** @@ -174,25 +173,25 @@ Countly.onNotification = function(callback){ * Set Push notification messaging mode * Should be call after Countly init */ -Countly.pushTokenType = function(tokenType){ - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","pushTokenType",[tokenType]); +Countly.pushTokenType = function (tokenType) { + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "pushTokenType", [tokenType]); } // countly deviceready for testing purpose -Countly.deviceready = function(){ +Countly.deviceready = function () { Countly.ready = true; //testing } // countly dummy success and error event -Countly.onSuccess = function(result){ - if(Countly.isDebug){ +Countly.onSuccess = function (result) { + if (Countly.isDebug) { console.log("Countly.onSuccess"); console.log(result); } } -Countly.onError = function(error){ - if(Countly.isDebug){ +Countly.onError = function (error) { + if (Countly.isDebug) { console.log("Countly.onError"); console.log(error); } @@ -201,17 +200,17 @@ Countly.onError = function(error){ // 2017 -Countly.setOptionalParametersForInitialization = function(options){ +Countly.setOptionalParametersForInitialization = function (options) { var args = []; options.latitude = String(options.latitude); options.longitude = String(options.longitude); - if(options.latitude && !options.latitude.match('\\.')){ - options.latitude += ".00"; + if (options.latitude && !options.latitude.match('\\.')) { + options.latitude += ".00"; } - if(options.longitude && !options.longitude.match('\\.')){ - options.longitude += ".00"; + if (options.longitude && !options.longitude.match('\\.')) { + options.longitude += ".00"; } args.push(options.city || ""); @@ -220,7 +219,7 @@ Countly.setOptionalParametersForInitialization = function(options){ args.push(options.longitude || "0.0"); args.push(String(options.ipAddress) || "0.0.0.0"); - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","setOptionalParametersForInitialization",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "setOptionalParametersForInitialization", args); } /** @@ -232,23 +231,23 @@ Countly.setOptionalParametersForInitialization = function(options){ * @param {IP address of user's} ipAddress * */ -Countly.setLocationInit = function(countryCode, city, location, ipAddress){ +Countly.setLocationInit = function (countryCode, city, location, ipAddress) { var args = []; args.push(countryCode || "null"); args.push(city || "null"); args.push(location || "null"); args.push(ipAddress || "null"); - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","setLocationInit",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "setLocationInit", args); } -Countly.setLocation = function(latitude, longitude, countryCode, city, ipAddress){ +Countly.setLocation = function (latitude, longitude, countryCode, city, ipAddress) { var args = []; - var location = latitude + " , " + longitude; + var location = latitude + " , " + longitude; args.push(countryCode || "null"); args.push(city || "null"); args.push(location || "null"); args.push(ipAddress || "null"); - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","setLocation",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "setLocation", args); } /** @@ -256,28 +255,28 @@ Countly.setLocation = function(latitude, longitude, countryCode, city, ipAddress * Get currently used device Id. * Should be call after Countly init * */ -Countly.getCurrentDeviceId = function(onSuccess, onError){ +Countly.getCurrentDeviceId = function (onSuccess, onError) { Countly.isInitialized().then((result) => { - if(result != "true") { - if(Countly.isDebug){ + if (result != "true") { + if (Countly.isDebug) { console.warn("'getCurrentDeviceId, init must be called before getCurrentDeviceId'"); } return; } - },(err) => { + }, (err) => { console.error(err); }); - cordova.exec(onSuccess, onError,"CountlyCordova","getCurrentDeviceId",[]); + cordova.exec(onSuccess, onError, "CountlyCordova", "getCurrentDeviceId", []); } -Countly.changeDeviceId = function(newDeviceID, onServer){ - if(onServer === false){ +Countly.changeDeviceId = function (newDeviceID, onServer) { + if (onServer === false) { onServer = "0"; - }else{ + } else { onServer = "1"; } newDeviceID = newDeviceID.toString() || ""; - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","changeDeviceId",[newDeviceID, onServer]); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "changeDeviceId", [newDeviceID, onServer]); }; Countly.isCrashReportingEnabled = false; @@ -286,24 +285,24 @@ Countly.isCrashReportingEnabled = false; * Enable crash reporting to report unhandled crashes to Countly * Should be call before Countly init */ -Countly.enableCrashReporting = function(){ +Countly.enableCrashReporting = function () { Countly.isCrashReportingEnabled = true; - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","enableCrashReporting",[]); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "enableCrashReporting", []); } -Countly.addCrashLog = function(crashLog){ - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","addCrashLog",[crashLog || ""]); +Countly.addCrashLog = function (crashLog) { + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "addCrashLog", [crashLog || ""]); }; -Countly.logException = function(exception, nonfatal, segments){ +Countly.logException = function (exception, nonfatal, segments) { var exceptionString = ""; if (Array.isArray(exception)) { - for(var i=0, il=exception.length; i { - if(result != "true") { - if(Countly.isDebug){ - console.warn('[CountlyCordova] appLoadingFinished, init must be called before appLoadingFinished'); + if (result != "true") { + if (Countly.isDebug) { + console.warn('[CountlyCordova] appLoadingFinished, init must be called before appLoadingFinished'); + } + return; } - return; - } - },(err) => { + }, (err) => { console.error(err); }); - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","appLoadingFinished",[]); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "appLoadingFinished", []); } /** * Get a list of available feedback widgets for this device ID */ -Countly.getFeedbackWidgets = function(){ - return new Promise((resolve,reject) => { - cordova.exec(resolve,reject,"CountlyCordova","getFeedbackWidgets",[]); +Countly.getFeedbackWidgets = function () { + return new Promise((resolve, reject) => { + cordova.exec(resolve, reject, "CountlyCordova", "getFeedbackWidgets", []); }); } @@ -663,22 +662,22 @@ Countly.getFeedbackWidgets = function(){ * * @param {Object} feedbackWidget - feeback Widget with id, type and name * @param {String} closeButtonText - text for cancel/close button - */ -Countly.presentFeedbackWidget = function(feedbackWidget, buttonText){ - if(!feedbackWidget) { - if(Countly.isDebug) { + */ +Countly.presentFeedbackWidget = function (feedbackWidget, buttonText) { + if (!feedbackWidget) { + if (Countly.isDebug) { console.error("[CountlyCordova] presentFeedbackWidget, feedbackWidget should not be null or undefined"); } return "feedbackWidget should not be null or undefined"; } - if(!feedbackWidget.id) { - if(Countly.isDebug){ + if (!feedbackWidget.id) { + if (Countly.isDebug) { console.error("[CountlyCordova] presentFeedbackWidget, feedbackWidget id should not be null or empty"); } return "FeedbackWidget id should not be null or empty"; } - if(!feedbackWidget.type) { - if(Countly.isDebug){ + if (!feedbackWidget.type) { + if (Countly.isDebug) { console.error("[CountlyCordova] presentFeedbackWidget, feedbackWidget type should not be null or empty"); } return "FeedbackWidget type should not be null or empty"; @@ -687,7 +686,7 @@ Countly.presentFeedbackWidget = function(feedbackWidget, buttonText){ var widgetType = feedbackWidget.type; var widgetName = feedbackWidget.name || ""; buttonText = buttonText || ""; - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","presentFeedbackWidget",[widgetId, widgetType, widgetName, buttonText]); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "presentFeedbackWidget", [widgetId, widgetType, widgetName, buttonText]); } /** @@ -695,8 +694,8 @@ Countly.presentFeedbackWidget = function(feedbackWidget, buttonText){ * In request queue, if there are any request whose app key is different than the current app key, * these requests' app key will be replaced with the current app key. */ -Countly.replaceAllAppKeysInQueueWithCurrentAppKey = function() { - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","replaceAllAppKeysInQueueWithCurrentAppKey",[]); +Countly.replaceAllAppKeysInQueueWithCurrentAppKey = function () { + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "replaceAllAppKeysInQueueWithCurrentAppKey", []); } /** @@ -704,15 +703,15 @@ Countly.replaceAllAppKeysInQueueWithCurrentAppKey = function() { * In request queue, if there are any request whose app key is different than the current app key, * these requests will be removed from request queue. */ -Countly.removeDifferentAppKeysFromQueue = function() { - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","removeDifferentAppKeysFromQueue",[]); +Countly.removeDifferentAppKeysFromQueue = function () { + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "removeDifferentAppKeysFromQueue", []); } // Push Notification -Countly.sendPushToken = function(options){ +Countly.sendPushToken = function (options) { var args = []; args.push(options.token || ""); - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","sendPushToken",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "sendPushToken", args); } // Push Notification @@ -721,8 +720,8 @@ Countly.sendPushToken = function(options){ * Set to "true" if you want HTTP POST to be used for all requests * Should be call before Countly init */ -Countly.setHttpPostForced = function(boolean){ - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","setHttpPostForced",[boolean == true?"1": "0"]); +Countly.setHttpPostForced = function (boolean) { + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "setHttpPostForced", [boolean == true ? "1" : "0"]); } /** @@ -731,10 +730,10 @@ Countly.setHttpPostForced = function(boolean){ * For iOS use "recordAttributionID" instead of "enableAttribution" * Should be call before Countly init */ -Countly.enableAttribution = function(attributionID = "") { +Countly.enableAttribution = function (attributionID = "") { if (Countly.isiOS) { - if(attributionID == "") { - if(Countly.isDebug){ + if (attributionID == "") { + if (Countly.isDebug) { console.error("[CountlyReactNative] enableAttribution, attribution Id for iOS can't be empty string"); } return "attribution Id for iOS can't be empty string"; @@ -742,7 +741,7 @@ Countly.enableAttribution = function(attributionID = "") { Countly.recordAttributionID(attributionID); } else { - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","enableAttribution",[]); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "enableAttribution", []); } } @@ -752,42 +751,42 @@ Countly.enableAttribution = function(attributionID = "") { * Currently implemented for iOS only * For Android just call the enableAttribution to enable campaign attribution. */ -Countly.recordAttributionID = function(attributionID){ +Countly.recordAttributionID = function (attributionID) { if (!Countly.isiOS) return "recordAttributionID : To be implemented"; var args = []; args.push(attributionID); - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","recordAttributionID",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "recordAttributionID", args); } -Countly.startTrace = function(traceKey){ +Countly.startTrace = function (traceKey) { var args = []; args.push(traceKey); - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","startTrace",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "startTrace", args); } -Countly.cancelTrace = function(traceKey){ +Countly.cancelTrace = function (traceKey) { var args = []; args.push(traceKey); - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","cancelTrace",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "cancelTrace", args); } -Countly.clearAllTraces = function(traceKey){ +Countly.clearAllTraces = function (traceKey) { var args = []; - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","clearAllTraces",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "clearAllTraces", args); } -Countly.endTrace = function(traceKey, customMetric){ +Countly.endTrace = function (traceKey, customMetric) { var args = []; args.push(traceKey); customMetric = customMetric || {}; - for(var key in customMetric){ + for (var key in customMetric) { args.push(key.toString()); args.push(customMetric[key].toString()); } - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","endTrace",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "endTrace", args); } -Countly.recordNetworkTrace = function(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime){ +Countly.recordNetworkTrace = function (networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime) { var args = []; args.push(networkTraceKey); args.push(responseCode.toString()); @@ -795,7 +794,7 @@ Countly.recordNetworkTrace = function(networkTraceKey, responseCode, requestPayl args.push(responsePayloadSize.toString()); args.push(startTime.toString()); args.push(endTime.toString()); - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","recordNetworkTrace",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "recordNetworkTrace", args); } /** @@ -803,40 +802,40 @@ Countly.recordNetworkTrace = function(networkTraceKey, responseCode, requestPayl * Enable APM features, which includes the recording of app start time. * Should be call before Countly init */ -Countly.enableApm = function(){ +Countly.enableApm = function () { var args = []; - cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","enableApm",args); + cordova.exec(Countly.onSuccess, Countly.onError, "CountlyCordova", "enableApm", args); } window.Countly = Countly; document.addEventListener("deviceready", Countly.deviceready, false); -logLevel = {"VERBOSE": "1", "DEBUG": "2", "INFO": "3", "WARNING": "4", "ERROR": "5"}; +logLevel = { "VERBOSE": "1", "DEBUG": "2", "INFO": "3", "WARNING": "4", "ERROR": "5" }; /** * Print log if logging is enabled * @param {String} functionName : name of function from where value is validating. * @param {String} message : log message * @param {String} logLevel : log level (INFO, DEBUG, VERBOSE, WARNING, ERROR) */ - log = (functionName, message, logLevel = logLevel.DEBUG) => { - if(Countly.isDebug) { +log = (functionName, message, logLevel = logLevel.DEBUG) => { + if (Countly.isDebug) { var logMessage = "[CountlyCordova] " + functionName + ", " + message; - switch (logLevel) { + switch (logLevel) { case logLevel.VERBOSE: console.log(logMessage); - break; + break; case logLevel.DEBUG: console.debug(logMessage); - break; + break; case logLevel.INFO: console.info(logMessage); - break; + break; case logLevel.WARNING: console.warn(logMessage); - break; + break; case logLevel.ERROR: console.error(logMessage); - break; + break; default: console.log(logMessage); } diff --git a/index.html b/index.html index d0e4dc5..7b4bc48 100644 --- a/index.html +++ b/index.html @@ -6,14 +6,16 @@ - + - + Countly Cordova Demo App @@ -40,7 +42,8 @@

Countly Cordova Demo App

- +
Events End
@@ -89,7 +92,8 @@

Countly Cordova Demo App

- + @@ -99,32 +103,41 @@

Countly Cordova Demo App

User Methods End
Remote Config Methods Start
- + - - - + + + - - + +
Remote Config Methods End
Other Methods Start
- + - - + +
Other Methods End
@@ -139,8 +152,10 @@

Countly Cordova Demo App

Performance Methods Start
- - + +
Performance Methods End
@@ -150,702 +165,702 @@

Countly Cordova Demo App

console.log("[CountlyCordova] onBodyLoad"); document.addEventListener("deviceready", onDeviceReady, false); } - + function onDeviceReady() { console.log("[CountlyCordova] deviceready"); - Countly.onNotification(function(theNotification){ + Countly.onNotification(function (theNotification) { console.log("[CountlyCordova] onNotification : " + JSON.stringify(theNotification)); }); app.init(); } - app = {}; - function makeid() { - var text = ""; - var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - - for (var i = 0; i < 5; i++) - text += possible.charAt(Math.floor(Math.random() * possible.length)); - - return text; - } - app.init = function() { - Countly.isInitialized().then((result) => { - if(result != "true") { - /** Recommended settings for Countly initialisation */ - Countly.setLoggingEnabled(true); // Enable countly internal debugging logs - Countly.enableCrashReporting(); // Enable crash reporting to report unhandled crashes to Countly - Countly.setRequiresConsent(true); // Set that consent should be required for features to work. - Countly.giveConsentInit(["location", "sessions", "attribution", "push", "events", "views", "crashes", "users", "push", "star-rating", "apm", "feedback", "remote-config"]); // give conset for specific features before init. - Countly.setLocationInit("TR", "Istanbul", "41.0082,28.9784", "10.2.33.12"); // Set user initial location. - - - /** Optional settings for Countly initialisation */ - Countly.enableParameterTamperingProtection("salt"); // Set the optional salt to be used for calculating the checksum of requested data which will be sent with each request - // Countly.pinnedCertificates("count.ly.cer"); // It will ensure that connection is made with one of the public keys specified - Countly.setHttpPostForced(false); // Set to "true" if you want HTTP POST to be used for all requests - Countly.enableApm(); // Enable APM features, which includes the recording of app start time. - Countly.enableAttribution(); // Enable to measure your marketing campaign performance by attributing installs from specific campaigns. - Countly.setRemoteConfigAutomaticDownload(function(r){ - console.log("[CountlyCordova] onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] onError : " + r); - }); // Set Automatic value download happens when the SDK is initiated or when the device ID is changed. - Countly.pushTokenType(Countly.messagingMode.TEST); // Set messaging mode for push notifications - - Countly.init("https://try.count.ly", "YOUR_API_KEY").then((result) => { - Countly.appLoadingFinished(); - Countly.setStarRatingDialogTexts("Title", "Message", "Dismiss"); - /** - * Push notifications settings - * Should be call after init - */ - Countly.onNotification(function(theNotification){ - console.log("[CountlyCordova] onNotification : " + JSON.stringify(theNotification)); - }); // Set callback to receive push notifications - Countly.askForNotificationPermission(); // This method will ask for permission, enables push notification and send push token to countly server. - - Countly.giveAllConsent(); // give consent for all features, should be call after init - // Countly.giveConsent(["events", "views"]); // give conset for some specific features, should be call after init. - },(err) => { - console.error(err); - }); - } - },(err) => { - console.error(err); - }); - - // Countly.eventSendThreshold(1); - }; - // app.test = function() { - // app.sendPushToken(); - // app.sendSampleEvent(); - // } - - app.setOptionalParametersForInitialization = function() { - Countly.setOptionalParametersForInitialization({ - "city": "Tampa", - "country": "US", - "latitude": "28.006324", - "longitude": "-82.7166183", - "ipAddress": "255.255.255.255" - }); - }; - - app.setLocation = function() { - Countly.setLocation("TR", "Istanbul", "41.0082,28.9784", "10.2.33.12"); - }; - - app.event = function() { - setInterval(function() { - app.sendSampleEvent(); - }, 1000); - } - app.start = function() { - Countly.start(); - } - - // app.manualSessionHandling = function() { - // Countly.manualSessionHandling(); - // } - - // app.updateSessionPeriod = function() { - // Countly.updateSessionPeriod(15); - // } - - // app.eventSendThreshold = function() { - // Countly.eventSendThreshold(1); - // } - - // app.storedRequestsLimit = function() { - // Countly.storedRequestsLimit(1); - // } - - app.stop = function() { - Countly.stop(); - } - - app.halt = function() { - Countly.halt(); - } - - app.sendSampleEvent = function() { - app.basicEvent(); - app.eventWithSum(); - app.eventWithSegment(); - app.eventWithSumSegment(); - } - - app.basicEvent = function() { - // example for basic event - var event = { - "key": "Basic Event", - "count": 1 - }; - Countly.recordEvent(event); - } - app.eventWithSum = function() { - // example for event with sum - var event = { - "key": "Event With Sum", - "count": 1, - "sum": "0.99", - }; - Countly.recordEvent(event); - } - app.eventWithSegment = function() { - // example for event with segment - var event = { - "key": "Event With Segment", - "count": 1 - }; - event.segments = { - "Country": "Turkey", - "Age": "28" - }; - Countly.recordEvent(event); - } - app.eventWithSumSegment = function() { - // example for event with segment and sum - var event = { - "key": "Event With Sum And Segment", - "count": 1, - "sum": "0.99" - }; - event.segments = { - "Country": "Turkey", - "Age": "28" + app = {}; + function makeid() { + var text = ""; + var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + for (var i = 0; i < 5; i++) + text += possible.charAt(Math.floor(Math.random() * possible.length)); + + return text; + } + app.init = function () { + Countly.isInitialized().then((result) => { + if (result != "true") { + /** Recommended settings for Countly initialisation */ + Countly.setLoggingEnabled(true); // Enable countly internal debugging logs + Countly.enableCrashReporting(); // Enable crash reporting to report unhandled crashes to Countly + Countly.setRequiresConsent(true); // Set that consent should be required for features to work. + Countly.giveConsentInit(["location", "sessions", "attribution", "push", "events", "views", "crashes", "users", "push", "star-rating", "apm", "feedback", "remote-config"]); // give conset for specific features before init. + Countly.setLocationInit("TR", "Istanbul", "41.0082,28.9784", "10.2.33.12"); // Set user initial location. + + + /** Optional settings for Countly initialisation */ + Countly.enableParameterTamperingProtection("salt"); // Set the optional salt to be used for calculating the checksum of requested data which will be sent with each request + // Countly.pinnedCertificates("count.ly.cer"); // It will ensure that connection is made with one of the public keys specified + Countly.setHttpPostForced(false); // Set to "true" if you want HTTP POST to be used for all requests + Countly.enableApm(); // Enable APM features, which includes the recording of app start time. + Countly.enableAttribution(); // Enable to measure your marketing campaign performance by attributing installs from specific campaigns. + Countly.setRemoteConfigAutomaticDownload(function (r) { + console.log("[CountlyCordova] onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] onError : " + r); + }); // Set Automatic value download happens when the SDK is initiated or when the device ID is changed. + Countly.pushTokenType(Countly.messagingMode.TEST); // Set messaging mode for push notifications + + Countly.init("https://try.count.ly", "YOUR_API_KEY").then((result) => { + Countly.appLoadingFinished(); + Countly.setStarRatingDialogTexts("Title", "Message", "Dismiss"); + /** + * Push notifications settings + * Should be call after init + */ + Countly.onNotification(function (theNotification) { + console.log("[CountlyCordova] onNotification : " + JSON.stringify(theNotification)); + }); // Set callback to receive push notifications + Countly.askForNotificationPermission(); // This method will ask for permission, enables push notification and send push token to countly server. + + Countly.giveAllConsent(); // give consent for all features, should be call after init + // Countly.giveConsent(["events", "views"]); // give conset for some specific features, should be call after init. + }, (err) => { + console.error(err); + }); + } + }, (err) => { + console.error(err); + }); + + // Countly.eventSendThreshold(1); }; - Countly.recordEvent(event); - } - app.eventWithSumSegment_duration = function() { - // example for event with segment and sum - var event = { - "key": "Event With Sum And Segment duration", - "count": 1, - "sum": "0.99", - "duration":"1000" + // app.test = function() { + // app.sendPushToken(); + // app.sendSampleEvent(); + // } + + app.setOptionalParametersForInitialization = function () { + Countly.setOptionalParametersForInitialization({ + "city": "Tampa", + "country": "US", + "latitude": "28.006324", + "longitude": "-82.7166183", + "ipAddress": "255.255.255.255" + }); }; - event.segments = { - "Country": "Turkey", - "Age": "28" + + app.setLocation = function () { + Countly.setLocation("TR", "Istanbul", "41.0082,28.9784", "10.2.33.12"); }; - Countly.recordEvent(event); - } - app.setUserData = function() { - // example for setUserData - var options = {}; - options.name = "Name of User"; - options.username = "Username"; - options.email = "User Email"; - options.org = "User Organization"; - options.phone = "User Contact number"; - options.picture = "https://count.ly/images/logos/countly-logo.png"; - options.picturePath = ""; - options.gender = "User Gender"; - options.byear = 1989; - Countly.setUserData(options); - }; - - app.setCaptianAmericaData = function() { - // example for setCaptianAmericaData - var deviceId = makeid(); - Countly.changeDeviceId(deviceId, false); - - var options = {}; - options.name = "Captian America"; - options.username = "captianamerica"; - options.email = "captianamerica@avengers.com"; - options.organization = "Avengers"; - options.phone = "+91 555 555 5555"; - options.picture = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Captain-America-icon.png"; - options.picturePath = ""; - options.gender = "M"; // "F" - options.byear = 1989; - Countly.setUserData(options); - - }; - - app.setIronManData = function() { - // example for setIronManData - var deviceId = makeid(); - Countly.changeDeviceId(deviceId, false); - - var options = {}; - options.name = "Iron Man"; - options.username = "ironman"; - options.email = "ironman@avengers.com"; - options.organization = "Avengers"; - options.phone = "+91 555 555 5555"; - options.picture = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Iron-Man-icon.png"; - options.picturePath = ""; - options.gender = "M"; // "F" - options.byear = 1989; - Countly.setUserData(options); - Countly.start(); - }; - - app.setSpiderManData = function() { - var deviceId = makeid(); - Countly.changeDeviceId(deviceId, false); - - var options = {}; - options.name = "Spider-Man"; - options.username = "spiderman"; - options.email = "spiderman@avengers.com"; - options.organization = "Avengers"; - options.phone = "+91 555 555 5555"; - options.picture = "http://icons.iconarchive.com/icons/mattahan/ultrabuuf/512/Comics-Spiderman-Morales-icon.png"; - options.picturePath = ""; - options.gender = "M"; // "F" - options.byear = 1989; - Countly.setUserData(options); - Countly.start(); - }; - - - - - app.setloggingenabled = function() { - // example for setLoggingEnabled - Countly.setLoggingEnabled(true); - } - app.setloggingdisabled = function() { - // example for setLoggingEnabled - Countly.setLoggingEnabled(false); - } - - app.sendPushToken = function() { - - var push = PushNotification.init({ - android: {sound: true}, - ios: { - alert: "true", - badge: "true", - sound: "true" - }, - windows: {} - }); - - push.on('registration', function(data) { - console.log("[CountlyCordova] registration : " + 'Token received: '+data.registrationId); - Countly.sendPushToken({ - "token": data.registrationId, - "messagingMode": Countly.messagingMode.DEVELOPMENT - }); - }); - - push.on('notification', function(data) { - console.log("[CountlyCordova] notification : " + JSON.stringify(data)); - }); - - push.on('error', function(e) { - // e.message - }); - // Countly.messagingMode.DEVELOPMENT - // Countly.messagingMode.PRODUCTION - // Countly.messagingMode.ADHOC - } - - app.setHttpPostForced = function() { - Countly.setHttpPostForced(true); - } - - app.askForNotificationPermission = function() { - Countly.askForNotificationPermission(); - } - - app.recordView = function(viewName) { - Countly.recordView(viewName); - } - - /** 2017 **/ - app.changeDeviceId = function() { - Countly.changeDeviceId("123456", true); - } - app.enableParameterTamperingProtection = function() { - Countly.enableParameterTamperingProtection("salt"); - } - - app.endEventBasic = function() { - Countly.startEvent("Timed Event"); - setTimeout(function() { - Countly.endEvent({ "key": "Timed Event" }); - }, 1000); - } - app.endEventWithSum = function() { - Countly.startEvent("Timed Event With Sum"); - setTimeout(function() { - Countly.endEvent({ "key": "Timed Event With Sum", "sum": "0.99" }); - }, 1000); - } - app.endEventWithSegment = function() { - Countly.startEvent("Timed Event With Segment"); - setTimeout(function() { - - var events = { - "key": "Timed Event With Segment" + + app.event = function () { + setInterval(function () { + app.sendSampleEvent(); + }, 1000); + } + app.start = function () { + Countly.start(); + } + + // app.manualSessionHandling = function() { + // Countly.manualSessionHandling(); + // } + + // app.updateSessionPeriod = function() { + // Countly.updateSessionPeriod(15); + // } + + // app.eventSendThreshold = function() { + // Countly.eventSendThreshold(1); + // } + + // app.storedRequestsLimit = function() { + // Countly.storedRequestsLimit(1); + // } + + app.stop = function () { + Countly.stop(); + } + + app.halt = function () { + Countly.halt(); + } + + app.sendSampleEvent = function () { + app.basicEvent(); + app.eventWithSum(); + app.eventWithSegment(); + app.eventWithSumSegment(); + } + + app.basicEvent = function () { + // example for basic event + var event = { + "key": "Basic Event", + "count": 1 + }; + Countly.recordEvent(event); + } + app.eventWithSum = function () { + // example for event with sum + var event = { + "key": "Event With Sum", + "count": 1, + "sum": "0.99", + }; + Countly.recordEvent(event); + } + app.eventWithSegment = function () { + // example for event with segment + var event = { + "key": "Event With Segment", + "count": 1 }; - events.segments = { + event.segments = { "Country": "Turkey", "Age": "28" }; - Countly.endEvent(events); - }, 1000); - } - app.endEventWithSumSegment = function() { - Countly.startEvent("Timed Event With Segment, Sum and Count"); - setTimeout(function() { - var events = { - "key": "Timed Event With Segment, Sum and Count", + Countly.recordEvent(event); + } + app.eventWithSumSegment = function () { + // example for event with segment and sum + var event = { + "key": "Event With Sum And Segment", "count": 1, "sum": "0.99" }; - events.segments = { + event.segments = { "Country": "Turkey", "Age": "28" }; - Countly.endEvent(events); - }, 1000); - } - app.startEventX = function(){ - Countly.startEvent("Event X"); - } - app.cancelEventX = function(){ - Countly.cancelEvent("Event X"); - } - // app.sendRating = function(){ - // // Ratings can be from 1 - 5; - // Countly.sendRating(5); - // } - app.askForFeedback = function(){ - Countly.askForFeedback("5e4254507975d006a22535fc", "Close"); - } - app.askForStarRating = function(){ - Countly.askForStarRating(function(ratingResult){ - console.log("[CountlyCordova] askForStarRating : " + ratingResult); - }); - } - - app.showSurvey = function(){ - Countly.getFeedbackWidgets().then((retrivedWidgets) => { - var surveyWidget = retrivedWidgets.find(x => x.type === 'survey') - if(surveyWidget) { - Countly.presentFeedbackWidget(surveyWidget, "Close") - } - },(err) => { - console.error("showSurvey getFeedbackWidgets error : " +err); - }); - } - - app.showNPS = function(){ - Countly.getFeedbackWidgets().then((retrivedWidgets) => { - var npsWidget = retrivedWidgets.find(x => x.type === 'nps') - if(npsWidget) { - Countly.presentFeedbackWidget(npsWidget, "Cancel") + Countly.recordEvent(event); + } + app.eventWithSumSegment_duration = function () { + // example for event with segment and sum + var event = { + "key": "Event With Sum And Segment duration", + "count": 1, + "sum": "0.99", + "duration": "1000" + }; + event.segments = { + "Country": "Turkey", + "Age": "28" + }; + Countly.recordEvent(event); + } + app.setUserData = function () { + // example for setUserData + var options = {}; + options.name = "Name of User"; + options.username = "Username"; + options.email = "User Email"; + options.org = "User Organization"; + options.phone = "User Contact number"; + options.picture = "https://count.ly/images/logos/countly-logo.png"; + options.picturePath = ""; + options.gender = "User Gender"; + options.byear = 1989; + Countly.setUserData(options); + }; + + app.setCaptianAmericaData = function () { + // example for setCaptianAmericaData + var deviceId = makeid(); + Countly.changeDeviceId(deviceId, false); + + var options = {}; + options.name = "Captian America"; + options.username = "captianamerica"; + options.email = "captianamerica@avengers.com"; + options.organization = "Avengers"; + options.phone = "+91 555 555 5555"; + options.picture = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Captain-America-icon.png"; + options.picturePath = ""; + options.gender = "M"; // "F" + options.byear = 1989; + Countly.setUserData(options); + + }; + + app.setIronManData = function () { + // example for setIronManData + var deviceId = makeid(); + Countly.changeDeviceId(deviceId, false); + + var options = {}; + options.name = "Iron Man"; + options.username = "ironman"; + options.email = "ironman@avengers.com"; + options.organization = "Avengers"; + options.phone = "+91 555 555 5555"; + options.picture = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Iron-Man-icon.png"; + options.picturePath = ""; + options.gender = "M"; // "F" + options.byear = 1989; + Countly.setUserData(options); + Countly.start(); + }; + + app.setSpiderManData = function () { + var deviceId = makeid(); + Countly.changeDeviceId(deviceId, false); + + var options = {}; + options.name = "Spider-Man"; + options.username = "spiderman"; + options.email = "spiderman@avengers.com"; + options.organization = "Avengers"; + options.phone = "+91 555 555 5555"; + options.picture = "http://icons.iconarchive.com/icons/mattahan/ultrabuuf/512/Comics-Spiderman-Morales-icon.png"; + options.picturePath = ""; + options.gender = "M"; // "F" + options.byear = 1989; + Countly.setUserData(options); + Countly.start(); + }; + + + + + app.setloggingenabled = function () { + // example for setLoggingEnabled + Countly.setLoggingEnabled(true); + } + app.setloggingdisabled = function () { + // example for setLoggingEnabled + Countly.setLoggingEnabled(false); + } + + app.sendPushToken = function () { + + var push = PushNotification.init({ + android: { sound: true }, + ios: { + alert: "true", + badge: "true", + sound: "true" + }, + windows: {} + }); + + push.on('registration', function (data) { + console.log("[CountlyCordova] registration : " + 'Token received: ' + data.registrationId); + Countly.sendPushToken({ + "token": data.registrationId, + "messagingMode": Countly.messagingMode.DEVELOPMENT + }); + }); + + push.on('notification', function (data) { + console.log("[CountlyCordova] notification : " + JSON.stringify(data)); + }); + + push.on('error', function (e) { + // e.message + }); + // Countly.messagingMode.DEVELOPMENT + // Countly.messagingMode.PRODUCTION + // Countly.messagingMode.ADHOC + } + + app.setHttpPostForced = function () { + Countly.setHttpPostForced(true); + } + + app.askForNotificationPermission = function () { + Countly.askForNotificationPermission(); + } + + app.recordView = function (viewName) { + Countly.recordView(viewName); + } + + /** 2017 **/ + app.changeDeviceId = function () { + Countly.changeDeviceId("123456", true); + } + app.enableParameterTamperingProtection = function () { + Countly.enableParameterTamperingProtection("salt"); + } + + app.endEventBasic = function () { + Countly.startEvent("Timed Event"); + setTimeout(function () { + Countly.endEvent({ "key": "Timed Event" }); + }, 1000); + } + app.endEventWithSum = function () { + Countly.startEvent("Timed Event With Sum"); + setTimeout(function () { + Countly.endEvent({ "key": "Timed Event With Sum", "sum": "0.99" }); + }, 1000); + } + app.endEventWithSegment = function () { + Countly.startEvent("Timed Event With Segment"); + setTimeout(function () { + + var events = { + "key": "Timed Event With Segment" + }; + events.segments = { + "Country": "Turkey", + "Age": "28" + }; + Countly.endEvent(events); + }, 1000); + } + app.endEventWithSumSegment = function () { + Countly.startEvent("Timed Event With Segment, Sum and Count"); + setTimeout(function () { + var events = { + "key": "Timed Event With Segment, Sum and Count", + "count": 1, + "sum": "0.99" + }; + events.segments = { + "Country": "Turkey", + "Age": "28" + }; + Countly.endEvent(events); + }, 1000); + } + app.startEventX = function () { + Countly.startEvent("Event X"); + } + app.cancelEventX = function () { + Countly.cancelEvent("Event X"); + } + // app.sendRating = function(){ + // // Ratings can be from 1 - 5; + // Countly.sendRating(5); + // } + app.askForFeedback = function () { + Countly.askForFeedback("5e4254507975d006a22535fc", "Close"); + } + app.askForStarRating = function () { + Countly.askForStarRating(function (ratingResult) { + console.log("[CountlyCordova] askForStarRating : " + ratingResult); + }); + } + + app.showSurvey = function () { + Countly.getFeedbackWidgets().then((retrivedWidgets) => { + var surveyWidget = retrivedWidgets.find(x => x.type === 'survey') + if (surveyWidget) { + Countly.presentFeedbackWidget(surveyWidget, "Close") + } + }, (err) => { + console.error("showSurvey getFeedbackWidgets error : " + err); + }); + } + + app.showNPS = function () { + Countly.getFeedbackWidgets().then((retrivedWidgets) => { + var npsWidget = retrivedWidgets.find(x => x.type === 'nps') + if (npsWidget) { + Countly.presentFeedbackWidget(npsWidget, "Cancel") + } + }, (err) => { + console.error("showNPS getFeedbackWidgets error : " + err); + }); + } + + + + app.addCrashLog = function () { + Countly.enableCrashReporting(); + Countly.addCrashLog("User Performed Step A"); + setTimeout(function () { + Countly.addCrashLog("User Performed Step B"); + }, 1000); + setTimeout(function () { + Countly.addCrashLog("User Performed Step C"); + // console.log("Opps found and error"); + a(); + }, 1000); + } + + function a() { + b(); + } + + function b() { + c(); + } + + function c() { + d(); + throw new Error("My Custom Error"); + } + + function d() { + try { + throw new Error("My Second Error"); + } catch (err) { + StackTrace.fromError(err).then(function (stackframes) { + Countly.logException(stackframes, true, { "_facebook_version": "0.0.1" }); + }); } - },(err) => { - console.error("showNPS getFeedbackWidgets error : " +err); - }); - } - - - - app.addCrashLog = function() { - Countly.enableCrashReporting(); - Countly.addCrashLog("User Performed Step A"); - setTimeout(function() { - Countly.addCrashLog("User Performed Step B"); - }, 1000); - setTimeout(function() { - Countly.addCrashLog("User Performed Step C"); - // console.log("Opps found and error"); - a(); - }, 1000); - } - - function a() { - b(); - } - - function b() { - c(); - } - - function c() { - d(); - throw new Error("My Custom Error"); - } - - function d() { - try { - throw new Error("My Second Error"); - } catch (err) { - StackTrace.fromError(err).then(function(stackframes) { - Countly.logException(stackframes, true, {"_facebook_version": "0.0.1"}); + } + + /** user details **/ + + app.userData = {}; + app.userData.setProperty = function () { + Countly.userData.setProperty("setProperty", "My Property"); + } + app.userData.increment = function () { + Countly.userData.setProperty("increment", 4); + Countly.userData.increment("increment"); + } + app.userData.incrementBy = function () { + Countly.userData.setProperty("incrementBy", 5); + Countly.userData.incrementBy("incrementBy", 10); + } + app.userData.multiply = function () { + Countly.userData.setProperty("multiply", 5); + Countly.userData.multiply("multiply", 20); + } + app.userData.saveMax = function () { + Countly.userData.saveMax("saveMax", 100); + } + app.userData.saveMin = function () { + Countly.userData.saveMin("saveMin", 50); + } + app.userData.setOnce = function () { + Countly.userData.setOnce("setOnce", 200); + } + app.userData.pushUniqueValue = function () { + Countly.userData.pushUniqueValue("pushUniqueValue", "morning"); + } + app.userData.pushValue = function () { + Countly.userData.pushValue("pushValue", "morning"); + } + app.userData.pullValue = function () { + Countly.userData.pullValue("pullValue", "morning"); + } + + //setRequiresConsent + app.setRequiresConsent = function () { + Countly.setRequiresConsent(true); + } + + app.giveMultipleConsent = function () { + Countly.giveConsent(["events", "views", "star-rating", "crashes"]); + } + app.removeMultipleConsent = function () { + Countly.removeConsent(["events", "views", "star-rating", "crashes"]); + } + app.giveAllConsent = function () { + Countly.giveAllConsent(); + } + app.removeAllConsent = function () { + Countly.removeAllConsent(); + } + + app.giveConsentSessions = function () { + Countly.giveConsent(["sessions"]); + } + app.giveConsentEvents = function () { + Countly.giveConsent(["events"]); + } + app.giveConsentViews = function () { + Countly.giveConsent(["views"]); + } + app.giveConsentLocation = function () { + Countly.giveConsent(["location"]); + } + app.giveConsentCrashes = function () { + Countly.giveConsent(["crashes"]); + } + app.giveConsentAttribution = function () { + Countly.giveConsent(["attribution"]); + } + app.giveConsentUsers = function () { + Countly.giveConsent(["users"]); + } + app.giveConsentPush = function () { + Countly.giveConsent(["push"]); + } + app.giveConsentStarRating = function () { + Countly.giveConsent(["star-rating"]); + } + app.giveConsentAppleWatch = function () { + Countly.giveConsent(["AppleWatch"]); + } + app.giveConsentAPM = function () { + Countly.giveConsent(["apm"]); + } + + app.removeConsentSessions = function () { + Countly.removeConsent(["sessions"]); + } + app.removeConsentEvents = function () { + Countly.removeConsent(["events"]); + } + app.removeConsentViews = function () { + Countly.removeConsent(["views"]); + } + app.removeConsentLocation = function () { + Countly.removeConsent(["location"]); + } + app.removeConsentCrashes = function () { + Countly.removeConsent(["crashes"]); + } + app.removeConsentAttribution = function () { + Countly.removeConsent(["attribution"]); + } + app.removeConsentUsers = function () { + Countly.removeConsent(["users"]); + } + app.removeConsentPush = function () { + Countly.removeConsent(["push"]); + } + app.removeConsentStarRating = function () { + Countly.removeConsent(["star-rating"]); + } + app.removeConsentAppleWatch = function () { + Countly.giveConsent(["AppleWatch"]); + } + app.removeConsentAPM = function () { + Countly.removeConsent(["apm"]); + } + + // Remote config usage + app.setRemoteConfigAutomaticDownload = function () { + Countly.setRemoteConfigAutomaticDownload(function (r) { + console.log("[CountlyCordova] setRemoteConfigAutomaticDownload onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] setRemoteConfigAutomaticDownload onError : " + r); + }); + } + app.remoteConfigUpdate = function () { + Countly.remoteConfigUpdate(function (r) { + console.log("[CountlyCordova] remoteConfigUpdate onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] remoteConfigUpdate onError : " + r); + }); + } + app.updateRemoteConfigForKeysOnly = function () { + Countly.updateRemoteConfigForKeysOnly(["name"], function (r) { + console.log("[CountlyCordova] updateRemoteConfigForKeysOnly onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] updateRemoteConfigForKeysOnly onError : " + r); + }); + } + app.updateRemoteConfigExceptKeys = function () { + Countly.updateRemoteConfigExceptKeys(["url"], function (r) { + console.log("[CountlyCordova] updateRemoteConfigExceptKeys onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] updateRemoteConfigExceptKeys onError : " + r); + }); + } + app.remoteConfigClearValues = function () { + Countly.remoteConfigClearValues(function (r) { + console.log("[CountlyCordova] remoteConfigClearValues onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] remoteConfigClearValues onError : " + r); + }); + } + app.getRemoteConfigValueForKey = function () { + Countly.getRemoteConfigValueForKey("name", function (r) { + console.log("[CountlyCordova] getRemoteConfigValueForKey onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] getRemoteConfigValueForKey onError : " + r); }); } - } - - /** user details **/ - - app.userData = {}; - app.userData.setProperty = function() { - Countly.userData.setProperty("setProperty", "My Property"); - } - app.userData.increment = function() { - Countly.userData.setProperty("increment", 4); - Countly.userData.increment("increment"); - } - app.userData.incrementBy = function() { - Countly.userData.setProperty("incrementBy", 5); - Countly.userData.incrementBy("incrementBy", 10); - } - app.userData.multiply = function() { - Countly.userData.setProperty("multiply", 5); - Countly.userData.multiply("multiply", 20); - } - app.userData.saveMax = function() { - Countly.userData.saveMax("saveMax", 100); - } - app.userData.saveMin = function() { - Countly.userData.saveMin("saveMin", 50); - } - app.userData.setOnce = function() { - Countly.userData.setOnce("setOnce", 200); - } - app.userData.pushUniqueValue = function() { - Countly.userData.pushUniqueValue("pushUniqueValue", "morning"); - } - app.userData.pushValue = function() { - Countly.userData.pushValue("pushValue", "morning"); - } - app.userData.pullValue = function() { - Countly.userData.pullValue("pullValue", "morning"); - } - -//setRequiresConsent - app.setRequiresConsent = function() { - Countly.setRequiresConsent(true); - } - - app.giveMultipleConsent = function() { - Countly.giveConsent(["events", "views", "star-rating", "crashes"]); - } - app.removeMultipleConsent = function() { - Countly.removeConsent(["events", "views", "star-rating", "crashes"]); - } - app.giveAllConsent = function() { - Countly.giveAllConsent(); - } - app.removeAllConsent = function() { - Countly.removeAllConsent(); - } - - app.giveConsentSessions = function() { - Countly.giveConsent(["sessions"]); - } - app.giveConsentEvents = function() { - Countly.giveConsent(["events"]); - } - app.giveConsentViews = function() { - Countly.giveConsent(["views"]); - } - app.giveConsentLocation = function() { - Countly.giveConsent(["location"]); - } - app.giveConsentCrashes = function() { - Countly.giveConsent(["crashes"]); - } - app.giveConsentAttribution = function() { - Countly.giveConsent(["attribution"]); - } - app.giveConsentUsers = function() { - Countly.giveConsent(["users"]); - } - app.giveConsentPush = function() { - Countly.giveConsent(["push"]); - } - app.giveConsentStarRating = function() { - Countly.giveConsent(["star-rating"]); - } - app.giveConsentAppleWatch = function() { - Countly.giveConsent(["AppleWatch"]); - } - app.giveConsentAPM = function(){ - Countly.giveConsent(["apm"]); - } - - app.removeConsentSessions = function() { - Countly.removeConsent(["sessions"]); - } - app.removeConsentEvents = function() { - Countly.removeConsent(["events"]); - } - app.removeConsentViews = function() { - Countly.removeConsent(["views"]); - } - app.removeConsentLocation = function() { - Countly.removeConsent(["location"]); - } - app.removeConsentCrashes = function() { - Countly.removeConsent(["crashes"]); - } - app.removeConsentAttribution = function() { - Countly.removeConsent(["attribution"]); - } - app.removeConsentUsers = function() { - Countly.removeConsent(["users"]); - } - app.removeConsentPush = function() { - Countly.removeConsent(["push"]); - } - app.removeConsentStarRating = function() { - Countly.removeConsent(["star-rating"]); - } - app.removeConsentAppleWatch = function() { - Countly.giveConsent(["AppleWatch"]); - } - app.removeConsentAPM = function(){ - Countly.removeConsent(["apm"]); - } - // Remote config usage - app.setRemoteConfigAutomaticDownload = function(){ - Countly.setRemoteConfigAutomaticDownload(function(r){ - console.log("[CountlyCordova] setRemoteConfigAutomaticDownload onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] setRemoteConfigAutomaticDownload onError : " + r); - }); - } - app.remoteConfigUpdate = function(){ - Countly.remoteConfigUpdate(function(r){ - console.log("[CountlyCordova] remoteConfigUpdate onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] remoteConfigUpdate onError : " + r); - }); - } - app.updateRemoteConfigForKeysOnly = function(){ - Countly.updateRemoteConfigForKeysOnly(["name"], function(r){ - console.log("[CountlyCordova] updateRemoteConfigForKeysOnly onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] updateRemoteConfigForKeysOnly onError : " + r); - }); - } - app.updateRemoteConfigExceptKeys = function(){ - Countly.updateRemoteConfigExceptKeys(["url"], function(r){ - console.log("[CountlyCordova] updateRemoteConfigExceptKeys onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] updateRemoteConfigExceptKeys onError : " + r); - }); - } - app.remoteConfigClearValues = function(){ - Countly.remoteConfigClearValues(function(r){ - console.log("[CountlyCordova] remoteConfigClearValues onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] remoteConfigClearValues onError : " + r); - }); - } - app.getRemoteConfigValueForKey = function(){ - Countly.getRemoteConfigValueForKey("name", function(r){ - console.log("[CountlyCordova] getRemoteConfigValueForKey onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] getRemoteConfigValueForKey onError : " + r); - }); - } - - app.updateRemoteConfigForbooleanValueOnly = function(){ - Countly.getRemoteConfigValueForKey("booleanValue", function(r){ - console.log("[CountlyCordova] updateRemoteConfigForbooleanValueOnly onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] updateRemoteConfigForbooleanValueOnly onError : " + r); - }); - } - app.updateRemoteConfigForfloatValueOnly = function(){ - Countly.getRemoteConfigValueForKey("floatValue", function(r){ - console.log("[CountlyCordova] updateRemoteConfigForfloatValueOnly onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] updateRemoteConfigForfloatValueOnly onError : " + r); - }); - } - app.updateRemoteConfigForintegerValueOnly = function(){ - Countly.getRemoteConfigValueForKey("integerValue", function(r){ - console.log("[CountlyCordova] updateRemoteConfigForintegerValueOnly onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] updateRemoteConfigForintegerValueOnly onError : " + r); - }); - } - app.updateRemoteConfigForstringValueOnly = function(){ - Countly.getRemoteConfigValueForKey("stringValue", function(r){ - console.log("[CountlyCordova] updateRemoteConfigForstringValueOnly onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] updateRemoteConfigForstringValueOnly onError : " + r); - }); - } - app.updateRemoteConfigForjsonValueOnly = function(){ - Countly.getRemoteConfigValueForKey("jsonValue", function(r){ - console.log("[CountlyCordova] updateRemoteConfigForjsonValueOnly onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] updateRemoteConfigForjsonValueOnly onError : " + r); - }); - } - app.updateRemoteConfigForjsonStringValueOnly = function(){ - Countly.getRemoteConfigValueForKey("arrayStringValue", function(r){ - console.log("[CountlyCordova] updateRemoteConfigForjsonStringValueOnly onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] updateRemoteConfigForjsonStringValueOnly onError : " + r); - }); - } - app.updateRemoteConfigForjsonNumberValueOnly = function(){ - Countly.getRemoteConfigValueForKey("arrayNumberValue", function(r){ - console.log("[CountlyCordova] updateRemoteConfigForjsonNumberValueOnly onSuccess : " + r) - }, function(r){ - console.log("[CountlyCordova] updateRemoteConfigForjsonNumberValueOnly onError : " + r); - }); - } - - var successCodes = [100, 101, 200, 201, 202, 205, 300, 301, 303, 305]; - var failureCodes = [400, 402, 405, 408, 500, 501, 502, 505]; - - app.startTrace = function(){ - var traceKey = "Trace Key"; - Countly.startTrace(traceKey); - } - app.endTrace = function(){ - var traceKey = "Trace Key"; - var customMetric = { - "ABC": 1233, - "C44C": 1337 - }; - Countly.endTrace(traceKey, customMetric); - } - function random(number){ - return Math.floor(Math.random() * number); - } - app.recordNetworkTraceSuccess = function(){ - var networkTraceKey = "api/endpoint.1"; - var responseCode = successCodes[random(successCodes.length)]; - var requestPayloadSize = random(700) + 200; - var responsePayloadSize = random(700) + 200; - var startTime = new Date().getTime(); - var endTime = startTime + 500; - Countly.recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime); - } - app.recordNetworkTraceFailure = function(){ - var networkTraceKey = "api/endpoint.1"; - var responseCode = failureCodes[random(failureCodes.length)]; - var requestPayloadSize = random(700) + 250; - var responsePayloadSize = random(700) + 250; - var startTime = new Date().getTime(); - var endTime = startTime + 500; - Countly.recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime); - } - app.enableApm = function(){ - Countly.enableApm(); - } - app.setCustomCrashSegment = function(){ - var segment = {"Key": "Value"}; - Countly.setCustomCrashSegment(segment); - } + app.updateRemoteConfigForbooleanValueOnly = function () { + Countly.getRemoteConfigValueForKey("booleanValue", function (r) { + console.log("[CountlyCordova] updateRemoteConfigForbooleanValueOnly onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] updateRemoteConfigForbooleanValueOnly onError : " + r); + }); + } + app.updateRemoteConfigForfloatValueOnly = function () { + Countly.getRemoteConfigValueForKey("floatValue", function (r) { + console.log("[CountlyCordova] updateRemoteConfigForfloatValueOnly onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] updateRemoteConfigForfloatValueOnly onError : " + r); + }); + } + app.updateRemoteConfigForintegerValueOnly = function () { + Countly.getRemoteConfigValueForKey("integerValue", function (r) { + console.log("[CountlyCordova] updateRemoteConfigForintegerValueOnly onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] updateRemoteConfigForintegerValueOnly onError : " + r); + }); + } + app.updateRemoteConfigForstringValueOnly = function () { + Countly.getRemoteConfigValueForKey("stringValue", function (r) { + console.log("[CountlyCordova] updateRemoteConfigForstringValueOnly onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] updateRemoteConfigForstringValueOnly onError : " + r); + }); + } + app.updateRemoteConfigForjsonValueOnly = function () { + Countly.getRemoteConfigValueForKey("jsonValue", function (r) { + console.log("[CountlyCordova] updateRemoteConfigForjsonValueOnly onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] updateRemoteConfigForjsonValueOnly onError : " + r); + }); + } + app.updateRemoteConfigForjsonStringValueOnly = function () { + Countly.getRemoteConfigValueForKey("arrayStringValue", function (r) { + console.log("[CountlyCordova] updateRemoteConfigForjsonStringValueOnly onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] updateRemoteConfigForjsonStringValueOnly onError : " + r); + }); + } + app.updateRemoteConfigForjsonNumberValueOnly = function () { + Countly.getRemoteConfigValueForKey("arrayNumberValue", function (r) { + console.log("[CountlyCordova] updateRemoteConfigForjsonNumberValueOnly onSuccess : " + r) + }, function (r) { + console.log("[CountlyCordova] updateRemoteConfigForjsonNumberValueOnly onError : " + r); + }); + } + + var successCodes = [100, 101, 200, 201, 202, 205, 300, 301, 303, 305]; + var failureCodes = [400, 402, 405, 408, 500, 501, 502, 505]; + + app.startTrace = function () { + var traceKey = "Trace Key"; + Countly.startTrace(traceKey); + } + app.endTrace = function () { + var traceKey = "Trace Key"; + var customMetric = { + "ABC": 1233, + "C44C": 1337 + }; + Countly.endTrace(traceKey, customMetric); + } + function random(number) { + return Math.floor(Math.random() * number); + } + app.recordNetworkTraceSuccess = function () { + var networkTraceKey = "api/endpoint.1"; + var responseCode = successCodes[random(successCodes.length)]; + var requestPayloadSize = random(700) + 200; + var responsePayloadSize = random(700) + 200; + var startTime = new Date().getTime(); + var endTime = startTime + 500; + Countly.recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime); + } + app.recordNetworkTraceFailure = function () { + var networkTraceKey = "api/endpoint.1"; + var responseCode = failureCodes[random(failureCodes.length)]; + var requestPayloadSize = random(700) + 250; + var responsePayloadSize = random(700) + 250; + var startTime = new Date().getTime(); + var endTime = startTime + 500; + Countly.recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime); + } + app.enableApm = function () { + Countly.enableApm(); + } + app.setCustomCrashSegment = function () { + var segment = { "Key": "Value" }; + Countly.setCustomCrashSegment(segment); + } // Remote config usage // /** Use StackTrace to log all exceptions **/ @@ -861,4 +876,4 @@

Countly Cordova Demo App

- + \ No newline at end of file diff --git a/src/android/CountlyCordova.java b/src/android/CountlyCordova.java index ff0cdda..6082ff1 100644 --- a/src/android/CountlyCordova.java +++ b/src/android/CountlyCordova.java @@ -21,17 +21,18 @@ public class CountlyCordova extends CordovaPlugin { public CountlyNative countlyNative = null; + public enum CountlyMessagingMode { - TEST, - PRODUCTION, + TEST, PRODUCTION, } @Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); Context context = this.cordova.getActivity().getApplicationContext(); - if(countlyNative == null){ - countlyNative = new CountlyNative( this.cordova.getActivity(), this.cordova.getActivity().getApplicationContext()); + if (countlyNative == null) { + countlyNative = new CountlyNative(this.cordova.getActivity(), + this.cordova.getActivity().getApplicationContext()); } } @@ -39,61 +40,49 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) { public void pluginInitialize() { } + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { Context context = this.cordova.getActivity().getApplicationContext(); - + if ("init".equals(action)) { callbackContext.success(countlyNative.init(args)); } if ("isInitialized".equals(action)) { callbackContext.success(countlyNative.isInitialized(args)); - } - else if("getCurrentDeviceId".equals(action)){ + } else if ("getCurrentDeviceId".equals(action)) { callbackContext.success(countlyNative.getCurrentDeviceId(args)); - } - else if("getDeviceIdAuthor".equals(action)){ + } else if ("getDeviceIdAuthor".equals(action)) { callbackContext.success(countlyNative.getDeviceIdAuthor(args)); - } - else if ("changeDeviceId".equals(action)){ + } else if ("changeDeviceId".equals(action)) { callbackContext.success(countlyNative.changeDeviceId(args)); - } - else if ("setHttpPostForced".equals(action)){ + } else if ("setHttpPostForced".equals(action)) { callbackContext.success(countlyNative.setHttpPostForced(args)); - } - else if("enableParameterTamperingProtection".equals(action)){ + } else if ("enableParameterTamperingProtection".equals(action)) { callbackContext.success(countlyNative.enableParameterTamperingProtection(args)); - } - else if("setLocationInit".equals(action)){ + } else if ("setLocationInit".equals(action)) { callbackContext.success(countlyNative.setLocationInit(args)); - } - else if("setLocation".equals(action)){ + } else if ("setLocation".equals(action)) { callbackContext.success(countlyNative.setLocation(args)); - } - else if("enableCrashReporting".equals(action)){ + } else if ("enableCrashReporting".equals(action)) { callbackContext.success(countlyNative.enableCrashReporting(args)); - } - else if("addCrashLog".equals(action)){ + } else if ("addCrashLog".equals(action)) { callbackContext.success(countlyNative.addCrashLog(args)); - } - else if("logException".equals(action)){ + } else if ("logException".equals(action)) { callbackContext.success(countlyNative.logException(args)); } else if ("start".equals(action)) { callbackContext.success(countlyNative.start(args)); - } - else if ("stop".equals(action)) { + } else if ("stop".equals(action)) { callbackContext.success(countlyNative.stop(args)); - } - else if ("halt".equals(action)) { + } else if ("halt".equals(action)) { callbackContext.success(countlyNative.halt(args)); } else if ("askForNotificationPermission".equals(action)) { callbackContext.success(countlyNative.askForNotificationPermission(args)); - } - else if ("registerForNotification".equals(action)) { - PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); + } else if ("registerForNotification".equals(action)) { + PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); countlyNative.registerForNotification(args, new CountlyNative.Callback() { @@ -103,25 +92,21 @@ public void callback(String result) { } }); - } - else if ("pushTokenType".equals(action)) { + } else if ("pushTokenType".equals(action)) { callbackContext.success(countlyNative.pushTokenType(args)); } - else if("startEvent".equals(action)){ + else if ("startEvent".equals(action)) { callbackContext.success(countlyNative.startEvent(args)); - } - else if("cancelEvent".equals(action)){ + } else if ("cancelEvent".equals(action)) { callbackContext.success(countlyNative.cancelEvent(args)); - } - else if("endEvent".equals(action)){ + } else if ("endEvent".equals(action)) { callbackContext.success(countlyNative.endEvent(args)); - } - else if("recordEvent".equals(action)){ + } else if ("recordEvent".equals(action)) { callbackContext.success(countlyNative.recordEvent(args)); } // else if ("event".equals(action)) { - // callbackContext.success(countlyNative.recordEvent(args)); + // callbackContext.success(countlyNative.recordEvent(args)); // } else if ("setLoggingEnabled".equals(action)) { callbackContext.success(countlyNative.setLoggingEnabled(args)); @@ -129,182 +114,143 @@ else if ("setLoggingEnabled".equals(action)) { else if ("setuserdata".equals(action)) { callbackContext.success(countlyNative.setuserdata(args)); - } - else if ("userData_setProperty".equals(action)) { + } else if ("userData_setProperty".equals(action)) { callbackContext.success(countlyNative.userData_setProperty(args)); - } - else if ("userData_increment".equals(action)) { + } else if ("userData_increment".equals(action)) { callbackContext.success(countlyNative.userData_increment(args)); - } - else if ("userData_incrementBy".equals(action)) { + } else if ("userData_incrementBy".equals(action)) { callbackContext.success(countlyNative.userData_incrementBy(args)); - } - else if ("userData_multiply".equals(action)) { + } else if ("userData_multiply".equals(action)) { callbackContext.success(countlyNative.userData_multiply(args)); - } - else if ("userData_saveMax".equals(action)) { + } else if ("userData_saveMax".equals(action)) { callbackContext.success(countlyNative.userData_saveMax(args)); - } - else if ("userData_saveMin".equals(action)) { + } else if ("userData_saveMin".equals(action)) { callbackContext.success(countlyNative.userData_saveMin(args)); - } - else if ("userData_setOnce".equals(action)) { + } else if ("userData_setOnce".equals(action)) { callbackContext.success(countlyNative.userData_setOnce(args)); - } - else if ("userData_pushUniqueValue".equals(action)) { + } else if ("userData_pushUniqueValue".equals(action)) { callbackContext.success(countlyNative.userData_pushUniqueValue(args)); - } - else if ("userData_pushValue".equals(action)) { + } else if ("userData_pushValue".equals(action)) { callbackContext.success(countlyNative.userData_pushValue(args)); - } - else if ("userData_pullValue".equals(action)) { + } else if ("userData_pullValue".equals(action)) { callbackContext.success(countlyNative.userData_pullValue(args)); } - //setRequiresConsent + // setRequiresConsent else if ("setRequiresConsent".equals(action)) { callbackContext.success(countlyNative.setRequiresConsent(args)); - } - else if ("giveConsentInit".equals(action)) { + } else if ("giveConsentInit".equals(action)) { callbackContext.success(countlyNative.giveConsentInit(args)); - } - else if ("giveConsent".equals(action)) { + } else if ("giveConsent".equals(action)) { callbackContext.success(countlyNative.giveConsent(args)); - } - else if ("removeConsent".equals(action)) { + } else if ("removeConsent".equals(action)) { callbackContext.success(countlyNative.removeConsent(args)); - } - else if ("giveAllConsent".equals(action)) { + } else if ("giveAllConsent".equals(action)) { callbackContext.success(countlyNative.giveAllConsent(args)); - } - else if ("removeAllConsent".equals(action)) { + } else if ("removeAllConsent".equals(action)) { callbackContext.success(countlyNative.removeConsent(args)); } // else if("sendRating".equals(action)){ - // callbackContext.success(countlyNative.sendRating(args)); + // callbackContext.success(countlyNative.sendRating(args)); // } - else if("recordView".equals(action)){ + else if ("recordView".equals(action)) { callbackContext.success(countlyNative.recordView(args)); - } - else if("setOptionalParametersForInitialization".equals(action)){ + } else if ("setOptionalParametersForInitialization".equals(action)) { callbackContext.success(countlyNative.setOptionalParametersForInitialization(args)); - } - else if("setRemoteConfigAutomaticDownload".equals(action)){ + } else if ("setRemoteConfigAutomaticDownload".equals(action)) { countlyNative.setRemoteConfigAutomaticDownload(args, new CountlyNative.Callback() { @Override public void callback(String result) { callbackContext.success(result); } }); - } - else if("remoteConfigUpdate".equals(action)){ + } else if ("remoteConfigUpdate".equals(action)) { countlyNative.remoteConfigUpdate(args, new CountlyNative.Callback() { @Override public void callback(String result) { callbackContext.success(result); } }); - } - else if("updateRemoteConfigForKeysOnly".equals(action)){ + } else if ("updateRemoteConfigForKeysOnly".equals(action)) { countlyNative.updateRemoteConfigForKeysOnly(args, new CountlyNative.Callback() { @Override public void callback(String result) { callbackContext.success(result); } }); - } - else if("updateRemoteConfigExceptKeys".equals(action)){ + } else if ("updateRemoteConfigExceptKeys".equals(action)) { countlyNative.updateRemoteConfigExceptKeys(args, new CountlyNative.Callback() { @Override public void callback(String result) { callbackContext.success(result); } }); - } - else if("remoteConfigClearValues".equals(action)){ + } else if ("remoteConfigClearValues".equals(action)) { callbackContext.success(countlyNative.remoteConfigClearValues(args)); - } - else if("getRemoteConfigValueForKey".equals(action)){ + } else if ("getRemoteConfigValueForKey".equals(action)) { callbackContext.success(countlyNative.getRemoteConfigValueForKey(args)); - } - else if("setStarRatingDialogTexts".equals(action)){ + } else if ("setStarRatingDialogTexts".equals(action)) { callbackContext.success(countlyNative.setStarRatingDialogTexts(args)); - } - else if("askForStarRating".equals(action)){ + } else if ("askForStarRating".equals(action)) { callbackContext.success(countlyNative.askForStarRating(args)); - } - else if("askForFeedback".equals(action)){ + } else if ("askForFeedback".equals(action)) { countlyNative.askForFeedback(args, new CountlyNative.Callback() { @Override public void callback(String result) { callbackContext.success(result); } }); - } - else if("appLoadingFinished".equals(action)){ + } else if ("appLoadingFinished".equals(action)) { callbackContext.success(countlyNative.appLoadingFinished(args)); - } - else if ("getFeedbackWidgets".equals(action)) { + } else if ("getFeedbackWidgets".equals(action)) { countlyNative.getFeedbackWidgets(args, new CountlyNative.JSONObjectCallback() { @Override public void success(JSONArray result) { - PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, - result); + PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } + @Override public void error(String error) { callbackContext.error(error); } }); - } - else if("presentFeedbackWidget".equals(action)){ + } else if ("presentFeedbackWidget".equals(action)) { countlyNative.presentFeedbackWidget(args, new CountlyNative.Callback() { @Override public void callback(String result) { callbackContext.success(result); } }); - } - else if("replaceAllAppKeysInQueueWithCurrentAppKey".equals(action)){ + } else if ("replaceAllAppKeysInQueueWithCurrentAppKey".equals(action)) { countlyNative.replaceAllAppKeysInQueueWithCurrentAppKey(); callbackContext.success("replaceAllAppKeysInQueueWithCurrentAppKey : Success"); - } - else if("removeDifferentAppKeysFromQueue".equals(action)){ + } else if ("removeDifferentAppKeysFromQueue".equals(action)) { countlyNative.removeDifferentAppKeysFromQueue(); callbackContext.success("removeDifferentAppKeysFromQueue : Success"); - } - else if("sendPushToken".equals(action)){ + } else if ("sendPushToken".equals(action)) { callbackContext.success(countlyNative.sendPushToken(args)); - } - else if("enableAttribution".equals(action)){ + } else if ("enableAttribution".equals(action)) { callbackContext.success(countlyNative.enableAttribution(args)); - } - else if("startTrace".equals(action)){ + } else if ("startTrace".equals(action)) { callbackContext.success(countlyNative.startTrace(args)); - } - else if("cancelTrace".equals(action)){ + } else if ("cancelTrace".equals(action)) { callbackContext.success(countlyNative.cancelTrace(args)); - } - else if("clearAllTraces".equals(action)){ + } else if ("clearAllTraces".equals(action)) { callbackContext.success(countlyNative.clearAllTraces(args)); - } - else if("endTrace".equals(action)){ + } else if ("endTrace".equals(action)) { callbackContext.success(countlyNative.endTrace(args)); - } - else if("recordNetworkTrace".equals(action)){ + } else if ("recordNetworkTrace".equals(action)) { callbackContext.success(countlyNative.recordNetworkTrace(args)); - } - else if("enableApm".equals(action)){ + } else if ("enableApm".equals(action)) { callbackContext.success(countlyNative.enableApm(args)); - } - else{ + } else { return false; } return true; - } + } @Override public void onResume(boolean multitasking) { diff --git a/src/android/CountlyMessagingService.java b/src/android/CountlyMessagingService.java index 977bada..21aafb7 100644 --- a/src/android/CountlyMessagingService.java +++ b/src/android/CountlyMessagingService.java @@ -22,15 +22,15 @@ public void onNewToken(String token) { public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); - if(!Countly.sharedInstance().isInitialized()) { + if (!Countly.sharedInstance().isInitialized()) { int mode = CountlyPush.getLastMessagingMethod(this); - if(mode == 0) { + if (mode == 0) { CountlyPush.init(getApplication(), Countly.CountlyMessagingMode.TEST); - } else if(mode == 1) { + } else if (mode == 1) { CountlyPush.init(getApplication(), Countly.CountlyMessagingMode.PRODUCTION); } } - + Log.d(TAG, "got new message: " + remoteMessage.getData()); // decode message data and extract meaningful information from it: title, body, badge, etc. diff --git a/src/android/CountlyNative.java b/src/android/CountlyNative.java index 8255d34..a76d020 100644 --- a/src/android/CountlyNative.java +++ b/src/android/CountlyNative.java @@ -1,4 +1,5 @@ package ly.count.android.sdk; + import ly.count.android.sdk.Countly; import ly.count.android.sdk.DeviceId; import ly.count.android.sdk.RemoteConfig; @@ -32,7 +33,6 @@ import com.google.firebase.FirebaseApp; import ly.count.android.sdk.ModuleFeedback.*; - public class CountlyNative { public static final String TAG = "CountlyCordovaPlugin"; @@ -48,46 +48,42 @@ public class CountlyNative { private static String lastStoredNotification = null; private final Set validConsentFeatureNames = new HashSet(Arrays.asList( - Countly.CountlyFeatureNames.sessions, - Countly.CountlyFeatureNames.events, - Countly.CountlyFeatureNames.views, - Countly.CountlyFeatureNames.location, - Countly.CountlyFeatureNames.crashes, - Countly.CountlyFeatureNames.attribution, - Countly.CountlyFeatureNames.users, - Countly.CountlyFeatureNames.push, - Countly.CountlyFeatureNames.starRating, - Countly.CountlyFeatureNames.apm, - Countly.CountlyFeatureNames.feedback, - Countly.CountlyFeatureNames.remoteConfig - )); - public CountlyNative(Activity _activity, Context _context){ + Countly.CountlyFeatureNames.sessions, Countly.CountlyFeatureNames.events, Countly.CountlyFeatureNames.views, + Countly.CountlyFeatureNames.location, Countly.CountlyFeatureNames.crashes, + Countly.CountlyFeatureNames.attribution, Countly.CountlyFeatureNames.users, + Countly.CountlyFeatureNames.push, Countly.CountlyFeatureNames.starRating, Countly.CountlyFeatureNames.apm, + Countly.CountlyFeatureNames.feedback, Countly.CountlyFeatureNames.remoteConfig)); + + public CountlyNative(Activity _activity, Context _context) { this.activity = _activity; this.context = _context; Countly.sharedInstance(); this.config.enableManualAppLoadedTrigger(); this.config.enableManualForegroundBackgroundTriggerAPM(); } - public static void onNotification(Map notification){ + + public static void onNotification(Map notification) { JSONObject json = new JSONObject(notification); String notificationString = json.toString(); log(notificationString, LogLevel.INFO); - if(notificationListener != null){ + if (notificationListener != null) { notificationListener.callback(notificationString); - }else{ + } else { lastStoredNotification = notificationString; } } + public interface Callback { void callback(String result); } + public interface JSONObjectCallback { void error(String result); + void success(JSONArray result); } - - public String init(JSONArray args){ + public String init(JSONArray args) { try { this.log("init", args); String serverUrl = args.getString(0); @@ -101,77 +97,74 @@ public String init(JSONArray args){ if (args.length() == 2) { } else if (args.length() == 3) { String yourDeviceID = args.getString(2); - if(yourDeviceID.equals("TemporaryDeviceID")){ + if (yourDeviceID.equals("TemporaryDeviceID")) { this.config.enableTemporaryDeviceIdMode(); - }else{ + } else { this.config.setDeviceId(yourDeviceID); } - } + } if (activity == null) { - if(Countly.sharedInstance().isLoggingEnabled()) { + if (Countly.sharedInstance().isLoggingEnabled()) { log("Activity is 'null' during init, cannot set Application", LogLevel.WARNING); } - } - else { + } else { this.config.setApplication(activity.getApplication()); } Countly.sharedInstance().init(this.config); Countly.sharedInstance().apm().triggerForeground(); return "initialized: success"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String isInitialized(JSONArray args){ + public String isInitialized(JSONArray args) { this.log("isInitialized", args); Boolean isInitialized = Countly.sharedInstance().isInitialized(); - if(isInitialized){ - return "true"; + if (isInitialized) { + return "true"; - }else{ - return "false"; - } + } else { + return "false"; + } } - public void log(String method, JSONArray args){ - if(isDebug){ - log("Method: "+method, LogLevel.INFO); - log("Arguments: "+args.toString(), LogLevel.INFO); + public void log(String method, JSONArray args) { + if (isDebug) { + log("Method: " + method, LogLevel.INFO); + log("Arguments: " + args.toString(), LogLevel.INFO); } } - public String getCurrentDeviceId(JSONArray args){ + public String getCurrentDeviceId(JSONArray args) { String deviceID = Countly.sharedInstance().getDeviceID(); if (deviceID == null) { log("getCurrentDeviceId, deviceIdNotFound", LogLevel.DEBUG); return "deviceIdNotFound"; - } - else { + } else { log("getCurrentDeviceId: " + deviceID, LogLevel.DEBUG); return deviceID; } } - public String getDeviceIdAuthor(JSONArray args){ + public String getDeviceIdAuthor(JSONArray args) { DeviceId.Type deviceIDType = Countly.sharedInstance().getDeviceIDType(); if (deviceIDType == null) { log("getDeviceIdAuthor, deviceIdAuthorNotFound", LogLevel.DEBUG); return "deviceIdAuthorNotFound"; - } - else { + } else { log("getDeviceIdAuthor: " + deviceIDType, LogLevel.DEBUG); - if(deviceIDType == DeviceId.Type.DEVELOPER_SUPPLIED){ + if (deviceIDType == DeviceId.Type.DEVELOPER_SUPPLIED) { return "developerProvided"; - }else{ + } else { return "sdkGenerated"; } } } - public String changeDeviceId(JSONArray args){ + public String changeDeviceId(JSONArray args) { try { this.log("changeDeviceId", args); String newDeviceID = args.getString(0); @@ -182,12 +175,12 @@ public String changeDeviceId(JSONArray args){ Countly.sharedInstance().deviceId().changeWithoutMerge(newDeviceID); } return "changeDeviceId success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String setHttpPostForced(JSONArray args){ + public String setHttpPostForced(JSONArray args) { try { this.log("setHttpPostForced", args); int isEnabled = Integer.parseInt(args.getString(0)); @@ -197,91 +190,92 @@ public String setHttpPostForced(JSONArray args){ this.config.setHttpPostForced(false); } return "setHttpPostForced"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String enableParameterTamperingProtection(JSONArray args){ + public String enableParameterTamperingProtection(JSONArray args) { try { this.log("enableParameterTamperingProtection", args); String salt = args.getString(0); this.config.setParameterTamperingProtectionSalt(salt); return "setParameterTamperingProtectionSalt success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String setLocationInit(JSONArray args){ + public String setLocationInit(JSONArray args) { try { this.log("setLocationInit", args); String countryCode = args.getString(0); String city = args.getString(1); String location = args.getString(2); String ipAddress = args.getString(3); - if("null".equals(countryCode)){ + if ("null".equals(countryCode)) { countryCode = null; } - if("null".equals(city)){ + if ("null".equals(city)) { city = null; } - if("null".equals(location)){ + if ("null".equals(location)) { location = null; } - if("null".equals(ipAddress)){ + if ("null".equals(ipAddress)) { ipAddress = null; } this.config.setLocation(countryCode, city, location, ipAddress); return "setLocationInit sent."; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String setLocation(JSONArray args){ + public String setLocation(JSONArray args) { try { this.log("setLocation", args); String countryCode = args.getString(0); String city = args.getString(1); String location = args.getString(2); String ipAddress = args.getString(3); - if("null".equals(countryCode)){ + if ("null".equals(countryCode)) { countryCode = null; } - if("null".equals(city)){ + if ("null".equals(city)) { city = null; } - if("null".equals(location)){ + if ("null".equals(location)) { location = null; } - if("null".equals(ipAddress)){ + if ("null".equals(ipAddress)) { ipAddress = null; } Countly.sharedInstance().setLocation(countryCode, city, location, ipAddress); return "setLocation success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String enableCrashReporting(JSONArray args){ + public String enableCrashReporting(JSONArray args) { this.log("enableCrashReporting", args); this.config.enableCrashReporting(); return "enableCrashReporting success!"; } - public String addCrashLog(JSONArray args){ + public String addCrashLog(JSONArray args) { try { this.log("addCrashLog", args); String record = args.getString(0); Countly.sharedInstance().crashes().addCrashBreadcrumb(record); return "addCrashLog success"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String setCustomCrashSegments(JSONArray args){ + + public String setCustomCrashSegments(JSONArray args) { try { this.log("setCustomCrashSegments", args); HashMap segments = new HashMap(); @@ -290,130 +284,130 @@ public String setCustomCrashSegments(JSONArray args){ } this.config.setCustomCrashSegment(segments); return "setCustomCrashSegments"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String logException(JSONArray args){ + public String logException(JSONArray args) { try { this.log("logException", args); String exceptionString = args.getString(0); Exception exception = new Exception(exceptionString); Countly.sharedInstance().crashes().recordHandledException(exception); return "logException success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String askForNotificationPermission(JSONArray args){ + public String askForNotificationPermission(JSONArray args) { this.log("askForNotificationPermission", args); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { String channelName = "Default Name"; String channelDescription = "Default Description"; - NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); + NotificationManager notificationManager = (NotificationManager) context + .getSystemService(context.NOTIFICATION_SERVICE); if (notificationManager != null) { - NotificationChannel channel = new NotificationChannel(CountlyPush.CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_DEFAULT); + NotificationChannel channel = new NotificationChannel(CountlyPush.CHANNEL_ID, channelName, + NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(channelDescription); notificationManager.createNotificationChannel(channel); } - } - CountlyPush.init(activity.getApplication(), pushTokenTypeVariable); - FirebaseApp.initializeApp(context); - FirebaseInstanceId.getInstance().getInstanceId() - .addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(Task task) { - if (!task.isSuccessful()) { - log("getInstanceId failed", task.getException(), LogLevel.WARNING); - return; - } - String token = task.getResult().getToken(); - CountlyPush.onTokenRefresh(token); - } - }); - return "askForNotificationPermission"; - } - public String registerForNotification(JSONArray args, final Callback theCallback){ + } + CountlyPush.init(activity.getApplication(), pushTokenTypeVariable); + FirebaseApp.initializeApp(context); + FirebaseInstanceId.getInstance().getInstanceId() + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(Task task) { + if (!task.isSuccessful()) { + log("getInstanceId failed", task.getException(), LogLevel.WARNING); + return; + } + String token = task.getResult().getToken(); + CountlyPush.onTokenRefresh(token); + } + }); + return "askForNotificationPermission"; + } + + public String registerForNotification(JSONArray args, final Callback theCallback) { notificationListener = theCallback; log("registerForNotification theCallback", LogLevel.INFO); - if(lastStoredNotification != null){ + if (lastStoredNotification != null) { theCallback.callback(lastStoredNotification); lastStoredNotification = null; } return "pushTokenType: success"; } - public String pushTokenType(JSONArray args){ + public String pushTokenType(JSONArray args) { try { this.log("pushTokenType", args); String tokenType = args.getString(0); - if("2".equals(tokenType)){ + if ("2".equals(tokenType)) { pushTokenTypeVariable = Countly.CountlyMessagingMode.TEST; - }else{ + } else { pushTokenTypeVariable = Countly.CountlyMessagingMode.PRODUCTION; } return "pushTokenType: success"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String start(JSONArray args){ + public String start(JSONArray args) { this.log("start", args); Countly.sharedInstance().onStart(activity); return "started: success"; } - public String stop(JSONArray args){ + public String stop(JSONArray args) { this.log("stop", args); Countly.sharedInstance().onStop(); return "stoped: success"; } - public String halt(JSONArray args){ + public String halt(JSONArray args) { this.log("halt", args); Countly.sharedInstance().halt(); return "halt: success"; } - - // public String eventSendThreshold(JSONArray args){ - // try { - // int eventSendThreshold = Integer.parseInt(args.getString(0)); - // Countly.sharedInstance().setEventQueueSizeToSend(eventSendThreshold); - // return "default"; - // }catch (JSONException jsonException){ - // return jsonException.toString(); - // } + // try { + // int eventSendThreshold = Integer.parseInt(args.getString(0)); + // Countly.sharedInstance().setEventQueueSizeToSend(eventSendThreshold); + // return "default"; + // }catch (JSONException jsonException){ + // return jsonException.toString(); + // } // } - - - public String startEvent(JSONArray args){ + public String startEvent(JSONArray args) { try { this.log("startEvent", args); String startEvent = args.getString(0); Countly.sharedInstance().events().startEvent(startEvent); return "startEvent"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String cancelEvent(JSONArray args){ + + public String cancelEvent(JSONArray args) { try { this.log("cancelEvent", args); String cancelEvent = args.getString(0); Countly.sharedInstance().events().cancelEvent(cancelEvent); return "cancelEvent"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String endEvent(JSONArray args){ + public String endEvent(JSONArray args) { try { this.log("endEvent", args); String key = args.getString(0); @@ -427,12 +421,12 @@ public String endEvent(JSONArray args){ } Countly.sharedInstance().events().endEvent(key, segmentation, count, sum); return "endEvent for:" + key; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String recordEvent(JSONArray args){ + public String recordEvent(JSONArray args) { try { this.log("recordEvent", args); String key = args.getString(0); @@ -447,12 +441,12 @@ public String recordEvent(JSONArray args){ } Countly.sharedInstance().events().recordEvent(key, segmentation, count, sum, duration); return "recordEvent for: " + key; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String setLoggingEnabled(JSONArray args){ + public String setLoggingEnabled(JSONArray args) { try { this.log("setLoggingEnabled", args); String loggingEnable = args.getString(0); @@ -464,26 +458,26 @@ public String setLoggingEnabled(JSONArray args){ this.config.setLoggingEnabled(false); } return "setLoggingEnabled success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String setuserdata(JSONArray args){ + public String setuserdata(JSONArray args) { try { this.log("setuserdata", args); JSONObject userData = args.getJSONObject(0); - Map userDataMap = toMap(userData); + Map userDataMap = toMap(userData); Countly.sharedInstance().userProfile().setProperties(userDataMap); Countly.sharedInstance().userProfile().save(); return "setuserdata success"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String userData_setProperty(JSONArray args){ + public String userData_setProperty(JSONArray args) { try { this.log("userData_setProperty", args); String keyName = args.getString(0); @@ -491,25 +485,24 @@ public String userData_setProperty(JSONArray args){ Countly.userData.setProperty(keyName, keyValue); Countly.userData.save(); return "userData_setProperty success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String userData_increment(JSONArray args){ + public String userData_increment(JSONArray args) { try { this.log("userData_increment", args); String keyName = args.getString(0); Countly.userData.increment(keyName); Countly.userData.save(); return "userData_increment: success"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - - public String userData_incrementBy(JSONArray args){ + public String userData_incrementBy(JSONArray args) { try { this.log("userData_incrementBy", args); String keyName = args.getString(0); @@ -517,12 +510,12 @@ public String userData_incrementBy(JSONArray args){ Countly.userData.incrementBy(keyName, keyIncrement); Countly.userData.save(); return "userData_incrementBy success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String userData_multiply(JSONArray args){ + public String userData_multiply(JSONArray args) { try { this.log("userData_multiply", args); String keyName = args.getString(0); @@ -530,12 +523,12 @@ public String userData_multiply(JSONArray args){ Countly.userData.multiply(keyName, multiplyValue); Countly.userData.save(); return "userData_multiply success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String userData_saveMax(JSONArray args){ + public String userData_saveMax(JSONArray args) { try { this.log("userData_saveMax", args); String keyName = args.getString(0); @@ -543,12 +536,12 @@ public String userData_saveMax(JSONArray args){ Countly.userData.saveMax(keyName, maxScore); Countly.userData.save(); return "userData_saveMax success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String userData_saveMin(JSONArray args){ + public String userData_saveMin(JSONArray args) { try { this.log("userData_saveMin", args); String keyName = args.getString(0); @@ -556,12 +549,12 @@ public String userData_saveMin(JSONArray args){ Countly.userData.saveMin(keyName, minScore); Countly.userData.save(); return "userData_saveMin success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String userData_setOnce(JSONArray args){ + public String userData_setOnce(JSONArray args) { try { this.log("userData_setOnce", args); String keyName = args.getString(0); @@ -569,12 +562,12 @@ public String userData_setOnce(JSONArray args){ Countly.userData.setOnce(keyName, minScore); Countly.userData.save(); return "userData_setOnce success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String userData_pushUniqueValue(JSONArray args){ + public String userData_pushUniqueValue(JSONArray args) { try { this.log("userData_pushUniqueValue", args); String type = args.getString(0); @@ -582,12 +575,12 @@ public String userData_pushUniqueValue(JSONArray args){ Countly.userData.pushUniqueValue(type, pushUniqueValue); Countly.userData.save(); return "userData_pushUniqueValue success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String userData_pushValue(JSONArray args){ + public String userData_pushValue(JSONArray args) { try { this.log("userData_pushValue", args); String type = args.getString(0); @@ -595,12 +588,12 @@ public String userData_pushValue(JSONArray args){ Countly.userData.pushValue(type, pushValue); Countly.userData.save(); return "userData_pushValue success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String userData_pullValue(JSONArray args){ + public String userData_pullValue(JSONArray args) { try { this.log("userData_pullValue", args); String type = args.getString(0); @@ -608,12 +601,12 @@ public String userData_pullValue(JSONArray args){ Countly.userData.pullValue(type, pullValue); Countly.userData.save(); return "userData_pullValue success!"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String setRequiresConsent(JSONArray args){ + public String setRequiresConsent(JSONArray args) { try { this.log("setRequiresConsent", args); String consentFlagString = args.getString(0); @@ -623,12 +616,12 @@ public String setRequiresConsent(JSONArray args){ } this.config.setRequiresConsent(consentFlag); return "setRequiresConsent: Success"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String giveConsentInit(JSONArray featureNames){ + public String giveConsentInit(JSONArray featureNames) { try { this.log("giveConsentInit", featureNames); List features = new ArrayList<>(); @@ -636,19 +629,18 @@ public String giveConsentInit(JSONArray featureNames){ String featureName = featureNames.getString(i); if (validConsentFeatureNames.contains(featureName)) { features.add(featureName); - } - else { + } else { log("Not a valid consent feature to add: " + featureName, LogLevel.DEBUG); } } this.config.setConsentEnabled(features.toArray(new String[features.size()])); return "giveConsentInit: Success"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String giveConsent(JSONArray featureNames){ + public String giveConsent(JSONArray featureNames) { try { this.log("giveConsent", featureNames); List features = new ArrayList<>(); @@ -656,19 +648,18 @@ public String giveConsent(JSONArray featureNames){ String featureName = featureNames.getString(i); if (validConsentFeatureNames.contains(featureName)) { features.add(featureName); - } - else { + } else { log("Not a valid consent feature to add: " + featureName, LogLevel.DEBUG); } } Countly.sharedInstance().consent().giveConsent(features.toArray(new String[features.size()])); return "giveConsent: Success"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String removeConsent(JSONArray featureNames){ + public String removeConsent(JSONArray featureNames) { try { this.log("removeConsent", featureNames); List features = new ArrayList<>(); @@ -676,69 +667,68 @@ public String removeConsent(JSONArray featureNames){ String featureName = featureNames.getString(i); if (validConsentFeatureNames.contains(featureName)) { features.add(featureName); - } - else { + } else { log("Not a valid consent feature to remove: " + featureName, LogLevel.DEBUG); } } Countly.sharedInstance().consent().removeConsent(features.toArray(new String[features.size()])); return "removeConsent: Success"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String giveAllConsent(JSONArray args){ + public String giveAllConsent(JSONArray args) { this.log("giveAllConsent", args); Countly.sharedInstance().consent().giveConsentAll(); return "giveAllConsent: Success"; } - public String removeAllConsent(JSONArray args){ + public String removeAllConsent(JSONArray args) { this.log("removeAllConsent", args); Countly.sharedInstance().consent().removeConsentAll(); return "removeAllConsent: Success"; } // public String sendRating(JSONArray args){ - // try { - // String ratingString = args.getString(0); - // int rating = Integer.parseInt(ratingString); - - // Map segm = new HashMap<>(); - // segm.put("platform", "android"); - // // segm.put("app_version", DeviceInfo.getAppVersion(context)); - // segm.put("rating", "" + rating); - - // Countly.sharedInstance().recordEvent("[CLY]_star_rating", segm, 1); - // return "sendRating: " + ratingString; - // }catch (JSONException jsonException){ - // return jsonException.toString(); - // } + // try { + // String ratingString = args.getString(0); + // int rating = Integer.parseInt(ratingString); + + // Map segm = new HashMap<>(); + // segm.put("platform", "android"); + // // segm.put("app_version", DeviceInfo.getAppVersion(context)); + // segm.put("rating", "" + rating); + + // Countly.sharedInstance().recordEvent("[CLY]_star_rating", segm, 1); + // return "sendRating: " + ratingString; + // }catch (JSONException jsonException){ + // return jsonException.toString(); + // } // } - public String recordView(JSONArray args){ + public String recordView(JSONArray args) { try { this.log("recordView", args); String viewName = args.getString(0); HashMap segmentation = new HashMap(); - for(int i=1,il=args.length();i retrievedWidgets, String error) { - if(error != null) { + if (error != null) { theCallback.error(error); } @@ -931,9 +925,9 @@ public void onFinished(List retrievedWidgets, String erro return "getAvailableFeedbackWidgets success."; } - public String presentFeedbackWidget(JSONArray args, final Callback theCallback){ + public String presentFeedbackWidget(JSONArray args, final Callback theCallback) { if (activity == null) { - if(Countly.sharedInstance().isLoggingEnabled()) { + if (Countly.sharedInstance().isLoggingEnabled()) { log("presentFeedbackWidget failed : Activity is null", LogLevel.ERROR); } theCallback.callback("presentFeedbackWidget Failed, Activity is null"); @@ -946,111 +940,108 @@ public String presentFeedbackWidget(JSONArray args, final Callback theCallback){ String widgetName = args.getString(2); String closeButtonText = args.getString(3); CountlyFeedbackWidget presentableFeedback = new CountlyFeedbackWidget(); - presentableFeedback.widgetId = widgetId; - presentableFeedback.type = FeedbackWidgetType.valueOf(widgetType); - presentableFeedback.name = widgetName; - Countly.sharedInstance().feedback().presentFeedbackWidget(presentableFeedback, activity, closeButtonText, new FeedbackCallback() { - @Override - public void onClosed() { - // TODO : send on close result to react native JS side - } - - @Override - public void onFinished(String error) { - if(error != null) { - theCallback.callback(error); - } - else { - theCallback.callback("presentFeedbackWidget success"); - } - } - }); + presentableFeedback.widgetId = widgetId; + presentableFeedback.type = FeedbackWidgetType.valueOf(widgetType); + presentableFeedback.name = widgetName; + Countly.sharedInstance().feedback().presentFeedbackWidget(presentableFeedback, activity, closeButtonText, + new FeedbackCallback() { + @Override + public void onClosed() { + // TODO : send on close result to react native JS side + } + + @Override + public void onFinished(String error) { + if (error != null) { + theCallback.callback(error); + } else { + theCallback.callback("presentFeedbackWidget success"); + } + } + }); return "presentFeedbackWidget: success"; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { theCallback.callback(jsonException.toString()); return jsonException.toString(); } } - - public void replaceAllAppKeysInQueueWithCurrentAppKey(){ + public void replaceAllAppKeysInQueueWithCurrentAppKey() { Countly.sharedInstance().requestQueueOverwriteAppKeys(); } - public void removeDifferentAppKeysFromQueue(){ + public void removeDifferentAppKeysFromQueue() { Countly.sharedInstance().requestQueueEraseAppKeysRequests(); } - public String sendPushToken(JSONArray args){ + public String sendPushToken(JSONArray args) { try { this.log("sendPushToken", args); String token = args.getString(0); CountlyPush.onTokenRefresh(token); - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } return "sendPushToken success."; } - public String enableAttribution(JSONArray args){ + public String enableAttribution(JSONArray args) { this.log("enableAttribution", args); this.config.setEnableAttribution(true); return "enableAttribution success!"; } - public String startTrace(JSONArray args){ + public String startTrace(JSONArray args) { try { this.log("startTrace", args); String traceKey = args.getString(0); Countly.sharedInstance().apm().startTrace(traceKey); return "startTrace success."; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - public String cancelTrace(JSONArray args){ + public String cancelTrace(JSONArray args) { try { this.log("cancelTrace", args); String traceKey = args.getString(0); Countly.sharedInstance().apm().cancelTrace(traceKey); return "cancelTrace success."; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - - public String clearAllTraces(JSONArray args){ + public String clearAllTraces(JSONArray args) { this.log("clearAllTraces", args); Countly.sharedInstance().apm().cancelAllTraces(); return "clearAllTrace success."; } - public String endTrace(JSONArray args){ + public String endTrace(JSONArray args) { try { this.log("endTrace", args); String traceKey = args.getString(0); HashMap customMetric = new HashMap(); for (int i = 1, il = args.length(); i < il; i += 2) { - try{ + try { customMetric.put(args.getString(i), Integer.parseInt(args.getString(i + 1))); - }catch(Exception exception){ - if(Countly.sharedInstance().isLoggingEnabled()){ + } catch (Exception exception) { + if (Countly.sharedInstance().isLoggingEnabled()) { log("endTrace, could not parse metrics, skipping it. ", LogLevel.ERROR); } } } Countly.sharedInstance().apm().endTrace(traceKey, customMetric); return "endTrace success."; - }catch (JSONException jsonException){ + } catch (JSONException jsonException) { return jsonException.toString(); } } - - public String recordNetworkTrace(JSONArray args){ + public String recordNetworkTrace(JSONArray args) { try { this.log("recordNetworkTrace", args); String networkTraceKey = args.getString(0); @@ -1059,29 +1050,33 @@ public String recordNetworkTrace(JSONArray args){ int responsePayloadSize = Integer.parseInt(args.getString(3)); long startTime = Long.parseLong(args.getString(4)); long endTime = Long.parseLong(args.getString(5)); - Countly.sharedInstance().apm().recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime); + Countly.sharedInstance().apm().recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, + responsePayloadSize, startTime, endTime); return "recordNetworkTrace success."; - }catch (Exception exception){ - if(Countly.sharedInstance().isLoggingEnabled()){ + } catch (Exception exception) { + if (Countly.sharedInstance().isLoggingEnabled()) { log("Exception occured at recordNetworkTrace method: ", exception, LogLevel.ERROR); } return exception.toString(); } } - public String enableApm(JSONArray args){ + public String enableApm(JSONArray args) { this.log("enableApm", args); this.config.setRecordAppStartTime(true); return "enableApm success."; } - enum LogLevel {INFO, DEBUG, VERBOSE, WARNING, ERROR} - static void log(String message, LogLevel logLevel) { + enum LogLevel { + INFO, DEBUG, VERBOSE, WARNING, ERROR + } + + static void log(String message, LogLevel logLevel) { log(message, null, logLevel); } - static void log(String message, Throwable tr, LogLevel logLevel) { - if(!isDebug) { + static void log(String message, Throwable tr, LogLevel logLevel) { + if (!isDebug) { return; } switch (logLevel) { @@ -1104,13 +1099,13 @@ static void log(String message, Throwable tr, LogLevel logLevel) { } public void onHostResume() { - if(Countly.sharedInstance().isInitialized()) { + if (Countly.sharedInstance().isInitialized()) { Countly.sharedInstance().apm().triggerForeground(); } } public void onHostPause() { - if(Countly.sharedInstance().isInitialized()) { + if (Countly.sharedInstance().isInitialized()) { Countly.sharedInstance().apm().triggerBackground(); } } @@ -1145,5 +1140,4 @@ public static List toList(JSONArray array) throws JSONException { return list; } - } diff --git a/src/ios/CountlyCordova.h b/src/ios/CountlyCordova.h index 190fbc6..4a9add6 100644 --- a/src/ios/CountlyCordova.h +++ b/src/ios/CountlyCordova.h @@ -2,57 +2,56 @@ @interface CountlyCordova : CDVPlugin -- (void)init:(CDVInvokedUrlCommand*)command; -- (void)isInitialized:(CDVInvokedUrlCommand*)command; -- (void)event:(CDVInvokedUrlCommand*)command; -- (void)recordEvent:(CDVInvokedUrlCommand*)command; -- (void)setLoggingEnabled:(CDVInvokedUrlCommand*)command; -- (void)setuserdata:(CDVInvokedUrlCommand*)command; +- (void)init:(CDVInvokedUrlCommand *)command; +- (void)isInitialized:(CDVInvokedUrlCommand *)command; +- (void)event:(CDVInvokedUrlCommand *)command; +- (void)recordEvent:(CDVInvokedUrlCommand *)command; +- (void)setLoggingEnabled:(CDVInvokedUrlCommand *)command; +- (void)setuserdata:(CDVInvokedUrlCommand *)command; // - (void)getDeviceID:(CDVInvokedUrlCommand*)command; -- (void)sendRating:(CDVInvokedUrlCommand*)command; -- (void)start:(CDVInvokedUrlCommand*)command; -- (void)update:(CDVInvokedUrlCommand*)command; -- (void)halt:(CDVInvokedUrlCommand*)command; -- (void)manualSessionHandling:(CDVInvokedUrlCommand*)command; -- (void)stop:(CDVInvokedUrlCommand*)command; -- (void)updateSessionPeriod:(CDVInvokedUrlCommand*)command; -- (void)eventSendThreshold:(CDVInvokedUrlCommand*)command; -- (void)storedRequestsLimit:(CDVInvokedUrlCommand*)command; -- (void)recordView:(CDVInvokedUrlCommand*)command; -- (void)resume:(CDVInvokedUrlCommand*)command; -- (void)suspend:(CDVInvokedUrlCommand*)command; +- (void)sendRating:(CDVInvokedUrlCommand *)command; +- (void)start:(CDVInvokedUrlCommand *)command; +- (void)update:(CDVInvokedUrlCommand *)command; +- (void)halt:(CDVInvokedUrlCommand *)command; +- (void)manualSessionHandling:(CDVInvokedUrlCommand *)command; +- (void)stop:(CDVInvokedUrlCommand *)command; +- (void)updateSessionPeriod:(CDVInvokedUrlCommand *)command; +- (void)eventSendThreshold:(CDVInvokedUrlCommand *)command; +- (void)storedRequestsLimit:(CDVInvokedUrlCommand *)command; +- (void)recordView:(CDVInvokedUrlCommand *)command; +- (void)resume:(CDVInvokedUrlCommand *)command; +- (void)suspend:(CDVInvokedUrlCommand *)command; +- (void)setHttpPostForced:(CDVInvokedUrlCommand *)command; +- (void)setLocationInit:(CDVInvokedUrlCommand *)command; +- (void)setLocation:(CDVInvokedUrlCommand *)command; +- (void)enableCrashReporting:(CDVInvokedUrlCommand *)command; +- (void)addCrashLog:(CDVInvokedUrlCommand *)command; +- (void)logException:(CDVInvokedUrlCommand *)command; +- (void)sendPushToken:(CDVInvokedUrlCommand *)command; +- (void)askForNotificationPermission:(CDVInvokedUrlCommand *)command; +- (void)registerForNotification:(CDVInvokedUrlCommand *)command; +- (void)pushTokenType:(CDVInvokedUrlCommand *)command; -- (void)setHttpPostForced:(CDVInvokedUrlCommand*)command; -- (void)setLocationInit:(CDVInvokedUrlCommand*)command; -- (void)setLocation:(CDVInvokedUrlCommand*)command; -- (void)enableCrashReporting:(CDVInvokedUrlCommand*)command; -- (void)addCrashLog:(CDVInvokedUrlCommand*)command; -- (void)logException:(CDVInvokedUrlCommand*)command; -- (void)sendPushToken:(CDVInvokedUrlCommand*)command; -- (void)askForNotificationPermission:(CDVInvokedUrlCommand*)command; -- (void)registerForNotification:(CDVInvokedUrlCommand*)command; -- (void)pushTokenType:(CDVInvokedUrlCommand*)command; +- (void)getCurrentDeviceId:(CDVInvokedUrlCommand *)command; +- (void)getDeviceIdAuthor:(CDVInvokedUrlCommand *)command; +- (void)changeDeviceId:(CDVInvokedUrlCommand *)command; +- (void)enableParameterTamperingProtection:(CDVInvokedUrlCommand *)command; +- (void)startEvent:(CDVInvokedUrlCommand *)command; +- (void)cancelEvent:(CDVInvokedUrlCommand *)command; +- (void)endEvent:(CDVInvokedUrlCommand *)command; -- (void)getCurrentDeviceId:(CDVInvokedUrlCommand*)command; -- (void)getDeviceIdAuthor:(CDVInvokedUrlCommand*)command; -- (void)changeDeviceId:(CDVInvokedUrlCommand*)command; -- (void)enableParameterTamperingProtection:(CDVInvokedUrlCommand*)command; -- (void)startEvent:(CDVInvokedUrlCommand*)command; -- (void)cancelEvent:(CDVInvokedUrlCommand*)command; -- (void)endEvent:(CDVInvokedUrlCommand*)command; - -- (void)userData_setProperty:(CDVInvokedUrlCommand*)command; -- (void)userData_increment:(CDVInvokedUrlCommand*)command; -- (void)userData_incrementBy:(CDVInvokedUrlCommand*)command; -- (void)userData_multiply:(CDVInvokedUrlCommand*)command; -- (void)userData_saveMax:(CDVInvokedUrlCommand*)command; -- (void)userData_saveMin:(CDVInvokedUrlCommand*)command; -- (void)userData_setOnce:(CDVInvokedUrlCommand*)command; -- (void)userData_pushUniqueValue:(CDVInvokedUrlCommand*)command; -- (void)userData_pushValue:(CDVInvokedUrlCommand*)command; -- (void)userData_pullValue:(CDVInvokedUrlCommand*)command; -- (void)setOptionalParametersForInitialization:(CDVInvokedUrlCommand*)command; +- (void)userData_setProperty:(CDVInvokedUrlCommand *)command; +- (void)userData_increment:(CDVInvokedUrlCommand *)command; +- (void)userData_incrementBy:(CDVInvokedUrlCommand *)command; +- (void)userData_multiply:(CDVInvokedUrlCommand *)command; +- (void)userData_saveMax:(CDVInvokedUrlCommand *)command; +- (void)userData_saveMin:(CDVInvokedUrlCommand *)command; +- (void)userData_setOnce:(CDVInvokedUrlCommand *)command; +- (void)userData_pushUniqueValue:(CDVInvokedUrlCommand *)command; +- (void)userData_pushValue:(CDVInvokedUrlCommand *)command; +- (void)userData_pullValue:(CDVInvokedUrlCommand *)command; +- (void)setOptionalParametersForInitialization:(CDVInvokedUrlCommand *)command; // - (void)setRequiresConsent:(CDVInvokedUrlCommand*)command; // - (void)giveConsent:(CDVInvokedUrlCommand*)command; @@ -60,28 +59,28 @@ // - (void)giveAllConsent:(CDVInvokedUrlCommand*)command; // - (void)removeAllConsent:(CDVInvokedUrlCommand*)command; -- (void)setRemoteConfigAutomaticDownload:(CDVInvokedUrlCommand*)command; -- (void)remoteConfigUpdate:(CDVInvokedUrlCommand*)command; -- (void)updateRemoteConfigForKeysOnly:(CDVInvokedUrlCommand*)command; -- (void)updateRemoteConfigExceptKeys:(CDVInvokedUrlCommand*)command; -- (void)remoteConfigClearValues:(CDVInvokedUrlCommand*)command; -- (void)getRemoteConfigValueForKey:(CDVInvokedUrlCommand*)command; -- (void)askForFeedback:(CDVInvokedUrlCommand*)command; -- (void)setStarRatingDialogTexts:(CDVInvokedUrlCommand*)command; -- (void)askForStarRating:(CDVInvokedUrlCommand*)command; -- (void)getFeedbackWidgets:(CDVInvokedUrlCommand*)command; -- (void)presentFeedbackWidget:(CDVInvokedUrlCommand*)command; -- (void)replaceAllAppKeysInQueueWithCurrentAppKey:(CDVInvokedUrlCommand*)command; -- (void)removeDifferentAppKeysFromQueue:(CDVInvokedUrlCommand*)command; -- (void)enableAttribution:(CDVInvokedUrlCommand*)command; -- (void)recordAttributionID:(CDVInvokedUrlCommand*)command; +- (void)setRemoteConfigAutomaticDownload:(CDVInvokedUrlCommand *)command; +- (void)remoteConfigUpdate:(CDVInvokedUrlCommand *)command; +- (void)updateRemoteConfigForKeysOnly:(CDVInvokedUrlCommand *)command; +- (void)updateRemoteConfigExceptKeys:(CDVInvokedUrlCommand *)command; +- (void)remoteConfigClearValues:(CDVInvokedUrlCommand *)command; +- (void)getRemoteConfigValueForKey:(CDVInvokedUrlCommand *)command; +- (void)askForFeedback:(CDVInvokedUrlCommand *)command; +- (void)setStarRatingDialogTexts:(CDVInvokedUrlCommand *)command; +- (void)askForStarRating:(CDVInvokedUrlCommand *)command; +- (void)getFeedbackWidgets:(CDVInvokedUrlCommand *)command; +- (void)presentFeedbackWidget:(CDVInvokedUrlCommand *)command; +- (void)replaceAllAppKeysInQueueWithCurrentAppKey:(CDVInvokedUrlCommand *)command; +- (void)removeDifferentAppKeysFromQueue:(CDVInvokedUrlCommand *)command; +- (void)enableAttribution:(CDVInvokedUrlCommand *)command; +- (void)recordAttributionID:(CDVInvokedUrlCommand *)command; -- (void)startTrace:(CDVInvokedUrlCommand*)command; -- (void)cancelTrace:(CDVInvokedUrlCommand*)command; -- (void)clearAllTraces:(CDVInvokedUrlCommand*)command; -- (void)endTrace:(CDVInvokedUrlCommand*)command; -- (void)recordNetworkTrace:(CDVInvokedUrlCommand*)command; -- (void)enableApm:(CDVInvokedUrlCommand*)command; -- (void)appLoadingFinished:(CDVInvokedUrlCommand*)command; +- (void)startTrace:(CDVInvokedUrlCommand *)command; +- (void)cancelTrace:(CDVInvokedUrlCommand *)command; +- (void)clearAllTraces:(CDVInvokedUrlCommand *)command; +- (void)endTrace:(CDVInvokedUrlCommand *)command; +- (void)recordNetworkTrace:(CDVInvokedUrlCommand *)command; +- (void)enableApm:(CDVInvokedUrlCommand *)command; +- (void)appLoadingFinished:(CDVInvokedUrlCommand *)command; @end diff --git a/src/ios/CountlyNative.h b/src/ios/CountlyNative.h index daebb97..9ff1a91 100644 --- a/src/ios/CountlyNative.h +++ b/src/ios/CountlyNative.h @@ -1,22 +1,22 @@ - -#import "AppDelegate.h" -@import UserNotifications; - -extern NSString * _Nullable const pushPluginApplicationDidBecomeActiveNotification; - -@interface AppDelegate (notification) -- (void)application:(UIApplication *_Nullable)application didReceiveRemoteNotification:(NSDictionary *_Nullable)userInfo fetchCompletionHandler:( void (^_Nullable)(UIBackgroundFetchResult))completionHandler; -- (id _Nullable ) getCommandInstance:(NSString*_Nullable)className; -- (void)pushPluginOnApplicationDidBecomeActive:(UIApplication *_Nullable)application; - -@property (nonatomic, retain) NSDictionary * _Nullable launchNotification; -@property (nonatomic, retain) NSNumber * _Nullable coldstart; - -@end - -@interface CountlyNative: NSObject -typedef void (^Result)(id _Nullable result); -- (void) onCall:(NSString * _Nullable)method commandString:(NSArray * _Nullable)commandString callback:(Result _Nullable ) result; -+ (void)onNotification: (NSDictionary *) notificationMessage; // :(Boolean *)isInline :(Boolean *)coldstart -- (void)recordPushAction; -@end + +#import "AppDelegate.h" +@import UserNotifications; + +extern NSString *_Nullable const pushPluginApplicationDidBecomeActiveNotification; + +@interface AppDelegate (notification) +- (void)application:(UIApplication *_Nullable)application didReceiveRemoteNotification:(NSDictionary *_Nullable)userInfo fetchCompletionHandler:(void (^_Nullable)(UIBackgroundFetchResult))completionHandler; +- (id _Nullable)getCommandInstance:(NSString *_Nullable)className; +- (void)pushPluginOnApplicationDidBecomeActive:(UIApplication *_Nullable)application; + +@property(nonatomic, retain) NSDictionary *_Nullable launchNotification; +@property(nonatomic, retain) NSNumber *_Nullable coldstart; + +@end + +@interface CountlyNative : NSObject +typedef void (^Result)(id _Nullable result); +- (void)onCall:(NSString *_Nullable)method commandString:(NSArray *_Nullable)commandString callback:(Result _Nullable)result; ++ (void)onNotification:(NSDictionary *)notificationMessage; // :(Boolean *)isInline :(Boolean *)coldstart +- (void)recordPushAction; +@end