AJAX-based form tracking with Google Analytics goals

I develop sites using a content management system, functions are added through third-party modules, which is much easier for designers like me. However, I am a little puzzled at the moment.

I have an AJAX based contact form, so there is no page loading when submitting the page. However, I do have access to HTML templates for each step (input page, submitted form, and sent email).

I did some research in the GA.js library, and it seems to me that I want to use the _trackPageView function. I have combined some thread-based code in the GA help group, but now I track the account for 2 days (when sending test forms ~ 5 + once a day), but I don’t see the goal being completed, seeing that the "dummy page "appears in my list of" Top Content "(fully expanded). The code I use is as follows:

/script tag/ try { var pageTracker = _gat._getTracker("UA-#####-##"); pageTracker._trackPageview(/formcomplete.html); } catch(err) {} /close script/ 

The target URI is configured as Head Match and uses the /formcomplete.html value, it is active, and the site is tracking. Any thoughts?

+4
source share
2 answers

You have a syntax error in your JavaScript code. You must wrap the virtual URI in quotation marks because the _trackPageview function expects a string as an argument.

 pageTracker._trackPageview("/formcomplete.html"); 

To avoid similar problems in the future, get an IDE that highlights syntax errors or checks the Firefox Error Console for any problems.

+6
source

In the place where I used this tracking style, I notice two differences between what I have and what you have.

First, at the top of the page, I called

 pageTracker._initData(); pageTracker._trackPageview(); 

in addition to what you have. In my case, this tracks the loading of the main page before the secondary (ajax) call.

Then when I make a GA call

 pageTracker._trackPageview('/virtual/name_i_gave_the_call') 

I have a virtual name in quotation marks, and not just in parens, as you have. Not sure which of these differences might help you, but it works for me.

0
source

All Articles