Custom Metrics is about providing configurable metrics to view the analytics. Custom metrics can be a simple Top box score of a single select question or can be a combination of scores of more than 2 questions. Example: You can multiply the responses of two questions which are of type multiselect or single select, save it and perform any kind of analysis later on.
In order to enable the Custom Metrics functionality, we need to perform some prerequisites:
The rebuild feature helps in recalculating custom metric values for the responses present in the survey. Users can select the date range for which they want to recalculate the custom metric scores. This feature can be helpful where responses are collected in the past and the user wants to create custom metric scores for such responses.
In the “Custom Metrics” window under the “Analytics” section, all the custom metrics present in the workspace will be shown. When hovered over the custom metric action item will be shown as Edit, Rebuild Metric, and Delete. Click on “Rebuild Metric”, which will open the “Rebuild Custom Metric” popup.
Prerequisite Steps:
Once you have the API response from the Postman, let’s build a logic on the response received:
Task: Let’s multiply 2 numbers from the responses received.
Assumptions: Assuming we want to do the multiplication of the number received from question1 and option 1 of question 2. Here, question 2 is a multi select question, then:
CODE:function main(response) {
var a= parseInt(response.getResponseSet().get(0).getAnswerValues().get(0).getAnswerText());
var b= parseInt(response.getResponseSet().get(1).getAnswerValues().get(0).getAnswerText());
return a*b;
}Here, get(0).getAnswerValues() >> corresponds to the question 1 of the survey
And, get(0).getAnswerText() >> corresponds to the 1st option of the question 1
Similarly, get(1).getAnswerValues() >> corresponds to the question 2 of the survey and get(0).getAnswerText() >> corresponds to the 1st option of the question 2.
function main(response) {
var a= parseInt(response.getResponseSet().get(2).getAnswerValues().get(0).getAnswerText());
return a;
}
function main(response) {
var a= response.customVariables['val'];
var b= a*1;
return b;
}
In order to view the responses of the logic applied in Custom Metrics screen for the transactions, click on Analytics >> Manage Data >> Responses >> Settings >> Display Custom Metrics >> Save Changes