Skip to content

Commit

Permalink
Add method to report feedback directly
Browse files Browse the repository at this point in the history
  • Loading branch information
ar2rsawseen committed Mar 15, 2020
1 parent f82dbb6 commit f1f065a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 42 deletions.
52 changes: 30 additions & 22 deletions lib/countly-bulk-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,31 +396,39 @@ function CountlyBulkUser(conf){
};

/**
* Report rating user left on the app
* @param {number} rating - rating from 1 to 5
* @param {string} platform - on which platforms/os did user leave rating
* @param {number} app_version - for which app_version did user leave rating
* @param {number} timestamp - when user rated the app
* @returns {module:lib/countly-bulk-user} instance
* Provide information about user
* @param {Object} feedback - object with feedback properties
* @param {string} feedback.widget_id - id of the widget in the dashboard
* @param {string} feedback.platform - user's platform
* @param {string} feedback.app_version - app's app version
* @param {number} feedback.rating - user's rating
* @param {boolean=} feedback.contactMe - did user give consent to contact him
* @param {string=} feedback.email - user's email
* @param {string=} feedback.comment - user's comment
**/
this.report_rating = function(rating, platform, app_version, timestamp){
if(this.check_consent("star-rating")){
var event = {
"key": "[CLY]_star_rating",
"count": 1,
"segmentation": {
"rating": rating,
"app_version":app_version,
"platform":platform
}
};
var query = prepareQuery({events:[event]});
if(timestamp){
query.timestamp = timestamp;
this.report_feedback = function (feedback) {
if (this.check_consent("star-rating")) {
if (!feedback.widget_id) {
log("Feedback must contain widget_id property");
return;
}
if (!feedback.rating) {
log("Feedback must contain rating property");
return;
}
if (this.check_consent("events")) {
var props = ["widget_id", "contactMe", "platform", "app_version", "rating", "email", "comment"];
var event = {
key: "[CLY]_star_rating",
count: 1,
segmentation: {}
};
event.segmentation = getProperties(feedback, props);
log("Reporting feedback: ", event);
this.add_event(event);
}
conf.server.add_request(query);
return this;
}
return this;
};

/**
Expand Down
78 changes: 58 additions & 20 deletions lib/countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Countly.Bulk = Bulk;
/**
* Array with list of available features that you can require consent for
*/
Countly.features = ["sessions","events","views","crashes","attribution","users","location"];
Countly.features = ["sessions","events","views","crashes","attribution","users","location","star-rating"];

//create object to store consents
var consents = {};
Expand Down Expand Up @@ -556,25 +556,6 @@ Countly.Bulk = Bulk;
}
};

/**
* Report user conversion to the server (when user signup or made a purchase, or whatever your conversion is)
* @param {string} campaign_id - id of campaign, the last part of the countly campaign link
* @param {string=} campaign_user_id - id of user's clicked on campaign link, if you have one
**/
Countly.report_conversion = function(campaign_id, campaign_user_id){
if(Countly.check_consent("attribution")){
if(campaign_id && campaign_user_id){
toRequestQueue({campaign_id: campaign_id, campaign_user: campaign_user_id});
}
else if(campaign_id){
toRequestQueue({campaign_id: campaign_id});
}
else{
log("No campaign data found");
}
}
};

/**************************
* Modifying custom property values of user details
* Possible modification commands
Expand Down Expand Up @@ -717,6 +698,63 @@ Countly.Bulk = Bulk;
}
};

/**
* Report user conversion to the server (when user signup or made a purchase, or whatever your conversion is)
* @param {string} campaign_id - id of campaign, the last part of the countly campaign link
* @param {string=} campaign_user_id - id of user's clicked on campaign link, if you have one
**/
Countly.report_conversion = function(campaign_id, campaign_user_id){
if(Countly.check_consent("attribution")){
if(campaign_id && campaign_user_id){
toRequestQueue({campaign_id: campaign_id, campaign_user: campaign_user_id});
}
else if(campaign_id){
toRequestQueue({campaign_id: campaign_id});
}
else{
log("No campaign data found");
}
}
};

/**
* Provide information about user
* @param {Object} feedback - object with feedback properties
* @param {string} feedback.widget_id - id of the widget in the dashboard
* @param {boolean=} feedback.contactMe - did user give consent to contact him
* @param {string=} feedback.platform - user's platform (will be filled if not provided)
* @param {string=} feedback.app_version - app's app version (will be filled if not provided)
* @param {number} feedback.rating - user's rating
* @param {string=} feedback.email - user's email
* @param {string=} feedback.comment - user's comment
**/
Countly.report_feedback = function (feedback) {
if (Countly.check_consent("star-rating")) {
if (!feedback.widget_id) {
log("Feedback must contain widget_id property");
return;
}
if (!feedback.rating) {
log("Feedback must contain rating property");
return;
}
if (Countly.check_consent("events")) {
var props = ["widget_id", "contactMe", "platform", "app_version", "rating", "email", "comment"];
var event = {
key: "[CLY]_star_rating",
count: 1,
segmentation: {}
};
event.segmentation = getProperties(feedback, props);
if (!event.segmentation.app_version) {
event.segmentation.app_version = metrics._app_version || Countly.app_version;
}
log("Reporting feedback: ", event);
Countly.add_event(event);
}
}
};

/**
* Automatically track javascript errors that happen on the nodejs process
* @param {string=} segments - additional key value pairs you want to provide with error report, like versions of libraries used, etc.
Expand Down

0 comments on commit f1f065a

Please sign in to comment.