I want to add Google Analytics to our website and read some conflicting information on where to put the script tag.
Google says to put it before the closing tag </ head>: http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html
</ head>
As our site is designed, this will mean editing each page. This is not a big deal if I need to do this, however our site also uses header and footer files.
These header and footer files have HTML code and they fall into the tags <body>even </body>after the page loads.
<body>
</body>
It would be much easier to add a script to the header or footer file. I would just insert it there once, and it will serve the code on each page.
My question is: can I do this? Can I move the script fragment inside the footer even though it is not up to the tag </head>that Google offers?
</head>
Am I asking for problems if I do this?
Thank!!
You can.
, " " (.. </body>), DOM ( script), script. , script DOM, ( ).
script
, , , script , , - , w371 > .
, Google <head>, , , , , .
<head>
. :. Firefox IE . , , . , , - , . , . , , , , , , .
, , , . , , .
, ( WordPress, ). , JS html ( < /body>), .
< /body>
, . script ; <head>, , document.ready. , . , .
document.ready
, , , .
f you have a header and footer file, why not just add your own Google Analytics code to it? Unless, of course, each page has a unique footer / header page. Then I recommend you take a look at MVC .