function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bohemianguy100bohemianguy100 

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) 
paul-lmipaul-lmi

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.