Skip to content

Instantly share code, notes, and snippets.

@tusamni
Last active Jan 15, 2022
Embed
What would you like to do?
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.
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");
@tusamni
Copy link
Author

tusamni commented Dec 16, 2021

NOTE: you must remove all line breaks and comments from this code before pasting it into a Chrome bookmark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment