Tweaking Google Analytics for widgets and blog parts
Blog-widget coders (blog-parts in Japanese parlance) who use Google Analytics (”GA”) may find that requests for their widget are not being tallied. The primary reason is because GA does most of its processing, and obtains much information from, client-side with javascript. But there is a way to add entries to your GA account without javascript, and I’ll share some PHP code below to help you on your way.
First though, you should read the following entries as they provided most of the information I am sharing. You’ll have a much better understanding what’s going on in the code, and about GA in general:
- server-side and client-side web analytics
- unobtrusive click assignments for Google Analytics
- Google Analytics without javascript
Now the code: this PHP snippet will generate the URL with the values you specify, and make the call to GA. There are a few parameters I’m not 100% certain about, but it shouldn’t break your stats as is. You will of course need to replace a few variables - such as the Google Analytics account number, the referrer URL, the title of the page you want to track, etc.
I make no claims about my coding style :) - just trying to help anyone who had similar issues about tracking widgets that I had
Enjoy!
Update: Two caveats I forgot to note regarding how this method will affect your GA stats. cURL identifies itself as “gzip” when making a page request (in this case, when notifying GA) so you’ll see gzip as a common browser. Also, the calls will be made from your hosting provider, which will skew the location statistics - i.e., if you have a service specifically for Japan but are hosting from a cheap provider in the US, you may notice a lot of visitors from the US …


Wordpress + Gmail mobile blogging:
Stardom Decktank:
Krugman's Interstellar paper:
svn:ignore propset:
So, who will you vote for?:
The best way to IKEA from Tokyo: