Dynamic Bookmarks in Google Chrome
I needed a simple way to automatically create date ranges for bookmarks in Google Chrome
As a digital marketer, I’m constantly loading Google Analytics to view site performance metrics. I have very specific requirements when looking at performance data in Analytics:
- I need to compare year-over-year data, ie: 2020 vs. 2019
- I need to make sure I’m comparing the same days of the week, ie: when comparing today vs. last year, I need to compare a Monday vs. Monday, but the dates don’t line up nicely, so you’re comparing the 22nd vs the 23rd last year.
This can be time consuming when using Google Analytics daily. You’ve got to load Analytics, get to the property, select the report and set your date ranges. After frustration set in, I resolved to figure out a method to build dynamic bookmarks in Google Chrome.
What’s the Fix?
Let’s assume that we want to populate a Google Analytics report with the date range for the current day, versus the same day of the week last year. As I’m writing this on Thursday (4/30/2020), the script will compare to the same Thursday last year (5/02/2019).
The first step is to build the current year’s date. For this example we’re going to use today’s date.
Cool, now we’ve got a date that looks like:
Next we need to do something similiar, but move back exactly one year to the same day of the week.
Now we’ve got the current date and comparison date, properly formattted for Analytics. Next let’s build the URL necessary to load the report.
// insert the url of the report you'd like to load // I save custom reports and use those as the base url 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 + "/";
There’s one final piece of the puzzle. We need to wrap all the prior code in a function, then call that function to open a new tab.
Bugs and Things to Note
- As of the time of writing this code, Google Chrome didn’t like any comments. I assume that’s because the bookmark in Google Chrome gets converted to one long string, so any comment in your code comments the rest of the code out.
- For some reason if you open a new tab, then try to load the bookmark, nothing happens. If you try the bookmark in a loaded tab, it’s fine. If you right click and open in a new tab, it’s fine. Anyone have a fix for this?
Get the Code
If you want to see the full code, I’ve created a GitHub Gist.
In part two, I’ll show you how to adopt this code to allow for other date ranges:
- Last seven days
- Month to date
- Last month
Looking for help with car photography or have questions about digital marketing? Fill out the form and I'll get back to you ASAP.