I find it annoying to paste in the Google code for the tracker at the end of each page.
Is there a way to have Apache deliver the <script> with each *.htm and *.php file downloaded?
I find it annoying to paste in the Google code for the tracker at the end of each page.
Is there a way to have Apache deliver the <script> with each *.htm and *.php file downloaded?
If you use Google PageSpeed Module you could set in the .htaccess:
See details here.
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.
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
This will add the code in footer.php to your PHP code.
We solved this problem a year ago by writing a module. It looks like someone else did this as well: https://github.com/dragon3/mod_google_analytics.
This is especially useful if you are front-ending an application you can't modify or something in tomcat you don't want to tweak.
After looking at that module, it seems like they don't check for text/html.. which might mean the module could trash your binary content if you don't use AddOutputFilterByType .. text/html. Be warned!