Install Google tracking, apache level
Solution 1:
If you use Google PageSpeed Module you could set in the .htaccess:
ModPagespeedEnableFilters insert_ga
ModPagespeedAnalyticsID <Analytics ID>
See details here.
Solution 2:
This is certainly possible via Apache. You can use the add-handler to add an action for all .htm or .php file on a per server, per directory or even in .htaccess.
Action add-footer /path/to/footer.cgi
AddHandler add-footer .htm
Where footer.cgi is a script which will add the footer to the file.
You can also do this within the php processing (although it would then only work for php files) using
php_value auto_append_file /path/to/footer.php
This will add the code in footer.php to your PHP code.