Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asherrard/3570e7d123457199c97f to your computer and use it in GitHub Desktop.
Save asherrard/3570e7d123457199c97f to your computer and use it in GitHub Desktop.
Create a dynamic dated bookmarklet or bookmark for viewing google analytics data and selected report for the last 14 or (x) number of days. After getting tired of having to change the date in google analytics I wrote this little bit of js to dynamically set the date for you when you open the bookmark.
javascript:(function() {
var daysBack = 14;
var report = "trafficsources-overview";
var id = "YOUR GOOGLE ANALYTICS REPORT ID";
var today = new Date();
var from = new Date(new Date().setDate(new Date().getDate()-daysBack));
from = from.toISOString().slice(0, 10).replace(/-/g, '');
today = today.toISOString().slice(0, 10).replace(/-/g, '');
var url = "https://www.google.com/analytics/web/#report/"+ report +"/"+ id +"/%3F_u.date00%3D"+ from + "%26_u.date01%3D" + today;
location.assign(url);
})();
//set the variables
//how many days to go back
//https://www.google.com/analytics/web/#report/trafficsources-overview/a00000000000000000b00000000/%3F_u.date01%3D20150316/
//copy the report url you'd like to view ^^ HERE ^^
//copy your analytics id, the next part of the url after the report ^^ ID HERE ^^
//CMD + SHIFT+ O to open chrome bookmark manager
//create a new bookmark
//copy and paste in the uncommented lines above as the URL
//PROFIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment