Last active
November 30, 2017 15:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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