jquerygoogle-analyticscontent-management-systemgoal-tracking

CMS - how to make it easy to set up?


I have been wondering a thing in a day or two. I was wondering that if I am e.g. Adding a comment with some jQuery on a submit button would it then be stupid to make a file - for example:

tracking.php?Param=[...]

And then Everything that can be made to a goal in analytics will have it's own parameter. The file does not have to include any code - the visit of the file should be enough for analytics, right?

So if I in my system has two formulars and want to have set up some goals on each of them and use tracking.php as my "goal-URL" is this an okay way to do so:

Calling the file in jQuery as this: tracking.php?Param=form1 tracking.php?Param=form2

As mentioned above the file would not have any content - just an empty file. And therefore it shouldn't make any delay - is that right?

OR is this just a bad workaound, that I have come up with in some late hours of thinking?


Solution

  • First off, that's not going to work. GA code needs to be executed at some point in time. GA does not automatically track requests made by javascript (jquery).

    And on that note, as Mads Jenson mentioned, you are reinventing the wheel. Unfortunately for some weird reason, you cannot use custom variables or events as goals, only URLs...I hear rumors that GA is going to eventually add that in, but until then, you are stuck with popping virtual page views to make goals.

    So, on a given page, if you want to track something as a goal, just call the following:

    var virtualPage = "/tracking/[...]";
    _gaq.push(['_trackPageview',virtualPage]);
    

    you would put whatever value you want in virtualPage but "/tracking/" as a prefix, followed by a specific value is a clean way to do it, and is similar to your idea of having a single url w/ unique parameter values (though you can pass it exactly as you put it if you want...).

    You can put that in a wrapper function to be called on an onclick, hover, after a certain amount of time has passed, if some other condition is met... whatever you want.

    But fair warning, there is a limit to how many requests GA will allow to make to it in per visit, so don't go crazy with tracking everything under the sun as a goal, or you may end up screwing yourself on tracking other custom tracking you've done, or even basic page view hits...