Skip to content

Instantly share code, notes, and snippets.

@Reedyn
Last active January 3, 2016 23:49
Show Gist options
  • Save Reedyn/8537117 to your computer and use it in GitHub Desktop.
Save Reedyn/8537117 to your computer and use it in GitHub Desktop.
JavaScript for opening Google Analytics with the last 7 days selected (not including today)
javascript: (function () {
var pages = {
dashboard: "#dashboard/eChzdEEBTFKu_c0u-nsdTg",
visitors: "#report/visitors-overview",
location: "#report/visitors-geo/",
};
var googleAnalytics = "a28736903w54575155p55522219";
var theDate = new Date();
var theYear = new String(theDate.getFullYear());
var theMonth = new String(theDate.getMonth() + 1);
var theDate = new String(theDate.getDate());
if (theMonth < 10) theMonth = "0" + theMonth;
if (theDate < 10) theDate = "0" + theDate;
var today = theYear + theMonth + theDate - 1;
var last_week = (theYear + theMonth + theDate) - 8;
var google_url = "https://www.google.com/analytics/web/" + pages["dashboard"] + "/" + googleAnalytics + "/" + "%3F_u.date00%3D" + last_week + "%26_u.date01%3D" + today + "/";
window.open(google_url, "new_window");
})();

Instructions

  1. Change the variable googleAnalytics value to your preferred analytics profile.
  2. copy the entire script and put it in a new bookmark
  3. ????
  4. PROFIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment