Creating a Customer Survey with Google Analytics events

ShareShare on Facebook0Tweet about this on TwitterShare on LinkedIn0Share on Google+0Buffer this page

How to know if your website content was valuable to the visitor? You can look at different session metrics or social shares, but still may want to ask the visitors to get better insights. There are various online surveys to use, with their own features and limits. What I would like to share, is how to create a custom survey with just a little bit of coding and Google Analytics events.

The idea that I had (being lazy to write a PHP/MySQL survey script from zero or search for an out-of-the-box solution that would fit), is to use Google Analytics as a survey database and events for collecting submission.

For a start, you need to have a simple HTML code with a question and a few answer options to put near the content you would like to get feedback on:

<p id="gasurvey">
<strong><span class="gasurvey-question">Did you find this article useful? </span>
- <a id="good" class="gasurvey-answer" href="#vote">Yes</a>
- <a id="bad" class="gasurvey-answer" href="#vote">No</a>
</strong>
</p>

You can do some design with CSS to make all look nice .

Then you need to do 2 things when a visitor clicks on one of the answers:

  1. Send an event to Google Analytics to record the answer.
  2. Show a “Thank you” message. You can also add a link to the more comprehensive survey (Google Drive Forms or any specialized online tool) to learn more about the visitor experience. Visitors may be a bit more open and willing to contribute further after making a small and easy step first.

Here is the simple JavaScript that will change the content of the paragraph after the click. (Note that I am using jQuery library and for WordPress you need to use “jQuery” instead of $):

<script>
$(".gasurvey-answer").click(function (e) {
  // Show a thank you message with a survey link
  $("#gasurvey").html('<strong>Thank you! Would you like to tell us more? <a href="#link-to-a-full-survey">Just write it here!</a></strong>'); 
});
</script>

These two code snippets can be places in the body of the page near the content (like I did here) or if you are familiar with JavaScript – can add in the <head></head> section with the survey HTML appended in the desired place via JavaScript.

Now the Google Analytics part – you can send Google Analytics events from the onclick function, but I would suggest to go for Google Tag Manager setup to have less code on a page.

Google Tag Manager setup is pretty simple. First make 2 rules for link clicks:

  1.  Link Click – Survey – Answer with conditions: {{event}} equals gtm.linkClick and {{element classes }} contains gasurvey-answer
  2.  Link Click – Survey – Full Survey with conditions: {{event}} equals gtm.linkClick and {{element classes }} contains gasurvey-fullsurvey.

Next, create 2 Google Analytics tags with Track Type  “Event” and use the Rules described above:

  1. Event – Survey Answer with Category: Survey,  Action: survey-answer, Label: {{element id}}
  2. Event – Survey Link with Category: Survey,  Action: survey-link

And that’s it. Test if all works and start collecting data.

Conclusions & Demo

What I like in this solution, is that you will be able to connect the survey answers to all the Google Analytics data. Know where the user came from (source / medium / keyword), is he new or returning, his browser version, etc. Having “yes/no” answers as in my example may not provide all the insight you need, but will give you more to think about and examine further.

You could also use the replies for building remarketing lists, create advanced segment and do bunch of other things. Just remember not to ask and save any personally identifiable information (PII) as it’s against the Google Analytics usage policy.

Of course, there are much comprehensive ways and tools to do customer surveys and some of them can be integrated with Google Analytics (I’ve found Userreport,  iPerceptions & Survey Analytics – haven’t tried any of them, though), so your might want to check other solutions before creating something from scratch. There is also a good article on Google Customer Survey integration by Justin Cutroni and Avinash Kaushik had a great blog post on choosing a right survey tool.

And to demonstrate the script in action. I do hope to get more “Yes” ;)

Did you find this article useful?Yes  – No

ShareShare on Facebook0Tweet about this on TwitterShare on LinkedIn0Share on Google+0Buffer this page

2 thoughts on “Creating a Customer Survey with Google Analytics events

    1. Hi, you surely can code a custom survey with user login, while it is beyond the scope of this post. You can ask this on developer/coding forums or google developers forums to get more in-depth answers.

Leave a Reply

Your email address will not be published. Required fields are marked *