Server side image requests
PHP (I’ll focus on PHP in this example) can also request a file from the internet without executing or showing it. Just requesting the analytics image is enough to trigger a hit in your report and it will show up in your account. The downside of requesting the image from your server is: You lose the IP address and other data that Google records at the moment the image is requested. The server IP of your web server will be recorded.
Server side requests in a client side report will obscure your data. Create a separate Analytics profile for everything you log server side.
Who requests my RSS feed?
- Create a new analytics profile with its own tracking code (not a copy of an existing profile). Activate the profile by temporarily changing the code on your homepage. After activating you return it to the original one.
- Add the following PHP code to the file that produces your RSS (preferably at the bottom): urchin-image.txt
- Update the urchin code, domain, user defined variable (if desired) and the fake page request you’d like to track.
- I left all the other data intact because it works with them and they don’t impact the report, but when I have time I can probably clean it up some more.
Tracking PDF or Image requests
The script that produces your RSS feed is already executing PHP code. Images and PDF files don’t execute anything, so you need to add something extra to track these in a similar way. The following code shows you how you can request an image, PDF, SWF or for instance downloads and request the Google Analytics (Urchin) code at the same time.
- Find out if your server supports mod_rewrite. If it does, you can produce cleaner URLs. As a RewriteRule in your htaccess you add something like: “RewriteRule ^tracker/(.*).gif$ /tracker.php?url=$1&filetype=gif [L]“. This requests the file tracker.php whenever a gif image from the (non-existing) directory tracker is requested. You can do the same with all other filetypes that don’t execute PHP code themselves.
- Create tracker.php and add something like the following code: tracker.txt. Customize the script where needed and add content type headers for everything you’ve added to the htaccess.
- Now you can open the extra profile you should have created and under “Content Optimization > Content Performance > Content Drilldown” you find the directory “tracker” with all image/file requests logged in it.
Here are all values you can fill: image-url-explained.txt
Google Analytics is very good once you implement some of the following tweaks.