Magento – How to implement google conversion tracking on a form

formsgoogle analytics

We have a form on our magento site for folks to apply for financing. The results get emailed. Simple enough. When someone submits the form, there is no redirect to a thank you page, only a message that pops up. What I don't know is what url I am supposed to use to track form submissions or what I need to do to get it working. The tag assistant in chrome shows the analytics is alive and well on the finance/apply page, which is where the success message pops up. I am not the programmer of the magento site, rather the marketing person told to figure this out. I've set up tracking successfully on the /checkout/onepage/success/ and it is working. I just am not sure how to handle form submission. Any and all help is appreciated.

Best Answer

There are a few ways to handle this, but to be honest in my experience the EASIEST way to track conversions is with a destination page. You'll need less programming experience to reconfigure your form to redirect to a submission confirmation page than you will to use the other methods, but I'll outline the simplest option available to you below.

Use JavaScript to register an URL click in Google Analytics that you have setup as a destination url for your goal tracking.

To use this method, first you have to setup a destination url goal conversion tracker for a page THAT DOES NOT ACTUALLY EXIST. This ensures that only the code you use below will trigger the goal conversion.

For example, let's assume you setup a goal conversion for the url on your site of /url-that-doesnt-exist.html

My guess is that if you look at the html code for your financing application form, there will be some login around the submit button that a user must click that calls a function to grab the form field data and generate an email that's sent to you. In my experience, that's the most common way those pop-up forms are generated and forms are sent via email without using a redirection page (they are submitted via JavaScript functions instead of PHP pages or controllers).

<input type="submit" onclick="someFunction();">

If you have logic like the above that is submitting your form and sending you the application via email, then you can use the _gaq.push function from the Google Analytics JavaScript API to register the fake URL you setup above as a goal conversion. To do this, you need to add the following logic to the javascript function that is submitting your form and sending you the email (In my above example you can see that the function name is someFunction() but you'll need to find the actual function that is used in your form):

_gaq.push([‘_trackPageview’,’/url-that-doesnt-exist.html’]);

This SHOULD work assuming you've setup a goal conversion tracker in your GA account pointing to /url-that-doesnt-exist.html

What you are doing is basically enhancing the JavaScript function that processes your current form, emails the results to you and generates the pop-up message so that it ALSO tells Google Analytics to record a hit on the URL that you setup for your goal conversion.

Here are some additional references for GA Tracking via advanced events, JavaScript functions, etc...(ie NON-Destination-Page-based)

Related Topic