Last active
January 15, 2022 22:34
-
-
Save tusamni/1007292a8566ac5a7f7268626ee5f8ae to your computer and use it in GitHub Desktop.
Dynamic Analytics Bookmarks to load comparison date ranges year over year. This example only works as a comparison for the current date, versus the same day of the week last year.
This file contains hidden or 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 url() { | |
var start_date = new Date(); | |
var start_dd = start_date.getDate(); | |
var start_mm = start_date.getMonth() + 1; | |
var start_yyyy = start_date.getFullYear(); | |
if (start_dd < 10) { start_dd = '0' + start_dd; } | |
if (start_mm < 10) { start_mm = '0' + start_mm; } | |
var start = '' + start_yyyy + start_mm + start_dd; | |
var end_date = new Date(); | |
end_date.setMilliseconds(end_date.getMilliseconds() - 604800000 * 52); | |
var end_dd = end_date.getDate(); | |
var end_mm = end_date.getMonth() + 1; | |
var end_yyyy = end_date.getFullYear(); | |
if (end_dd < 10) { end_dd = '0' + end_dd; } | |
if (end_mm < 10) { end_mm = '0' + end_mm; } | |
var end = '' + end_yyyy + end_mm + end_dd; | |
return 'https://analytics.google.com/analytics/web/#my-reports/**REPORTID*/%3F_u.date00%3D' + start + '%26_u.date01%3D' + start + '%26_u.date10%3D' + end + '%26_u.date11%3D' + end + '/'; | |
}; | |
window.open(url(), "_self"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: you must remove all line breaks and comments from this code before pasting it into a Chrome bookmark.