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

Added a method for feedback widget segmentation #438

Merged
merged 13 commits into from
Nov 9, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## X.X.X
- Mitigated an issue where numerical device IDs were parsed at the initialization

- You can now add segmentation while presenting a widget

## 23.6.0
- Added a new flag, 'loadAPMScriptsAsync', which can load the APM related scripts automatically for Async implementations
- Adding SDK health check requests after init
Expand Down
8 changes: 5 additions & 3 deletions examples/examples_feedback_widgets.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

// Decide which which widget to show. Here the first rating widget is selected.
var i = countlyPresentableFeedback.length - 1;
var i = countlyPresentableFeedback.length;
var countlyFeedbackWidget = countlyPresentableFeedback[0];
while (i--) {
// You can change 'rating' to 'nps' or 'survey'. Or you can create your own logic here.
Expand All @@ -44,11 +44,13 @@
var selectorId = "";
var selectorClass = "";

// Define the segmentation (optional)
const segmentation = { page: "home_page" };

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


//=================================================
// Fetching and reporting feedback widgets manually
//=================================================
Expand Down
18 changes: 16 additions & 2 deletions lib/countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -3038,9 +3038,12 @@
* @param {Object} presentableFeedback - Current presentable feedback
* @param {String} id - DOM id to append the feedback widget
* @param {String} className - Class name to append the feedback widget
* @param {Object} feedbackWidgetSegmentation - Segmentation object to be passed to the feedback widget
* */
this.present_feedback_widget = function(presentableFeedback, id, className) {
log(logLevelEnums.INFO, "[present_feedback_widget] Presenting the feedback widget by appending to the element with ID: [ " + id + " ] and className: [ " + className + " ]");
this.present_feedback_widget = function(presentableFeedback, id, className, feedbackWidgetSegmentation) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case "id" and "class name" are not used, what value should be provided. should be mentioned in the function doc

// TODO: feedbackWidgetSegmentation implementation only assumes we want to send segmentation data. Change it if we add more data to the custom object.
log(logLevelEnums.INFO, "present_feedback_widget, Presenting the feedback widget by appending to the element with ID: [ " + id + " ] and className: [ " + className + " ]");

if (!this.check_consent(featureEnums.FEEDBACK)) {
return;
}
Expand All @@ -3053,6 +3056,12 @@
return;
}

log(logLevelEnums.INFO, "present_feedback_widget, Adding segmentation to feedback widgets:[" + JSON.stringify(feedbackWidgetSegmentation) + "]");
if (!feedbackWidgetSegmentation || typeof feedbackWidgetSegmentation !== "object" || Object.keys(feedbackWidgetSegmentation).length === 0) {
log(logLevelEnums.DEBUG, "present_feedback_widget, Segmentation is not an object or empty");
feedbackWidgetSegmentation = null;
}

try {
var url = this.url;

Expand Down Expand Up @@ -3097,6 +3106,11 @@
url += "&platform=" + this.platform;
url += "&app_version=" + this.app_version;
url += "&sdk_version=" + SDK_VERSION;
if (feedbackWidgetSegmentation) {
var customObjectToSendWithTheWidget = {};
customObjectToSendWithTheWidget.sg = feedbackWidgetSegmentation;
url += "&custom=" + JSON.stringify(customObjectToSendWithTheWidget);
}
// Origin is passed to the popup so that it passes it back in the postMessage event
// Only web SDK passes origin and web
url += "&origin=" + passedOrigin;
Expand Down
Loading