Enhancing Google Analytics Using Greasemonkey
By Sal Uryasev
April 11, 2008
Find more about:
webanalytics
google
analytics
hack
greasemonkey
There is a new post that re-releases the script as a Firefox Plugin. Find it here.
My boss Zach has a problem. Every four hours the craving strikes him. No matter where he is, he pulls out his shiny Macbook Pro and navigates to Juice's Google Analytics site. He pulls up the list of referrers to our site and meticulously searches for new domains. He has an freakish ability to pick out IP addresses that have never linked to us before. Even so, there had to be a better way.
I wondered whether Greasemonkey might be able to help. Greasemonkey is an extension for Firefox that allows users to install custom javascript when you visit a specific website. These scripts can add a delete button for Gmail, automatically display lyrics to your YouTube music video, or do pretty much anything else you would want to enhance the functionality of a website.
After poking around the subtleties of the Google Analytics interface, I came up with a little script that can identify the new referrals that Zach so desperately craves. When navigating to the "Referring Sites" section of Google Analytics, the script add the following button to the interface.

Pushing the button downloads all the referrer data for the date displayed in the Google Analytics range, as well as a similar set of data for the range up to, but not including, the last three days. The difference between the two data sources is used to calculate all of the results. The specific number of days can be changed by editing the first line of the script. Greasemonkey then displays the results in two tables above the original Referrer table. (Greasemonkey works entirely within your browser shell, so your data should be quite secure.)

The first table shows any sites that have displayed more than a 50% increase in visits over the last 3 days as compared to the rest of the time range. The second shows all new recent sites that do not appear at all more than 3 days ago. This can be quite useful to anyone, who, like Zach, absolutely needs to know about any new and exciting inbound links.
Installation Instructions:
Firefox 2.0+
Greasemonkey
googleanalyticsdownloade.user.js
If you don't already have Firefox, install it. Install Greasemonkey, and do the required Firefox restart. You should see a handsome monkey peeking at you from the bottom right hand corner of your browser. Open the script file in your firefox browser, and Greasemonkey should give you an option to install the script.
Afterwards, log into Google Analytics, and navigate to your Referring Sources Tab. Click the button.





20 comments | Show all comments only the last 5 are shown
John Henson said:
Sal,
Some really nice JavaScript. I really love to see stuff like this done with GA.
Would you mind if re-use your export logic (with credit)?
Thanks,
John
Sal said:
John,
Thanks for the kind comment. Feel free to reuse it at your leisure.
-Sal
Avinash Kaushik said:
Awesome enhancement!
I am also afflicted with the same disease as Zach, and now I have a easy cure!
Absolutely love it.
Thanks,
Avinash.
Paul Irish said:
Just took a look at the code to scrape the new date without changing the URL...
var DI = new unsafeWindow.DateInputView;
var startdate = DI.parseDate(DI.primaryBeginField.value)
var enddate = DI.parseDate(DI.primaryEndField.value)
I didn't test this within the context of the script, but it hands back some nice Date objects that you can play with... hopefully it simplifies things for you.
:)
Sal said:
Thanks Paul!
I added some increased date functionality built upon your suggestion.
Al said:
Great tool, nice features!
Thank you.
Al
Tim Leighton-Boyce said:
This is extremely useful, thank you. This certainly helps gain some clearer insight by cutting through the usual suspects and highlighting the items of interest.
Rich said:
This is so cool - thanks to Avinash for pointing it out and of course the juice team for building this functionality!
Matthew said:
I'm not a programmer but like the Greasemonkey script. If I wanted to change the number of days it looks back to 30 rather than 3, do I just make the following change? "look_back = 30"
Chris Gemignani said:
Matthew,
We've got a new script coming probably tomorrow with a few new features. We'll address customization in that post. It really isn't hard. :-)
Tim said:
Hi,
I read about the script and desperately want to have it. I just couldn't make it work. I installed Greasemonkey, installed the script and restarted the browser. Than I logged into my Google Analytics Account and looked at the referring sites report - no new buttom to click on.
Have I done something wrong? A little more detailed instructions would be helpful as I really want to use that script!
Thanks in advance,
Tim
Dave said:
I installed the script and it looks great! I'm always digging in to see who has sent us new traffic, so thanks! I'd like to make the "look_back" date different as well, but I don't know where to find the script to make that change and save it. Any help on where to find the installed script to edit it?
Josh Chambers said:
Thanks a lot! I'll be writing a blog post about this for sure. Great script.
Neerav said:
thanks for this excellent tool
Is there somewhere I can subscribe to keep up to date with new versions?
Sal Uryasev said:
Matthew/Dave: The new post (linked at the top of the page) should have the details you need.
Tim: It sounds as if you did everything correctly. Is the script visible if you go to Tools=>Greasemonkey=>Manage User Scripts?
Neerav: There really is no great way to subscribe to just this script. I will link in the relevant places if anything changes though.
Neerav said:
Hi Sal
Enabling the "subscribe to comments" plugin could help. That way you can post a comment saying there's a new version and everyone who commented gets that comment as an email
Tim said:
Hi Sal,
thank you so much - I just reinstalled it and now it works! This is really fantastic!
Thanks,
Tim
Nate Sidmore said:
Awesome tool Sal, (thanks to Avinash for the tip).
I did run into a problem with the Firefox pop-up message "Warning: Unresponsive script". However that problem can be solved by lengthening the time allowed for scripts to run. For more details go to http://lifehacker.com/software/firefox/put-off-firefox-15s-unresponsive-script-dialogue-162574.php
However I was bummed when after setting the time allowance to 10 minutes, and clicking the "Who Sent Me Unusual Traffic" button in GA, the script ran for 9 min 38 sec before returning results. Any tips on getting quicker returns?
Chris Gemignani said:
Nate:
Thanks for the encouragement. If you check our "Keyword Trends" Greasemonkey script (linked at the start of this post), we write about how to change the parameters in the script to make things run faster.
Edwin said:
How can I only bring up the report for non-paid keywords? Selecting it and then returning the results, still brings up cpc words as well.
said:
Add a comment