2525 // Displaying feedback widgets
2626 //=================================================
2727 Countly . feedback . showNPS ( ) ;
28-
28+
2929 // OR with a specific ID, name or tag
3030 // const id = 'ID_from_server';
3131 // Countly.feedback.showNPS(id);
32-
32+
3333 // Other feedback widgets
3434 // Countly.feedback.showSurvey();
3535 // Countly.feedback.showRating();
3939 // ADVANCED: Fetching and displaying feedback widgets
4040 //=================================================
4141 function fetchAndDisplayWidget ( ) {
42- // Fetch user's feedbacks widgets from the server (must have been created at server first)
4342 Countly . get_available_feedback_widgets ( feedbackWidgetsCallback ) ;
4443 }
4544
5150 }
5251
5352 // Decide which which widget to show. Here the first rating widget is selected.
54- const widgetType = "rating " ;
53+ const widgetType = "survey " ;
5554 const countlyFeedbackWidget = countlyPresentableFeedback . find ( widget => widget . type === widgetType ) ;
5655 if ( ! countlyFeedbackWidget ) {
5756 console . error ( `[Countly] No ${ widgetType } widget found` ) ;
8988 console . error ( `[Countly] No ${ widgetType } widget found` ) ;
9089 return ;
9190 }
91+ console . log ( `[Countly] Found ${ widgetType } widget` ) ;
9292
9393 // Get data with the widget object
9494 Countly . getFeedbackWidgetData ( countlyFeedbackWidget ,
100100 }
101101
102102 const CountlyWidgetData = feedbackData ;
103+ console . log ( `[Countly] Found ${ widgetType } widget data` , CountlyWidgetData ) ;
103104 // record data according to the widget type
104105 if ( CountlyWidgetData . type === 'nps' ) {
105- Countly . reportFeedbackWidgetManually ( countlyFeedbackWidget , CountlyWidgetData , { rating : 3 , comment : "comment" } ) ;
106+ console . log ( `[Countly] Recording NPS data manually` ) ;
107+ Countly . reportFeedbackWidgetManually ( countlyFeedbackWidget , CountlyWidgetData , { rating : 5 , comment : "comment" } ) ;
106108 } else if ( CountlyWidgetData . type === 'survey' ) {
109+ console . log ( `[Countly] Recording Survey data manually` ) ;
107110 var widgetResponse = { } ;
108111 // form the key/value pairs according to data
109- widgetResponse [ "answ-" + CountlyWidgetData . questions [ 0 ] . id ] = CountlyWidgetData . questions [ 0 ] . type === "rating" ? 3 : "answer" ;
112+ widgetResponse [ "answ-" + CountlyWidgetData . questions [ 0 ] . id ] = CountlyWidgetData . questions [ 0 ] . type === "rating" ? 5 : "answer" ;
110113 Countly . reportFeedbackWidgetManually ( countlyFeedbackWidget , CountlyWidgetData , widgetResponse ) ;
111114 } else if ( CountlyWidgetData . type === 'rating' ) {
112- Countly . reportFeedbackWidgetManually ( countlyFeedbackWidget , CountlyWidgetData , { rating : 3 , comment : "comment" , email : "email" , contactMe : true } ) ;
115+ console . log ( `[Countly] Recording Rating data manually` ) ;
116+ Countly . reportFeedbackWidgetManually ( countlyFeedbackWidget , CountlyWidgetData , { rating : 5 , comment : "comment" , email : "email" , contactMe : true } ) ;
113117 }
114118 }
115119
116120 ) ;
117121 } )
118122 }
123+
124+ document . querySelector ( "#one" ) . addEventListener ( "click" , function ( ) {
125+ fetchAndDisplayWidget ( ) ;
126+ } ) ;
127+ document . querySelector ( "#two" ) . addEventListener ( "click" , function ( ) {
128+ getFeedbackWidgetListAndDoThings ( 'nps' ) ;
129+ } ) ;
130+ document . querySelector ( "#three" ) . addEventListener ( "click" , function ( ) {
131+ getFeedbackWidgetListAndDoThings ( 'survey' ) ;
132+ } ) ;
133+ document . querySelector ( "#four" ) . addEventListener ( "click" , function ( ) {
134+ getFeedbackWidgetListAndDoThings ( 'rating' ) ;
135+ } ) ;
136+
119137 </ script >
120138</ head >
121139
@@ -129,10 +147,10 @@ <h1>Feedback Widgets</h1>
129147 < center >
130148 < img src ="./images/team_countly.jpg " id ="wallpaper " />
131149 < p > < a href ='https://countly.com/ '> Countly</ a > </ p >
132- < p > < button onclick =" fetchAndDisplayWidget() "> Enable Feedback Widget</ button > </ p >
133- < p > < button onclick =" getFeedbackWidgetListAndDoThings('nps') "> Manually Record NPS Data</ button > </ p >
134- < p > < button onclick =" getFeedbackWidgetListAndDoThings('survey') "> Manually Record Survey Data</ button > </ p >
135- < p > < button onclick =" getFeedbackWidgetListAndDoThings('rating') "> Manually Record Rating Data</ button > </ p >
150+ < p > < button id =" one "> Enable Feedback Widget</ button > </ p >
151+ < p > < button id =" two "> Manually Record NPS Data</ button > </ p >
152+ < p > < button id =" three "> Manually Record Survey Data</ button > </ p >
153+ < p > < button id =" four "> Manually Record Rating Data</ button > </ p >
136154 </ center >
137155</ body >
138156
0 commit comments