views:

827

answers:

2

I'm developing sites using a content management system, features are added via 3rd party modules which is much easier for designers like myself. However, I'm a bit perplexed at the moment.

I have an AJAX-based contact form, so there is no page-load upon submission. However, I do have access to HTML templates for each step (Input page, Form submitted, and the email that is sent).

I did some research on the GA.js library and it seems like I'd want to use the _trackPageView function. I cobbled some code together based upon threads in the GA Help group, but I've been monitoring the account for 2days now (while submitting test forms ~5+ times per day) but I am not seeing the goal being completed, nor am I seeing the 'dummy page' show up under my Top Content list (fully expanded). The code I'm using is the following:

/script tag/

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

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

A: 

In the place where I've used this style of tracking I notice two difference between what I have and what you have.

First, at the top of the page, I've called

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

in addition to what you have. In my case that tracks the main page load before the secondary (ajax) call occurs.

Then when I do the GA call

pageTracker._trackPageview('/virtual/name_i_gave_the_call')

I have the virtual name in quotes, not just bare in the parens as you have it. Not sure which (if either) of these differences may help you, but it is working for me.

Devin Ceartas
I will give these a shot, unfortunately it will take a couple hours to gather any results thanks to GA's delay in updating the stats, I really wish there were some kind of sandbox mode or system that we could bounce this stuff off real-time :) Thanks!
SilentBobSC
Calling `pageTracker._initData();` is no more needed.
Török Gábor
+1  A: 

You have a syntax error in your JavaScript code. You must wrap the virtual URI in quotes since function _trackPageview expects a string as its argument.

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

For avoiding similar issues in the future, get an IDE that highlights syntax errors or check Firefox's Error Console for any problems.

Török Gábor