This could be achieved by editing the Drupal template page.tpl.php. However, this would then mean you cannot run multiple sites from the same base theme template.
The Drupal Google Analytics module is currently available from the module downloads.
Drush install fails with
drush en google_analytics -y.
To install with Drush use:
drush dl google_analytics and then
drush en googleanalytics.
Note the underscore in the namespace.
The Drupal module also offers a bit more than basic tracking.
Allows you to provide a list of pages to track, or a list of pages not to track.
Usually Google Analytics will track all users on a site, but you can also omit groups of users by Drupal role. Simply un-tick the role name on the settings page.
The module provides functionality to track downloads of files, mailto and outgoing links on your site. Select the relevant options on the main Google Analytics settings page. A textfield is also provided where you can specify a list of file extensions that should be tracked. Separate each file extension with a '|' character
pdf|zip|doc or better leave the defaults.
To see the link tracking reports, go into your Google Analytics dashboard and click on the main Content menu item on the left. That should reveal the Event Tracking option.
Search and Adsense
Allows you to track internal search and track AdSense ads.
Allows you to send custom variables along with the Google Analytics tracking request. You can use node tokens to populate the value on pages that provide the node object.
Advanced settings for Google Analytics are hidden away in the collapsed fieldset. Expand it and you'll find the following additional features.
Cache tracking code
If you find your site pages load slow due to a delay in fetching the urchin.js/ga.js file from Google's servers - there's the option to cache the urchin.js/ga.js file locally on your server for 1 day. In order to use this feature your site must be configured to serve public files.
Custom code snippets
<script> ... </script> tags from the start and end of your snippet! The "before" textarea sets variables prior to the actual trackPageview, then the "after" handles variables, and additional actions (like tracking in multiple accounts).