Google Analytics Date Range – Analytics Today

Google Analytic's default date range is one month. As of this writing, there isn't a way to change it. When tracking the visitors of multiple websites, it is often nice to be able to see the activity of the current day. In order to change the date range, you have to use the Flash based calendar on the right hand side of the page. The calendar sends a request back to Google servers to fetch the information for the date range that you chose. Although nice to use, it can be time consuming and tedious.

Analytics Calendar

The other way to request a date range is to pass a date parameter in the URL:

Example:
https: //google.com....dashboard?...&pdr=20080109-20080109

parameter: pdr

value: 20080109-20080109 (YearMonthDay-YearMonthDay)

Greasemonkey is a Firefox Add-on that allows customized JavaScript to be added to any web page that you visit.

I've written a user script called Analytics Today that sets your Analytics date range to the current day instead of the previous month. You can still obviously change the range just as you do now. Please feel free to try it out. I've included it, along with source code, below!

-

Download it here -> AnalyticsToday.user.js - v0.1.3 (10-21-08)

-

Source Code:

// ==UserScript==
// @name          Analytics Today - v0.1.3
// @namespace     blog.dansnetwork.com
// @description   Sets Google Analytic's default date range to today.

// @include       https://www.google.com/analytics/reporting*

// @exclude
// ==/UserScript==

var url = window.location.href;
var urlParam = "&pdr=";

var today = new Date();
var day = today.getDate().toString();
var month = (today.getMonth() + 1).toString();
var year = today.getFullYear().toString();
var todaysRange;

if(day < 10)
day = '0' + day;
if(month < 10)
month = '0' + month;

var todaysRange = year + month + day + '-' + year + month + day;

if(url.indexOf(urlParam) < 0)
window.location.href += '&pdr=' + todaysRange;

Tags: , , ,

  • This was exactly what I was looking for to track my new blog, http://greasypc.blogspot.com, and my other sites. I feel like I’ve wasted so much time and worn out my wrist having to constantly change the date range.

  • Perfect! Thanks for sharing this clever tool.

  • Dan

    It appears as if Google has modified their URL slightly. Applying Analytics Today to:

    https://www.google.com/analytics/reporting*

    instead of

    https://www.google.com/analytics/reporting/dashboard*

    should do the trick.

    (Tools -> Greasemonkey -> Manage User Scripts -> Click on Analytics Today in the left column -> Edit the URL in the Included Pages section)

    **The download and source code have now been modified

  • Dan

    The bug has been fixed!

    ** The userscript file and source code have now been updated

  • Hey, love the user script!

    I’m making a firefox extension to compile a bunch of GA user scripts together and was wondering if I could get permission from you to add this script to the extension?

    Let me know,
    Thanks,
    Erik Vold

  • Cole

    How could this script be modified to show YESTERDAY instead of TODAY?

  • Dan

    @Cole

    After line 14 (var today = new Date();) add the following line:

    today.setDate(today.getDate()-1);

    to turn Analytics Today into Analytics Yesterday!

  • Brad

    I hacked a few lines onto this to make it show the previous 3 calendar months prior to today. Seems to work but I didn’t test the year subtraction bit strenuously.

    var url = window.location.href;
    var urlParam = “&pdr=”;

    var today = new Date();
    var day = today.getDate().toString();
    var month = (today.getMonth() + 1).toString();
    var year = today.getFullYear().toString();
    var start_year = today.getFullYear().toString();
    var start_month = (today.getMonth() – 2).toString();
    var todaysRange;

    if(day < 10)
    day = '0' + day;

    if(month < 10)
    month = '0' + month;

    if(start_month < 1){
    start_month = start_month + 12;
    start_year = start_year – 1;}

    if(start_month < 10)
    start_month = '0' + start_month;

    var todaysRange = start_year + start_month + day + '-' + year + month + day;

    if(url.indexOf(urlParam) < 0)
    window.location.href += '&pdr=' + todaysRange;