Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
[sdk-187] Added feedback widget: (#78)
Browse files Browse the repository at this point in the history
* 20.11.0 Features Added:
- Added Surveys and NPS feedback widgets
- Added replaceAllAppKeysInQueueWithCurrentAppKey method to replace all app keys in queue with the current app key
- Added removeDifferentAppKeysFromQueue method to remove all different app keys from the queue
- Added setStarRatingDialogTexts method to set text's for different fields of star rating dialog
- Added recordAttributionID method for iOS.

* getDeviceIdAuthor implemented for iOS.

* Android sdk version updated

* Countly pod updated to 20.11.1 for iOS and some small fixes.

* Googleservices enables for plugin

* Feedback widget changes implemented:
— getFeebackwidgets return list of object.
— presentFeedbackWidget accept widget object as a parameter.
  • Loading branch information
ijunaid authored Dec 15, 2020
1 parent f194037 commit 90e7d35
Show file tree
Hide file tree
Showing 10 changed files with 409 additions and 22 deletions.
105 changes: 101 additions & 4 deletions Countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Countly = {};
Countly.serverUrl = "";
Countly.appKey = "";
Countly.ready = false;
Countly.version = "20.04";
Countly.version = "20.11.0";
Countly.isDebug = false;
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
if (/android/i.test(userAgent)) {
Expand Down Expand Up @@ -496,6 +496,20 @@ Countly.rating = {
// cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","sendRating",[rating.toString()]);
// }

/**
* Set's the text's for the different fields in the star rating dialog. Set value null if for some field you want to keep the old value
*
* @param {String} starRatingTextTitle - dialog's title text (Only for Android)
* @param {String} starRatingTextMessage - dialog's message text
* @param {String} starRatingTextDismiss - dialog's dismiss buttons text (Only for Android)
*/
Countly.setStarRatingDialogTexts = function(starRatingTextTitle, starRatingTextMessage, starRatingTextDismiss){
var args = [];
args.push(starRatingTextTitle);
args.push(starRatingTextMessage);
args.push(starRatingTextDismiss);
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","setStarRatingDialogTexts",args);
}
// ui related methods
// opens the modal
Countly.askForStarRating = function(callback){
Expand All @@ -505,7 +519,65 @@ Countly.askForStarRating = function(callback){
Countly.askForFeedback = function(widgetId, buttonText){
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","askForFeedback",[widgetId, buttonText || ""]);
}
// FEEDBACK-WORK

/**
* 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",[]);
});
}

/**
* Present a chosen feedback widget
*
* @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) {
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){
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){
console.error("[CountlyCordova] presentFeedbackWidget, feedbackWidget type should not be null or empty");
}
return "FeedbackWidget type should not be null or empty";
}
var widgetId = feedbackWidget.id;
var widgetType = feedbackWidget.type;
var widgetName = feedbackWidget.name || "";
buttonText = buttonText || "";
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","presentFeedbackWidget",[widgetId, widgetType, widgetName, buttonText]);
}

/**
* Replaces all requests with a different app key with the current app key.
* 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",[]);
}

/**
* Removes all requests with a different app key in request queue.
* 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",[]);
}

// Push Notification
Countly.sendPushToken = function(options){
Expand All @@ -527,10 +599,35 @@ Countly.setHttpPostForced = function(boolean){
/**
*
* Enable campaign attribution reporting to Countly.
* For iOS use "recordAttributionID" instead of "enableAttribution"
* Should be call before Countly init
*/
Countly.enableAttribution = function() {
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","enableAttribution",[]);
Countly.enableAttribution = function(attributionID = "") {
if (Countly.isiOS) {
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";
}
Countly.recordAttributionID(attributionID);
}
else {
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","enableAttribution",[]);
}
}

/**
*
* set attribution Id for campaign attribution reporting.
* Currently implemented for iOS only
* For Android just call the enableAttribution to enable campaign attribution.
*/
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);
}

Countly.startTrace = function(traceKey){
Expand Down
31 changes: 29 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ <h1 class="ui center aligned header">Countly Cordova Demo App</h1>
<!-- <button onclick="app.sendRating()" class="fluid ui button">Send 5 star rating!!</button> -->
<button onclick="app.askForStarRating()" class="fluid ui button orange">Open rating modal</button>
<button onclick="app.askForFeedback()" class="fluid ui button orange">Open feedback modal</button>
<button onclick="app.showSurvey()" class="fluid ui button orange">Show Survey</button>
<button onclick="app.showNPS()" class="fluid ui button orange">Show NPS</button>
<div class="ui horizontal divider">Rating Methods End</div>

<div class="ui horizontal divider">Performance Methods Start</div>
Expand Down Expand Up @@ -168,7 +170,7 @@ <h1 class="ui center aligned header">Countly Cordova Demo App</h1>
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"]); // give conset for specific features before init.
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.


Expand All @@ -183,13 +185,14 @@ <h1 class="ui center aligned header">Countly Cordova Demo App</h1>
}, 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.setStarRatingDialogTexts("Title", "Message", "Dismiss");
/**
* Push notifications settings
* Should be call after init
*/
Countly.pushTokenType(Countly.messagingMode.TEST); // Set messaging mode for push notifications
Countly.onNotification(function(theNotification){
console.log("[CountlyCordova] onNotification : " + JSON.stringify(theNotification));
}); // Set callback to receive push notifications
Expand Down Expand Up @@ -517,6 +520,30 @@ <h1 class="ui center aligned header">Countly Cordova Demo App</h1>
});
}

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");
Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'countly:countly-sdk-js',
version: '20.4.0', // Meteor doesn't go with 18.08.1
version: '20.11.0',
summary: 'Countly is an innovative, real-time, open source mobile analytics and push notifications platform. It collects data from mobile devices, and visualizes this information to analyze mobile application usage and end-user behavior. There are two parts of Countly: the server that collects and analyzes data, and mobile SDK that sends this data. Both parts are open source with different licensing terms.',
git: 'https://github.com/Countly/countly-sdk-cordova.git',
documentation: 'README.md'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "countly-sdk-cordova",
"description": "Countly is an innovative, real-time, open source mobile analytics and push notifications platform. It collects data from mobile devices, and visualizes this information to analyze mobile application usage and end-user behavior. There are two parts of Countly: the server that collects and analyzes data, and mobile SDK that sends this data. Both parts are open source with different licensing terms.",
"version": "20.4.0",
"version": "20.11.0",
"homepage": "https://github.com/Countly/countly-sdk-cordova#readme",
"repository": {
"type": "git",
Expand Down
11 changes: 7 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="countly-sdk-cordova" version="20.4.0">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="countly-sdk-cordova" version="20.11.0">

<name>Countly</name>

Expand Down Expand Up @@ -49,7 +49,7 @@
<source url="https://github.com/CocoaPods/Specs.git"/>
</config>
<pods use-frameworks="true">
<pod name="Countly" version="20.04.3"/>
<pod name="CountlyPod" version="20.11.1"/>
</pods>
</podspec>
<!-- Push notification -->
Expand All @@ -75,6 +75,8 @@
<feature name="CountlyCordova">
<param name="android-package" value="ly.count.android.sdk.CountlyCordova" />
</feature>
<preference name="GradlePluginGoogleServicesEnabled" value="true" />
<preference name="GradlePluginGoogleServicesVersion" value="4.2.0" />
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest">
Expand All @@ -92,7 +94,7 @@

<source-file src="src/android/CountlyCordova.java" target-dir="src/ly/count/android/sdk"/>
<source-file src="src/android/CountlyNative.java" target-dir="src/ly/count/android/sdk"/>
<framework src="ly.count.android:sdk:20.04.5" />
<framework src="ly.count.android:sdk:20.11.2" />

<!-- Push notification -->
<config-file target="AndroidManifest.xml" parent="/manifest/application">
Expand All @@ -108,7 +110,8 @@
<permission android:name="${applicationId}.CountlyPush.BROADCAST_PERMISSION" android:protectionLevel="signature" />
</config-file>
<dependency id="cordova-support-google-services" version="~1.4.0"/>
<framework src="com.google.firebase:firebase-messaging:20.1.7" />
<!-- if any version higher than 18.0.0 is used then it forces AndroidX -->
<framework src="com.google.firebase:firebase-messaging:18.0.0" />
<source-file src="src/android/CountlyMessagingService.java" target-dir="src/ly/count/android/sdk"/>
</platform>

Expand Down
36 changes: 36 additions & 0 deletions src/android/CountlyCordova.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.os.Bundle;
Expand Down Expand Up @@ -215,6 +216,9 @@ else if("remoteConfigClearValues".equals(action)){
else if("getRemoteConfigValueForKey".equals(action)){
callbackContext.success(countlyNative.getRemoteConfigValueForKey(args));
}
else if("setStarRatingDialogTexts".equals(action)){
callbackContext.success(countlyNative.setStarRatingDialogTexts(args));
}
else if("askForStarRating".equals(action)){
callbackContext.success(countlyNative.askForStarRating(args));
}
Expand All @@ -226,6 +230,38 @@ public void callback(String result) {
}
});
}
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.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);

}
@Override
public void error(String error) {
callbackContext.error(error);
}
});
}
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)){
countlyNative.replaceAllAppKeysInQueueWithCurrentAppKey();
callbackContext.success("replaceAllAppKeysInQueueWithCurrentAppKey : Success");
}
else if("removeDifferentAppKeysFromQueue".equals(action)){
countlyNative.removeDifferentAppKeysFromQueue();
callbackContext.success("removeDifferentAppKeysFromQueue : Success");
}
else if("sendPushToken".equals(action)){
callbackContext.success(countlyNative.sendPushToken(args));
}
Expand Down
Loading

0 comments on commit 90e7d35

Please sign in to comment.