Jump to content

How can I track form submissions in Google Analytics?

Go to solution Solved by foleyatwork,

Recommended Posts

I'm want to use Google Analytics to track conversions from my Squarespace 6 site - those conversions being a completed form on the site - but cannot find a way to include the code in the submission button or the form submitted page.

Does anyone know of a workaround to allow me to track completed forms?

Edited by erich
retag
Link to comment
  • 2 weeks later...

jQuery code injection will do the job. Just inject the following code on your form page, replacing the category and action with your own labels.


    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
   <script type="text/javascript">

   $(document).ready(function(){
       $('input.button').click(function() {
           window.setInterval(foo, 100);
       });
   });

   function foo(){
           if($(".form-submission-text").is(':visible')){
               _gaq.push(['_trackEvent', 'YourForm', 'Submission']);
           }
   }

   </script>

Edited by edwinorange
Link to comment
  • 2 weeks later...
  • Solution

Paste the following code into the footer code injection of your site.


<script>
 Y.use('node', function() {
   Y.on('domready', function() {
     Y.all('.form-block').each(function(n) {
       var d = n.getData('block-json');
       d = Y.JSON.parse(d);
       n.one('form').on('submit',function() {
         _gaq.push(['_trackEvent', d.formName + ' Submission', 'Form Submission', 'Submit']);
       });
     });
   });
 });
</script>

This is a one step process. Once you paste this code in your footer, each form will be tracked automatically with the form name in Google Analytics.

Please post any feedback as a comment here. If there is a bug I will try and fix it.

Also, please note this is not supported by Squarespace, even though I am a Squarespace employee. Support won't be able to help you out, but I will do my best to make sure this code works and stays up-do-date.

Edited by foleyatwork

Developer Evangelist at Squarespace.

Link to comment
  • 3 weeks later...

Hello-

Would this also work for tracking e-commerce conversions? I am searching for a way to track conversions from Adwords, etc through to purchase. There is currently no way to inject code into the completed sale page.

Any help is appreciated.

Andy

Link to comment
  • 1 month later...
  • 3 weeks later...

I am unable to get this to work.

Looking at the page elements in the browser inspector window I do not see the formName property in the form-block, and thus when the form 'submit' event fires, d.formName is undefined. My form-block looks like this:


<div class="sqs-block form-block" data-block-json="{"useLightbox":false,"lightboxHandleText":"Get Info","formId":"51d4498ee4b03b50e2322d8c"}" data-block-type="9" id="block-6d99117d0a0ea3afbb33">

is there another way to get the formName from the formId?

Edited by Mark L
Link to comment
  • 1 month later...
  • 4 weeks later...

This does not work with google adwords campaigns.

Any proof it does?

Since squarespace is so focused on small businesses, wouldn't this be a core feature? Tracking money spent to drive traffic that converts to my new sqaurespace contact form?

Link to comment
  • 3 weeks later...
  • 2 weeks later...

THIS IS FOR ADWORDS, NOT ANALYTICSYou can simply paste the Google Adwords code into the Post-Submit HTML box under Edit Form -> Advanced. e.g:

?value=0&label=7opUCNj90wQQmJWz6AMX&guid

This script will be fired only on successful submission of the form.

See My new Answer Related to a simple method related to creating a /Thank-You page.

Edited by webbroi
Link to comment

ok, so @foleyatwork i just tried this (adding the google adwords script to the 'post-submit html' on the contact's advance form. @webbroi said this works).

we'll see, but it looks like the code is there on the first page load too. i believe that will trigger a google adwords 'conversion' as soon as the contact page is loaded. correct me if i'm wrong.

thanks!

Edited by odower
Link to comment
  • 4 weeks later...
  • 2 months later...

Hello,

I'm interested in using this code snippet in the footer of my site to track form submissions, but I wanted to check first to make sure this would work as is, even if I have changed the names of the submission buttons from the standard "Submit" to something else like "Register"? Will this code still automatically send all form submissions to Google Analytics?

Thanks!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.