Integrating Google Analytics With Your SurveyGizmo Surveys

Ever want to know a little bit more about how people are interacting with your surveys?

Us too.

That’s why we offer an integration between SurveyGizmo and Google Analytics

Why would we want to do this?

Well, Google Analytics is a very powerful (and free) web analytics suite. It allows you to track survey conversions, path analysis, sources of surveys traffic and even various versions of your forms and surveys. It’s the best of all worlds.

So let’s get the ball rolling:

Introduction to Google Integration Code

When you create a Google Analytics account you are given code snippets and instructed to place them at the bottom of each page on your website. For use in surveys, you will need to add them to the HTML Template of your Survey’s Theme.

The code should looks like this: (highlight to copy all of the code, WordPress isn’t playing nice in displaying it)

<script type="text/javascript">//
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'YOUR GA CODE']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
    ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
    var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
} );
</script>

You should place this bit of code at the top of your survey’s HTML template (the very top). First we are going to modify this bit just a little. Why? Because we want to track individual survey pages, and make them a bit easier to understand in Google Analytics.

So, here is what we are going to do.

We are going to pass an argument (a bit of data) to the urchinTracker function that will identify individual pages of the survey. We are also going to create a “fake” folder for our survey.

You will need to change two lines of the above code, one to add your GA Code, and another to reference a page in the survey. When finished with the changes, your whole code will look like this:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'YOUR GA CODE']);
_gaq.push(['_setDomainName', 'yourwebsitedomain.com']);
_gaq.push(['_trackPageview', '/surveys/surveyname/page[template("currentpagenumber")].html']);
 
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
} );
 </script>

*Note – This has code has been updated to work with SurveyGizmo 3.0 surveys which use a new merge code system. If you are using a SurveyGizmo 2.0 survey, you’ll want to insert [%%:Survey_Page%%] instead of [template(“currentpagenumber”)] in order to track page numbers.

You should replace “surveyname” for every survey you integrate. Make it distinct and understandable. The merge code [template(“currentpagenumber”)] will merge in the current page number.

Tip: If you want to get fancier you can merge in the value of a hidden question on the page, or even question data from previous pages this way.





survey dev tools ebook guide




When you launch your survey, it will store the navigation and traffic information to your Google Analytics account!

From here you can treat your “surveys” folder like it was just another part of your website. You can run your favorite reports, build charts graphs, etc. Enjoy! Next week we will look into test variations of your surveys and landing pages and doing analysis in Google Analytics.

 

**This has been updated with the new Google Analytics code.

 

Join the Conversation
  • Is there a list or page containing the syntax for passing information from Gizmo to Google?

  • Nils

    How about connecting Google Analytics data with the survey data. Is it possible to match this data?

  • Great to see you have been thinking about the things we like to do! However Google have an updated code fragment to use – can you update your code sample to use this.

    I was not able to find the next part of your series – “Next week we will look into test variations of your surveys and landing pages and doing analysis in Google Analytics.” – a piece on setting goals and analysing what is happening would be good – also how to reduce abandonment rates!

  • Pingback: Kudzu Business Success Center - 11 Ways Small Businesses Can Use Surveys for Online Marketing()

  • Greg B

    Will this code work when using an iFrame on our site for the SurveyGizmo form?

    • Hi Greg,
      This should work with the iFrame method. But when it comes to analytics, we always suggest testing it out first.
      Cheers!
      Brittany

  • Mike Roedema

    This isn’t working for me. Is this code still current? Is it OK to use a template merge code that might contain characters invalid for a URL, like spaces? Because we use one template for all our surveys, I’m trying to form an opt_pageURL argument that will include the survey title, and because our surveys can be lengthy, I’m including the page title as well. This is the path:

    ‘/[template(“survey title”)]/page[template(“currentpagenumber”)]/[template(“page title”)]’

    • sgizmo

      Hi Mike,

      Google has changed the way they track a bit. We’re updating the code above to show this.

      What’s missing is this line: _gaq.push([‘_setDomainName’, ‘A.com’]);

      This is required for cross domain tracking.

      -Christian

      • Mike Roedema

        Christian, thanks so much for the prompt reply. I actually had a bigger problem in that I set up a Universal Analytics (analytics.js) account and was trying to use this Classic (ga.js) code. I’m now using the correct script for UA but haven’t tested it yet. I set up an account just for SG, so I shouldn’t need cross domain tracking. It remains to be seen whether my fancy path will work.

        • Christian Vanek

          Mike,

          Oh! I’m afraid the documentation on Universal is a little scarce at this point (gotta love Google). Let us know if we can be of any other help!

          Cheers,

          -Christian

  • Justin Crowe

    Hi Mike,

    I’m opening up a ticket with this question for you with our Support team & someone should be in touch soon!

    Cheers & happy surveying!
    Justin

  • Lena Prickett

    I can’t seem to get this to work — I’ve pasted the code into my survey’s HTML template, but nothing’s showing up in my Google Analytics account. Do I need to take a further step to activate?

    • sgizmo

      Lena – Give us a call so we can look at your survey and help you out!

  • nhocks

    The page the survey is on already has the analytics code (not within the survey iframe). Would I need to remove this code from the page first or can it stay there?

    • sgizmo

      You should be just fine to keep your current page’s analytics in place. There shouldn’t be any conflicts since you’re using a totally different page view action for your survey and your browser treats an iframe like a totally separate page as far as JavaScript is concerned. Thanks for the question!