One of the major shortcomings of the free version of Google Analytics is the limit GA poses on how much data you can extract. Fortunately, I’ve found a hack and here’s how to bypass the limits and extracting data for a full day at a time.
The past months I’ve been working intensely on how to utilize web analytics data in Google Analytics for ML/AI-purposes. I’ve detailed this in the previous chapters – this one is a part of the enquiry. One of the many challenges I’ve had to deal with in the process is the limit on how much data you can extract from the free version of Google Analytics. This can off course be dealt with by upgrading to Google 360. This is rather costly however…
Python script bypasses the limits
Instead I’ve developed a Python script that bypasses the limits and allows you to extract whatever amount of data from Google Analytics you fancy. That is: the script withdraws data from one day at a time, but within this timeframe I haven’t experienced any restrictions.
What the script does is creating a loop and pulling data out in batches. The script adds the date, hour, and minute dimension and allows us to split data into 60 batches and neatly join the associated data frames together at the end.
The reason for using the minute dimension is that it is convenient to loop through for two reasons. First, it is a dimension were values are stored as numeric. Second, splitting data out by each minute during a day equally distributes the data out in 60 batches.
Conversely, hour of day would not equally distribute data out in 24 batches considering that website traffic often peaks around 4 pm which may cause a violation of the API limit.
Here’s the script:
The full code is available in our whitepaper “Google analytics, ML and AI”. You can download the whitepaper for free right here.
The scripts shown above only show some of the features available with the Python API. Importantly, up to 9 dimensions can be pulled out in one request by adjusting the above scripts further. Furthermore, other filters can also be implemented and predefined by adjusting the script ever so slightly following the guidance provided here.
Good luck extracting data from Google Analytics for whatever purpose you might have.
Bypass the limits of Googles – download whitepaper
This is the fourth blogpost on how to extract data from the free standard version of Google Analytics in order to make it ready for machine learning purposes. All the posts are gathered and edited into a whitepaper, which includes full coding examples. Download the whitepaper for free right here.