Even when I first started using Google Analytics I always preferred to put the tracking code at the top of the page. It just made more sense to me to make sure that I didn’t loose or miss some visitors in the statistics.
I understand why it is normally recommended to add it to the bottom. By putting it at the bottom it allows your entire page to load, and the last thing to load is the Google Analytics so that the visitors can view the page faster.
If you put it at the top then your page will stall until the Analytics code is fully loaded before continuing to load the rest of the page. As we all know visitors are pretty impatient so the faster the page loads the better.
For the most part, I keep my sites pretty slim and trim anyway. And if it loaded last then a visitor could potentially visit a page, and then leave before the tracking loaded, or even click off to another page throwing off your entry page stats as well as bounce rates, number of pages visited, etc, etc.
But here’s where the Asynchronous Tracking can help out. This code is designed to load first in the <head> tags of your page, and it will load at the same time as your page. This prevents any delays, but also ensures you are getting the statistics you really need.
Anyway, on to X-Cart. They’ve been including a little module for some time now that makes it pretty easy to just turn on and have statistics streaming in no time. But it was always at the bottom of the page, last thing to load.
I created a little mod for you guys here that will allow you to use the Google Asynchronous Tracking.
You can’t just swap out the main Google Tracking code for the Asynchronous otherwise the Commerce tracking will stop working. So I’ve fixed both sections and tried to keep it as minimal as possible on edits.
I did however create the mod as a separate mod instead of just modifying the Google Analytics that was there. This benefits you because you can easily switch back and forth if you are not sure of all this mumbo jumbo.
The file is included below for download. Uncompress it. You’ll find a README inside with quick instructions. As well as the only two files that need to be uploaded. I’ve tested it in 4.2.x and 4.3.x there are a few varying instructions so read carefully.
Most importantly, if you find problems or need help do not hesitate to ask. I’ll be glad to help as I need this in tip top shape for my projects anyway.
Download Google Asynchronous Tracking for X-Cart
Update: When you uncompress it there are four separate folders. Support added for 4.1.x, 4.2.x, 4.3.x and 4.4.x
Also, added support for Google Speed Tracking in the new Google Analytics reports. Remember speed is now a ranking factor so keep an eye on it.






5:39 pm
Any idea how one would go about utilizing your tpl files in X-Cart 4.1.x? Will they work?
8:12 pm
Yes they will work if you use the files for 4.2.x. There is a small difference though. In the instructions I mention adding some lines to the “service_head.tpl” file. Instead you’ll need to open the “home.tpl” file and add the same lines directly before the “</head>” closing tag towards the beginning of the file. Beyond that change everything should work fine.
12:00 pm
Looks like it edited out the closing tag you referenced in your message – I assume you mean the ‘head’ closing tag?
6:22 pm
Yes I did sorry about that. I fixed it.
Also, since you were asking about 4.1.x I have to say that another person installed it on 4.1.x and found problems with the eCommerce Tracking for 4.1.x. I’m going to work on a fix for it and provide an update.
6:48 pm
Awesome – I was going to ask that as well because I ran into a few smarty errors on the checkout page (from the ecommerce tracking portion). I didn’t know if it was because of a botched upgrade (I’ve never used the Google Analytics module supplied by Qualiteam… just my own), or something specific to your code.
On a related note, do you happen to know if custom variables created for older versions (read: whatever version was available in 2007) of the GA tracking script will work with the asynchronous code?
9:32 pm
Everything on the Asynchronous Tracking script is called differently. If you use some custom variables those variables might still work but the way you call them or use them in your site will be different. You can see all the migration examples here:
http://code.google.com/apis/analytics/docs/tracking/asyncMigrationExamples.html
3:59 pm
what about 4.4.3 support?
9:15 pm
I actually haven’t created a version for 4.4.3 yet as there wasn’t any requests for it. But I can definitely do it. The code is extremely simple as far as the changes goes. I’ll work on creating a release for 4.4.3 this weekend.
12:00 pm
I get a failure trying to load the patch, 4.1.8.
SQL PATCH FAILED AT QUERY:
INSERT INTO `xcart_config` ( `name` , `comment` , `value` , `category` , `orderby` , `type` , `defvalue` , `variants` , `validation` ) VALUES ( ‘ganalytics_asynchronous_commerce’, ‘eCommerce Tracking’, ‘N’, ‘Google_Asynchronous’, ’10′, ‘checkbox’, ‘N’, ”, ” )
Also, will this code work with GA’s new site speed metric?
Thank you
12:24 pm
I tried to manually patch it through phpmyadmin. It seems the field “validation” is not recognized.
12:30 pm
name comment value category orderby type defvalue variants
1:33 pm
I think I fixed it by manually adding a new field in xcart_config.
9:01 am
“Also, since you were asking about 4.1.x I have to say that another person installed it on 4.1.x and found problems with the eCommerce Tracking for 4.1.x. I’m going to work on a fix for it and provide an update.”
Hi Jason,
Our eCommerce Tracking is not working. Did you find a fix for the 4.1 carts?
Thank you!
11:27 am
No I haven’t. I don’t have a copy of X-Cart 4.1.x available to me any longer. It’s pretty out of date. There has been a little interest in it, if I could get my hands on it I could take a look. I have a license but as you know QualiTeam only has the latest releases in their file area, and all my clients have upgraded.
10:50 pm
There is a new plugin uploaded with 4.1.x files and 4.4.x files, and I’ve updated the version to support Speed Tracking in the new Google Analytics panel.
Just remember speed is a ranking factor now.
3:29 pm
Hi Jason,
Thanks for the mod.
Just installed it on v.4.4.2 and can only get the Google Account number to show up in the asynchronous code if I have the old Google Analytics mod switched on as well as the field for the account number in there populated.
(that of course means that I have both old and new codes appearing on the page).
Any idea on what I can do to fix this (short of hard coding the account number into the ga_code.tpl).?
Many thanks
Rupert
3:42 pm
Ah, I worked it out.
In the version of ga_code.tpl for the 4.4.x package, you have the call for the Google account number as:
{$config.Google_Analytics.ganalytics_code}
It should be:
{$config.Google_Asynchronous.ganalytics_asynchronous_code}
Replacing the former with the latter fixes the issue.
Best
Rupert
3:43 pm
Oh my mistake. I guess I put that together too quickly. Thanks for the catch I’ll update the code.
3:57 pm
No problem.
Thanks for the heads up on v4.4.2
3:34 pm
Rupert, I have it installed on a 4.4.3 installation and I am not getting the same result. Can you try it again, but this time clear your cache and also clear your template cache on your server for X-Cart?
Should be at:
x-cart dir /var/templates_c/
Depending on how your X-Cart is set up this might cause the issue. I’ll investigate the code and see if there might be something there. Although you may consider upgrading to 4.4.3 anyway, there are a lot of bugs in 4.4.2 especially with the address book.
3:43 pm
Hi Jason,
Our comments overlapped.
See my reply to my own comment above.
Best
Rupert
7:25 am
Hi Mate,
Thanks for this mod, was simple enough to install. All seems to be working so far but need to wait until we make a sales before I can confirm if the e-commerce side works as I could never get it to work on the standard mod.
Thanks again
8:07 am
It works
This is great, thank you very much for this.