views:

133

answers:

2

I'm including the Google Analytics Script divided into 2 pierces of Javascript code:

google-analytics.js: (above)

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "

page-tracker.js

try {
var pageTracker = _gat._getTracker("U*-********-*");
pageTracker._trackPageview();
} catch(err) {}

(I hided the "U*-**-*" because I think it's an important serial number, not sure)

I tried placing them in the same Javascript file and I waited for 1 day and Google didn't start tracking my page. Am I doing something wrong?

Should I just place them in a same file. How?

(I checked the URL and its right and i set the default page to be index.php)

+1  A: 

You have to place both pieces of GA code on the same page you want tracked, that is the only way it should work.

Google's Analytics setup page says:

Copy the following code, then paste it onto every page you want to track immediately before the </body> tag.

Or as written on the "Learn More" link:

Implementing the code Once you find the code snippet, copy and paste it into the bottom of your content, immediately before the </body> tag of each page you are planning to track. If you use a common include or template, you can enter it there. To implement tracking code for secure pages (e.g. https://), please read How do I obtain tracking code for secure pages?

...and the link: Learn More

shanabus
A: 

Depends where you put your script tag which includes the first chunk of code, if its after the pageTracker call then you'll have trouble as it won't be in the DOM yet.

Your better off just including it in the footer as it comes from Google. Are you splitting it for browser caching reasons? Or because you want to log different info per page? Other than that I can't see a reason for why you would want to split it.

Pete Duncanson
I wanted a cleaner code in my index.php
janoChen