From b33e0ca596ec38bd3dfddec56450c09cda7b50b1 Mon Sep 17 00:00:00 2001 From: Peter Obiechina Date: Tue, 3 Oct 2023 16:26:21 +0100 Subject: [PATCH 1/2] creating example for reporting feedback widgets manually. --- CountlyRNExample/App.tsx | 136 ++++++++++++++++++++++++++++++++++ CountlyRNExample/package.json | 2 +- 2 files changed, 137 insertions(+), 1 deletion(-) diff --git a/CountlyRNExample/App.tsx b/CountlyRNExample/App.tsx index 0cb18e7..b813dce 100644 --- a/CountlyRNExample/App.tsx +++ b/CountlyRNExample/App.tsx @@ -653,6 +653,139 @@ class Example extends Component { Countly.recordIndirectAttribution(attributionValues); }; + reportSurveyManually = () => { + Countly.getFeedbackWidgets((retrivedWidgets, error) => { + if (error != null) { + console.log('reportSurveyManually Error : ' + error); + } else { + console.log('reportSurveyManually Success : ' + retrivedWidgets.length); + const surveyWidget = retrivedWidgets.find((x) => x.type === 'survey'); + if (surveyWidget) { + this.reportSurvey(surveyWidget); + } + } + }); + }; + + reportSurvey = (chosenWidget) => { + Countly.getFeedbackWidgetData(chosenWidget, (retrievedWidgetData, error) => { + if (error != null) { + console.log('reportSurvey Error : ' + error); + } else { + const segments = {}; + if (retrievedWidgetData && retrievedWidgetData.size !== 0) { + const questions = retrievedWidgetData['questions']; + + if (questions != null) { + console.log('questions', questions); + //iterate over all questions and set random answers + for (let a = 0; a < questions.length; a++) { + const question = questions[a]; + const wType = question['type']; + const questionId = question['id']; + const answerKey = 'answ-' + questionId; + switch (wType) { + //multiple answer question + case 'multi': + const options = question['choices']; + let str = ''; + for (let b = 0; b < options.length; b++) { + if (b % 2 == 0) { + if (b != 0) { + str += ','; + } + str += options[b]['key']; + } + } + segments[answerKey] = str; + break; + case 'radio': + //dropdown value selector + case 'dropdown': + const choices = question['choices']; + const pick = this.getRandomInt(choices.length); + segments[answerKey] = choices[pick]['key']; + break; + //text input field + case 'text': + segments[answerKey] = 'Some random text ' + this.getRandomInt(999999999); + break; + //rating picker + case 'rating': + segments[answerKey] = this.getRandomInt(10); + break; + } + } + } + } + console.log('reportFeedbackWidgetManually Success : ', retrievedWidgetData, segments); + Countly.reportFeedbackWidgetManually(chosenWidget, retrievedWidgetData ?? {}, segments); + } + }).catch((e) => { + console.log('catch', e); + }); + }; + + reportNPSManually = () => { + Countly.getFeedbackWidgets((retrivedWidgets, error) => { + if (error != null) { + console.log('reportNPSManually Error : ' + error); + } else { + console.log('reportNPSManually Success : ' + retrivedWidgets.length); + const npsWidget = retrivedWidgets.find((x) => x.type === 'nps'); + if (npsWidget) { + this.reportNPS(npsWidget); + } + } + }); + }; + + reportNPS = (chosenWidget) => { + Countly.getFeedbackWidgetData(chosenWidget, (retrievedWidgetData, error) => { + if (error != null) { + console.log('reportSurvey Error : ' + error); + } else { + const segments = {'rating': 8}; + console.log('reportSurvey Success : ', retrievedWidgetData, segments); + Countly.reportFeedbackWidgetManually(chosenWidget, retrievedWidgetData, segments); + } + }).catch((e) => { + console.log('catch', e); + }); + }; + + reportRatingManually = () => { + Countly.getFeedbackWidgets((retrivedWidgets, error) => { + if (error != null) { + console.log('reportRatingManually Error : ' + error); + } else { + console.log('reportRatingManually Success : ' + retrivedWidgets.length); + const npsWidget = retrivedWidgets.find((x) => x.type === 'rating'); + if (npsWidget) { + this.reportRating(npsWidget); + } + } + }); + }; + + reportRating = (chosenWidget) => { + Countly.getFeedbackWidgetData(chosenWidget, (retrievedWidgetData, error) => { + if (error != null) { + console.log('reportRating Error : ' + error); + } else { + const segments = {'rating': 7, 'comment': 'Filled out comment' + this.getRandomInt(999999), 'email': 'test' + this.getRandomInt(999999) + '@yahoo.com'}; + console.log('reportRating Success : ', retrievedWidgetData, segments); + Countly.reportFeedbackWidgetManually(chosenWidget, retrievedWidgetData, segments); + } + }).catch((e) => { + console.log('catch', e); + }); + }; + + getRandomInt = (max) => { + return Math.floor(Math.random() * max); + }; + test = () => { this.onInit(); this.onStart(); @@ -759,6 +892,9 @@ class Example extends Component { + + + diff --git a/CountlyRNExample/package.json b/CountlyRNExample/package.json index 39e82e3..90233c9 100644 --- a/CountlyRNExample/package.json +++ b/CountlyRNExample/package.json @@ -10,7 +10,7 @@ "test": "jest" }, "dependencies": { - "countly-sdk-react-native-bridge": "23.6.0", + "countly-sdk-react-native-bridge": "23.6.1", "react": "18.2.0", "react-native": "0.71.0" }, From 6f75138e7753f920e5b6163d84b2dc7344ca4a29 Mon Sep 17 00:00:00 2001 From: Peter Obiechina Date: Thu, 5 Oct 2023 12:10:55 +0100 Subject: [PATCH 2/2] Example updated for the feedback module --- CountlyRNExample/App.tsx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/CountlyRNExample/App.tsx b/CountlyRNExample/App.tsx index b813dce..b677f60 100644 --- a/CountlyRNExample/App.tsx +++ b/CountlyRNExample/App.tsx @@ -654,7 +654,7 @@ class Example extends Component { }; reportSurveyManually = () => { - Countly.getFeedbackWidgets((retrivedWidgets, error) => { + Countly.feedback.getAvailableFeedbackWidgets((retrivedWidgets, error) => { if (error != null) { console.log('reportSurveyManually Error : ' + error); } else { @@ -668,7 +668,7 @@ class Example extends Component { }; reportSurvey = (chosenWidget) => { - Countly.getFeedbackWidgetData(chosenWidget, (retrievedWidgetData, error) => { + Countly.feedback.getFeedbackWidgetData(chosenWidget, (retrievedWidgetData, error) => { if (error != null) { console.log('reportSurvey Error : ' + error); } else { @@ -719,7 +719,7 @@ class Example extends Component { } } console.log('reportFeedbackWidgetManually Success : ', retrievedWidgetData, segments); - Countly.reportFeedbackWidgetManually(chosenWidget, retrievedWidgetData ?? {}, segments); + Countly.feedback.reportFeedbackWidgetManually(chosenWidget, retrievedWidgetData ?? {}, segments); } }).catch((e) => { console.log('catch', e); @@ -727,7 +727,7 @@ class Example extends Component { }; reportNPSManually = () => { - Countly.getFeedbackWidgets((retrivedWidgets, error) => { + Countly.feedback.getAvailableFeedbackWidgets((retrivedWidgets, error) => { if (error != null) { console.log('reportNPSManually Error : ' + error); } else { @@ -741,13 +741,13 @@ class Example extends Component { }; reportNPS = (chosenWidget) => { - Countly.getFeedbackWidgetData(chosenWidget, (retrievedWidgetData, error) => { + Countly.feedback.getFeedbackWidgetData(chosenWidget, (retrievedWidgetData, error) => { if (error != null) { console.log('reportSurvey Error : ' + error); } else { - const segments = {'rating': 8}; + const segments = {'rating': this.getRandomInt(10)}; console.log('reportSurvey Success : ', retrievedWidgetData, segments); - Countly.reportFeedbackWidgetManually(chosenWidget, retrievedWidgetData, segments); + Countly.feedback.reportFeedbackWidgetManually(chosenWidget, retrievedWidgetData, segments); } }).catch((e) => { console.log('catch', e); @@ -755,7 +755,7 @@ class Example extends Component { }; reportRatingManually = () => { - Countly.getFeedbackWidgets((retrivedWidgets, error) => { + Countly.feedback.getAvailableFeedbackWidgets((retrivedWidgets, error) => { if (error != null) { console.log('reportRatingManually Error : ' + error); } else { @@ -769,13 +769,13 @@ class Example extends Component { }; reportRating = (chosenWidget) => { - Countly.getFeedbackWidgetData(chosenWidget, (retrievedWidgetData, error) => { + Countly.feedback.getFeedbackWidgetData(chosenWidget, (retrievedWidgetData, error) => { if (error != null) { console.log('reportRating Error : ' + error); } else { - const segments = {'rating': 7, 'comment': 'Filled out comment' + this.getRandomInt(999999), 'email': 'test' + this.getRandomInt(999999) + '@yahoo.com'}; + const segments = {'rating': this.getRandomInt(5), 'comment': 'Filled out comment' + this.getRandomInt(999999), 'email': 'test' + this.getRandomInt(999999) + '@yahoo.com'}; console.log('reportRating Success : ', retrievedWidgetData, segments); - Countly.reportFeedbackWidgetManually(chosenWidget, retrievedWidgetData, segments); + Countly.feedback.reportFeedbackWidgetManually(chosenWidget, retrievedWidgetData, segments); } }).catch((e) => { console.log('catch', e);