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
Johnny BaillargeauxJohnny Baillargeaux 

Force a page to be tracked with google analytics

Hi,

I have created an e-commerce site and enabled google analytics by setting the tracking code field on the site config page in salesforce. My page template uses the site component <site:googleAnalyticsTracking/> and the data are exposed to my GA dashboard as expected.

I just have one issue with one specific page. The checkout process (5 steps) is in reality just 1 visual force page with the same URL accross the different steps therefore, for this specific part of the site, I cannot create reports to check on which step the user decided to leave or any other similar requirement like this.

When I look at how site:googleAnalyticsTracking is rendered on the output HTML, i can see the following javascript injected:
 
try {
          var pageTracker = _gat._getTracker("<my tracking code>");

          pageTracker._setCookiePath("/cp");
        pageTracker._trackPageview();
     }
     catch(err) {
     }

By looking the GA documentation (https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration?csw=1#_gat.GA_Tracker_._trackPageview), I can see that we can force a URL.

How to do it because the javascript is populated automatically because of the GA site component. Worst case, I can try to overwrite the value by injecting "pageTracker._trackPageview('Step1')", pageTracker._trackPageview('Step2),etc... on the click event for each of the next/back buttons visible at the bottom of my checkout process but is there a way to do it more properly?

Of course an option would be to create 1 page per step but this is a real complex checkout process with a lot of call to outbound API and it will require a lot of refactoring and rewrite the test classes.

Any help or guideline would help me a lot. Thanks in advance for your help.

Cdt.