[Update – May 2015] Updated description so that it matches the latest version of the extension on GitHub
[Update – September 2014] I moved the extension project to GitHub, and updated this post accordingly
This is a continuation from my previous post on the same subject.
I promised a Chrome Extension that opens Google Analytics page and sets today’s date as the default date range. You can grab it from GitHub.
To add it to your Chrome:
- download and unzip the extension to some folder
- open your Chrome Extensions page (type
chrome://extensionsin the address bar or press the Settings button (top right) then Tools/Extensions)
- drag and drop the extracted
ganalytics-lastDay.crxfile to the Extensions page, a
Drop to installmessage should appear
- confirm the dialog
To configure the extension, simply open it and follow the instructions (which are the same as in my previous post). If you need to change the Analytics code at any moment, you just go back to the
chrome://extensions page, find the extension and click on (the ridiculously small)
In case you want to play with date ranges, follow the instructions on the GitHub page.
The files you want to play with are
conf.js, which both contain the
getURL() function (duplicated, because using shared JS files in Chrome Extensions turned out to be a bit tricky). That function takes the portion of the URL manually pasted by the user and builds the full Analytics URL with it. As you can see, there’s 2 variables involved:
yesterday. You can change these dates using
Date‘s functions, like this:
var date = new Date(), today = '', oneMonthAgo = ''; today += date.getFullYear(); today += pad2(date.getMonth() + 1); today += pad2(date.getDate()); date.setMonth(date.getMonth() - 1); oneMonthAgo += date.getFullYear(); oneMonthAgo += pad2(date.getMonth() + 1); oneMonthAgo += pad2(date.getDate()); return 'https://www.google.com/analytics/web/?#home/' + code +'/%3F_u.date00%3D' + oneMonthAgo + '%26_u.date01%3D' + today +'/=';
Of course, you may also want to change the default landing page: just go to that page in Google Analytics and change the
?#home part in the URL with whatever you want, like for example
return 'https://www.google.com/analytics/web/?#report/app-visitors-overview/' + code +'/%3F_u.date00%3D' + oneMonthAgo + '%26_u.date01%3D' + today +'/=';
Something that can also be useful for bookmarklets: if you monitor more than one website/app with Analytics, you may want to have a bookmark for each of them (or you may want to have the extension open Analytics for a specific webpage). Each webpage/app has its own
code, so you can either paste the code for the webpage you want the extension to open, or maybe hardcode the correct combination of link and code on different bookmarklets.