As you can see here, Netlify Analytics only spans the past 30 days:
This could easily be solved if we could download the data and retain it ourselves. However, there is no way in the Netlify Analytics UI to download the data.
Still on the Netlify Analytics page, let’s fire up the Firefox developer tools and take a look at the network tab:
Let’s take a look at the pageviews request:
By viewing the network requests, we can see the data we want is just raw JSON. We could just download this manually, but that’s going to get old fast. We want to automate this.
First, you will need to generate a “personal access token”. Checkout the Netlify docs for the details.
In short, go to: Netlify → User Settings → Applications → Personal access tokens → New access token. Or click here if you’re already logged in to Netlify.
Second, you will need your site ID, which is a UUID that identifies your site. It can be found in the Netlify UI under “Site settings”.
Using curl to download Netlify Analytics pageviews §
With our token and site ID, now we can run curl to download the pageviews JSON data. Replace <TOKEN> with your personal access token, and <SITE_ID> with the site ID:
In pageviews.json we can see the raw data:
Note that you will need to adjust the to and from timestamp. They are both unix timestamps in milliseconds, not seconds (i.e. unix time * 1000). The value of from should be smaller than to. The maximum range is 30 days.
Using Python to download Netlify Analytics pageviews §
As a quick-and-dirty example, here is the same wrapped up Python script called gather_analytics.py, which automatically calculates the timestamp range: