+ Start a Discussion

Google Analytics - _gaq.push() method

We are using Google Analytics in one of our Sties.  We've added the google analytics standard component tag to the bottom of each of our VF pages:


<site:googleAnalyticsTracking />


We are trying to get a more granular level of analytics tracking for some search result links. We have a datatable that iterates over a returned list of search results.  Within each result we have a couple of links we'd like to track.  Is it possible to use the javascript _gaq.push() method to capture data on when these links are clicked and pass the appropriate information into Google Analytics?  Can you use merge field syntax to pass the data into the method?


<apex:outputLink value="http://{!cont.Website__c}" onClick="_gaq.push(['_trackEvent', 'Category', 'Action', 'Label']);">


How would you use merge field syntax to pass in the appropriate data?


Has anyone done this?  Is it possible?


Thanks for any help.

Best Answer chosen by Admin (Salesforce Developers) 

the native google analytics tag in visualforce doesn't use the asynchronous analytics code you're trying to use.  it uses the 2+ years deprecated "old" version of the google analytics code.  as a workaround, create your own apex component that contains the "new" google analytics tracking code.  you can use merge field syntax to grab the analytics ID from the site config if you don't want to hard code it, but this will get you what you need.  your strategy looks ok otherwise.