diff --git a/lib/countly-bulk-user.js b/lib/countly-bulk-user.js index 1298348..6dc6f9d 100644 --- a/lib/countly-bulk-user.js +++ b/lib/countly-bulk-user.js @@ -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; }; /** diff --git a/lib/countly.js b/lib/countly.js index fbdd998..becacdd 100644 --- a/lib/countly.js +++ b/lib/countly.js @@ -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 = {}; @@ -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 @@ -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.