Mostly because of Stephen Hackett’s endorsement of it in Systematic #11, I’m giving Gauges a try for my blog analytics right now. One thing I immediately appreciated about Gauges was the simplicity of the API. You can easily incorporate it into scripts, tools, even things like Status Board, with a little output formatting.
The first thing I did was add a plugin to Slogger. It’s in the plugins_disabled folder right now. If you want to try it out, you can update your install to the latest version, or just download it directly and save it to your “plugins” folder.
./slogger -o gauges to initialize the config, then open your
slogger_config file in a text editor. You’ll need an API key, which is really easy to get. Once you’re logged into your Gauges account, go to My Account -> API keys and create a new key called “Gauges for Slogger” (or whatever) and copy the resulting string of letters and numbers. Paste that into
slogger_config and the next time you run it (or it runs automatically), you should get an entry for each of your Gauges. Each entry includes the total views, total visits, top five pages and top five referrers.
Next, I built a command line tool that works as a GeekTool geeklet. It requires an API key, too. If you created one for Slogger, just re-use it, otherwise follow the instructions above to get one. Hang on to it while I explain the rest of the setup.
First, you need to save the script as “gauges.rb” to a folder on your drive. It doesn’t really matter if it’s in your path unless you plan to use the command frequently from the command line. If that’s the case, I’ll assume you know how to put it in your path and make it executable.
You’ll need the JSON ruby gem as well. I don’t know why this isn’t included in the main Ruby distribution. Sorry. Run
gem install json (you may need
sudo gem install json if you get a permission error) to install it. If you’re using rvm be sure to install it in your “system” environment if you want GeekTool to be able to use it (GeekTool doesn’t inherit your shell environment).
Next, run the command from the command line:
ruby gauges.rb. The first time you run it, it will ask for the API key, which you can paste in at the prompt. Hit return and it will check your account and spit out (pretty, color-coded) Visits/View numbers for each gauge. It stores your key securely in your system Keychain as a generic Internet password1.
Note that you can customize the colors in the script by changing the color names in the output (GREEN, BLUE, etc.) to other colors defined above the function.
For GeekTool, I only wanted the unique visitors numbers for one gauge at a time. By running the script with a gauge name as the argument, you can get just that. If you add “views” as the next argument, you’ll get total page views instead of visitors.
Create a shell geeklet and add the command to it. Include the path to wherever you placed the script. For example,
~/scripts/gauges.rb brettterpstra.com will give me a visitors number that I can style however I like. You can add a label to the output in a second image geeklet, or a shell geeklet with “override text” turned on. Change the command to
~/scripts/gauges.rb brettterpstra.com views to get total views.
In case you missed the link earlier, here’s the CLI/GeekTool script on GitHub.
As a final note, the Gauges main dashboard makes a pretty good Dashboard widget2. Just load it up in Safari, click File->Open in Dashboard and select the graph/page list portion of the page. It will stay logged in and give you live updates every time you open Dashboard.
That’s it, really. I don’t know if I’ll settle on Gauges permanently, find something else, or go back to Google Analytics. I’ll have fun for as long as I’m here, though.
It’s a technique borrowed from the TextMate blogging bundle that I’m experimenting with as a solution for future scripts. It helps avoid forcing users to edit files or create external configuration files, and is ideal for scripts that just need one or two configuration settings. ↩
I know, I’m the only one left who uses Dashboard. I don’t understand why. I just turn it off as a space in Mission Control and use BetterTouchTool to make a 3-finger click swipe down on my Magic Trackpad open it up. I control my lights and my temperature there, track my deliveries and, obviously, my site analytics and up/downtime. ↩