This article provides an overview of how to use the Response completed trigger to access all of the answers contained within a single survey submission.
Perfect for multi-question surveys, workflows based on this trigger will be able to determine what actions to take based on one or more of the survey answers.
Please Note:
This article presumes that you have both Grapevine Surveys and Shopify Flow installed in your store, that you are familiar with how to create Shopify Flow workflows and that you have an action you'd like to take based on the answers of your survey.
Quick links
- Why would I use this?
- The Response completed trigger
- Creating a workflow using the Response completed trigger
- Looping through the entire response variable array
- Handling the response array based on conditions
- Need any help?
Why would I use this?
Let's say that a customer filled out your post-purchase multi-question survey and provided an NPS score of 7 (or less) but failed to provide an answer to the next question which asked the reason for their rating.
Surely you'd want your Customer Support Team to follow up with the respondent to find out what went wrong?
Having the complete set of survey answers available within a single trigger enables you to create workflows to handle a variety of scenarios by combining conditions and actions.
Something as simple as a Slack ping into the Customer Support Team's Slack channel, could provide all the information required for the team to swing into action and turn that customer's frown upside down.
The Response completed trigger
The Response complete trigger will fire when a respondent has answered the last question in a survey. It will only fire once if ALL required questions have been answered and the survey has been submitted.
The payload of this trigger will contain a response variable that holds an array of all of the questions and answers within the survey.
The response variable array can be accessed via liquid, but it can also be queried using Flow conditions, making it really simple to define a set of conditions that must be met before taking an action.
We'll take a look at how to handle the response variable array using both of these methods, but first, let's set up our workflow to use the Response completed trigger.
Creating a workflow using the Response completed trigger
Let's start by creating a new workflow.
Select the Grapevine Surveys triggers and then select the Response complete trigger:
Next, we need to add a condition to only handle responses from a specific survey.
To do this, visit the Grapevine Surveys app and from the surveys overview screen, click on your chosen survey to open the survey report view and then copy the unique survey code from the top of the page:
Now that you have the survey code, head back to your workflow and add a condition to Check if the survey code in the trigger matches the survey you want to handle responses for.
Search the available trigger variables in the right-hand settings panel and select the surveycode variable.
Make sure that the Equal to operator is selected and then paste your survey code in as the value:
That's the basics.
We'll use the Log output action to access the results.
Add the Log output action to your workflow:
Looping through the entire response variable array
We're going to output each survey question and answer into the Log output action to demonstrate the contents of the Response array within the Response completed trigger.
Select the Log output action that you just added to your workflow and select the Add a variable link:
Scroll to the bottom of the list of available variables and select the Response variable under the Shopify API section and then select answers:
Then select answer:
You will see that the Output field of the Log output action has been updated with the following liquid code:
{% for answers_item in response.answers %}
{{answers_item.answer}}
{% endfor %}
Although we only selected the answer key, there are three keys within each item of the response multi-dimensional array. These are:
questioncode - {{answers_item.questioncode}} - The unique code associated to a question in your survey
question - {{answers_item.question}} - The text of the question asked
answer - {{answers_item.answer}} - The answer provided by the survey respondent
Let's add the two other keys to our liquid loop. This will need to be done manually rather than using the Add a variable link.
I have separated the keys using a forward slash, but you can choose how to separate your data:
Your liquid code may therefore look as follows in the Log output action:
{% for answers_item in response.answers %}
{{answers_item.questioncode}} / {{answers_item.question}} / {{answers_item.answer}}
{% endfor %}
Feel free to add the other trigger variables into the Log output action to give further context about the survey response, e.g.
Response date: {{responsedate}}
Survey name: {{surveyname}}
Survey code: {{surveycode}}
Surface: {{surface}}
Customer ID: {{customerid}}
External ID: {{externalid}}
Customer Name: {{customername}}
Customer Email: {{customeremail}}
Order ID: {{orderid}}
Order Name: {{ordername}}
Order Total: {{ordertotal}}
Survey Responses:
{% for answers_item in response.answers %}
{{answers_item.questioncode}} / {{answers_item.question}} / {{answers_item.answer}}
{% endfor %}
Give your workflow a name and then turn it on.
When you next receive a response to your survey, the workflow will output the trigger variables and will loop through each question/answer in the response.answers array to output the questioncode, question and answer.
Let's see how that output looks. Visit your workflow again in Shopify Flow and click on the latest workflow run:
Then scroll down to the logged output section and you should see something similar to the following:
As you can see, all of the survey answers have been logged in the output as well as the question code and question.
It's now down to you to decide where to send this data, whether it's a slack ping to the Customer Support Team or a new row in a Google Sheet.
Handling the response array based on conditions
As per our example at the beginning of this article, you may only want an action to run when a specific combination of answers are present within a survey response. We'll create a workflow now that will only log the output IF the answer to two specific survey questions meet our conditions.
Create a new workflow using the Response completed trigger and the condition to ensure it only works with a specific survey.
Now add a condition:
In the right-hand pane, select Add a variable:
Scroll to the bottom of the list of variables and under the Shopify API section, select Response:
Then select answers:
And then questioncode:
The Condition configuration panel will then appear:
You will now need to locate the question code for the questions you are looking to use in your condition. In our example workflow, we are going to need to know the answer to two specific questions out of a possible 5 to determine if we should run a particular action or not.
You can locate your survey question question code either from the report view of the survey, or, you can create a test workflow to log the output of the Response completed trigger as described earlier in this article.
For our workflow example we want to know if the answer to our NPS survey is a value of 7, or less.
Armed with our questioncode, we can now start to configure the condition to only look at this question within the Response array:
Now we need to check if the answer to this NPS question is 7 or less. Let's add some more criteria to this condition. Select the Add criteria button and choose the AND operator:
And then select answers_item and then answer from the available variables:
Within the answer_item.answer criteria change the operator from Equal to to Is not any of:
Within the Answer input field of that criteria, enter the number 8 and hit return, then the number 9 and hit return and the number 10 and hit return. That criteria should then look as follows:
Now we need to add some further criteria to check if the open text question after the NPS question is empty or not. If it is empty and the NPS score is 7 or less, then we want to notify the Customer Support Team.
Select the Add criteria button at the very bottom of the Condition configuration panel and select the AND operator:
Once again, scroll to the bottom of the list of variables and under the Shopify API section, select Response, then answers and then questioncode:
Enter the question code for the open text question following the NPS question:
Now we need to add criteria to check if the respondent has answered this question or not. Select the Add criteria button and choose the AND operator:
And then select answers_item and then answer from the available variables:
Within the answer_item.answer criteria change the operator from Equal to to Empty or does not exist:
Your workflow should now look as follows:
Let's add an action to email the support team with this information:
On the Check If condition, select Then, select Action and find the Send internal email action under the Flow actions:
Within the Send internal email action configuration panel, add in the email address of your Customer Support Team and the subject line of the email.
Now paste the following code into the Message field:
The following customer has left an NPS score of 7 or less.
Please follow-up with them to see how we can improve.
Details:
Response date: {{responsedate}}
Survey name: {{surveyname}}
Survey code: {{surveycode}}
Surface: {{surface}}
Customer ID: {{customerid}}
External ID: {{externalid}}
Customer Name: {{customername}}
Customer Email: {{customeremail}}
Order ID: {{orderid}}
Order Name: {{ordername}}
Order Total: {{ordertotal}}
Survey Responses:
{% for answers_item in response.answers %}
{{answers_item.questioncode}} / {{answers_item.question}} / {{answers_item.answer}}
{% endfor %}
This is how your completed workflow will appear:
Give your workflow a name:
Now turn on your workflow:
That's it!
Run some tests to see if your workflow works.
As you can see from a test run of our example workflow, even though the customer has left an NPS score of 6, they also submitted an answer to the open text question asking the reason for their rating. Therefore, the workflow did not execute the Send internal email action:
In this test run of the workflow, the customer has left an NPS score of 6 but did not answer the open text question asking the reason for their rating. Therefore, the workflow did execute the Send internal email action:
In this test run, the customer has left an NPS score of 10 but did not answer the open text question asking the reason for their rating. Therefore, the workflow did not execute the Send internal email action because the rating was higher than a 7:
Run your own tests and tweak your workflow until it meets your needs.
You can add further conditions and actions into the same workflow to handle a variety of different scenarios. Shopify Flow opens up endless possibilities for how you can handle your survey data.