Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[908] nps and survey manual reporting #272

Merged
merged 10 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 22.06.1
- Added SDK calls to report Feedback widgets manually

## 22.06.0
- Updated BoomerangJS to the latest version (1.737.0)
- Implemented static code analysis recommendations from Codacy, Snyk and Deep Scan
Expand Down
257 changes: 257 additions & 0 deletions cypress/integration/manual_widget_reporting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
/* eslint-disable cypress/no-unnecessary-waiting */
/* eslint-disable require-jsdoc */
var Countly = require("../../lib/countly");
var hp = require("../support/helper");

const contactMe = true;
const platform = "platform";
const email = "email";
const app_version = "app_version";
const comment = "comment";
const CountlyWidgetData = { true: true };

function CountlyFeedbackWidgetMaker(a, b) {
return { _id: a, type: b };
}

function widgetResponseMakerNpsRating(a) {
return {
contactMe: contactMe, // boolean
rating: a, // number
email: email,
comment: comment // string
};
}
function widgetResponseMakerSurvey(a, b, c, d) {
return {
a: b,
c: d
};
}

function ratingMaker(a, b) {
return {
widget_id: a, // string
contactMe: contactMe, // boolean
platform: platform, // string
app_version: app_version, // string
rating: b, // number
comment: comment, // string
email: email // string
};
}
// num is 1 for ratings, 2 for nps, 3 for surveys
function common_rating_check(param, num) {
// eslint-disable-next-line no-nested-ternary
cy.expect(param[0].key).to.equal(num === 1 ? "[CLY]_star_rating" : num === 2 ? "[CLY]_nps" : "[CLY]_survey");
cy.expect(param[0].segmentation.app_version).to.equal(app_version);
cy.expect(param[0].segmentation.platform).to.equal(platform);
if (num !== 3) {
cy.expect(param[0].segmentation.comment).to.equal(comment);
if (num === 1) {
cy.expect(param[0].segmentation.contactMe).to.equal(contactMe);
cy.expect(param[0].segmentation.email).to.equal(email);
}
}
}

function initMain() {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://try.count.ly",
max_events: -1,
test_mode: true,
debug: true

});
}
// TODO: Add more tests
describe("Manual Rating Widget recording tests, old call ", () => {
it("Checks if a rating object is send correctly", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.recordRatingWidgetWithID(ratingMaker("123", 1));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(1);
cy.check_commons(eq[0], 1);
common_rating_check(eq, 1);
cy.expect(eq[0].segmentation.rating).to.equal(1);
cy.expect(eq[0].segmentation.widget_id).to.equal("123");
});
});
});
it("Checks if rating recording without id would be stopped", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.recordRatingWidgetWithID(ratingMaker(undefined, 1));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(0);
});
});
});
it("Checks if rating recording without rating would be stopped", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.recordRatingWidgetWithID(ratingMaker("123", undefined));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(0);
});
});
});
it("Checks if id and rating is enough", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.recordRatingWidgetWithID({ widget_id: "123", rating: 1 });
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(1);
cy.check_commons(eq[0], 1);
cy.expect(eq[0].segmentation.rating).to.equal(1);
cy.expect(eq[0].segmentation.widget_id).to.equal("123");
});
});
});
it("Check improper rating number in fixed", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.recordRatingWidgetWithID({ widget_id: "123", rating: 11 });
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(1);
cy.check_commons(eq[0], 1);
cy.expect(eq[0].segmentation.rating).to.equal(5);
cy.expect(eq[0].segmentation.widget_id).to.equal("123");
});
});
});
});
describe("Manual nps recording tests ", () => {
it("Checks if a nps is send correctly", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidgetMaker("123", "nps"), CountlyWidgetData, widgetResponseMakerNpsRating(2));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(1);
cy.check_commons(eq[0], 2);
cy.expect(eq[0].segmentation.rating).to.equal(2);
cy.expect(eq[0].segmentation.widget_id).to.equal("123");
});
});
});
it("Checks if nps would be omitted with no id", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidgetMaker(undefined, "nps"), CountlyWidgetData, widgetResponseMakerNpsRating(2));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(0);
});
});
});
it("Checks if rating would be curbed", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidgetMaker("123", "nps"), CountlyWidgetData, widgetResponseMakerNpsRating(11));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(1);
cy.check_commons(eq[0], 2);
cy.expect(eq[0].segmentation.rating).to.equal(10);
cy.expect(eq[0].segmentation.widget_id).to.equal("123");
});
});
});
});
describe("Manual survey recording tests ", () => {
it("Checks if a survey is send correctly", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidgetMaker("123", "survey"), CountlyWidgetData, widgetResponseMakerSurvey("a", "b", "c", 7));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(1);
cy.check_commons(eq[0], 3);
cy.expect(eq[0].segmentation.widget_id).to.equal("123");
cy.expect(eq[0].segmentation.a).to.equal("b");
cy.expect(eq[0].segmentation.c).to.equal(7);
});
});
});
it("Checks if null response would have closed flag", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidgetMaker("123", "survey"), CountlyWidgetData, null);
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(1);
cy.check_commons(eq[0], 3);
cy.expect(eq[0].segmentation.widget_id).to.equal("123");
cy.expect(eq[0].segmentation.closed).to.equal(1);
});
});
});
it("Checks if no id would be rejected", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidgetMaker(undefined, "survey"), CountlyWidgetData, widgetResponseMakerSurvey("a", "b", "c", 7));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(0);
});
});
});
});
describe("Manual Rating widget recording tests, new call ", () => {
it("Checks if a rating is send correctly", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidgetMaker("123", "rating"), CountlyWidgetData, widgetResponseMakerNpsRating(3));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(1);
cy.check_commons(eq[0], 1);
cy.expect(eq[0].segmentation.widget_id).to.equal("123");
cy.expect(eq[0].segmentation.rating).to.equal(3);
});
});
});
it("Checks if null response would have closed flag", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidgetMaker("123", "rating"), CountlyWidgetData, null);
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(1);
cy.expect(eq[0].segmentation.widget_id).to.equal("123");
cy.expect(eq[0].segmentation.closed).to.equal(1);
});
});
});
it("Checks if no id would be rejected", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidgetMaker(undefined, "rating"), CountlyWidgetData, widgetResponseMakerNpsRating(3));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(0);
});
});
});
it("Checks if rating would be curbed", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidgetMaker("123", "rating"), CountlyWidgetData, widgetResponseMakerNpsRating(6));
cy.fetch_local_event_queue().then((eq) => {
cy.log(eq);
expect(eq.length).to.equal(1);
cy.check_commons(eq[0], 1);
cy.expect(eq[0].segmentation.rating).to.equal(5);
cy.expect(eq[0].segmentation.widget_id).to.equal("123");
});
});
});
});
69 changes: 60 additions & 9 deletions examples/examples_feedback_widgets.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,81 @@

//initializing Countly with params and passing require_consent config as true as feedback widget depends on consent
Countly.init({
app_key: 'YOUR_APP_ID', //your app key
app_key: 'YOUR_APP_KEY', //your app key
url: 'https://try.count.ly', //your server goes here
debug: true
});

function enable() {
//Fetch user's NPS and Survey feedbacks from the server
function fetchAndDisplayWidget() {
// Fetch user's NPS and Survey feedbacks from the server
Countly.get_available_feedback_widgets(feedbackWidgetsCallback);
}

//Surveys feedback callback function
// Surveys feedback callback function
function feedbackWidgetsCallback(countlyPresentableFeedback, err) {
if (err) {
console.log(err);
return;
}
//The available feedback types are nps and survey, decide which one to show
// Decide which which widget to show. Here first one is selected:
var countlyFeedbackWidget = countlyPresentableFeedback[0];

//Define the element ID and the class name, optional
// Define the element ID and the class name (optional)
var selectorId = "";
var selectorClass = "";

//Display the feedback widget to the end user
// Display the feedback widget to the end user
Countly.present_feedback_widget(countlyFeedbackWidget, selectorId, selectorClass);
}


var CountlyFeedbackWidget;
var CountlyWidgetData;
// an example of getting the widget list, using it to get widget data and then recording data for it manually. widgetType can be 'nps', 'survey' or 'rating'
function getFeedbackWidgetListAndDoThings(widgetType) {
// get the widget list
Countly.get_available_feedback_widgets(
// callback function, 1st param is the feedback widget list
function (feedbackList, err) {
if (err) {
console.log(err);
return;
}
var i = feedbackList.length - 1;
while (i--) {
if (feedbackList[i].type === widgetType) {
CountlyFeedbackWidget = feedbackList[i];
break;
}
}
if (CountlyFeedbackWidget) {
// Get data with the widget object
Countly.getFeedbackWidgetData(CountlyFeedbackWidget,
// callback function, 1st param is the feedback widget data
function (feedbackData, err) {
if (err) {
console.log(err);
return;
}
CountlyWidgetData = feedbackData;
// record data according to the widget type
if (CountlyWidgetData.type === 'nps') {
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidget, CountlyWidgetData, { rating: 3, comment: "comment" });
} else if (CountlyWidgetData.type === 'survey') {
var widgetResponse = {};
// form the key/value pairs according to data
widgetResponse["answ-" + CountlyWidgetData.questions[0].id] = CountlyWidgetData.questions[0].type === "rating" ? 3 : "answer";
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidget, CountlyWidgetData, widgetResponse);
} else if (CountlyWidgetData.type === 'rating') {
Countly.reportFeedbackWidgetManually(CountlyFeedbackWidget, CountlyWidgetData, { rating: 3, comment: "comment", email: "email", contactMe: true });
}
}

);
} else {
console.error("The widget type you are looking for does not exist")
}
})
}
</script>
</head>

Expand All @@ -49,7 +97,10 @@ <h1>Feedback Widgets</h1>
<center>
<img src="./images/team_countly.jpg" id="wallpaper" />
<p><a href='http://count.ly/'>Count.ly</a></p>
<p><button onclick="enable()">Enable Feedback Widget</button></p>
<p><button onclick="fetchAndDisplayWidget()">Enable Feedback Widget</button></p>
<p><button onclick="getFeedbackWidgetListAndDoThings('nps')">Manually Record NPS Data</button></p>
<p><button onclick="getFeedbackWidgetListAndDoThings('survey')">Manually Record Survey Data</button></p>
<p><button onclick="getFeedbackWidgetListAndDoThings('rating')">Manually Record Rating Data</button></p>
</center>
</body>

Expand Down
Loading