Export Google Analytics Standard to BigQuery

the 2nd day

Export Google Analytics Standard to BigQuery

I want to export Google Analytics (hereinafter GA) to BigQuery, but GA360 is too expensive! I thought, so I implemented to export to BigQuery via GCS using GA API. I haven't tried it a little yet, so I think it's perfect, but it's not bad because I post it every day ... lol

Rough flow

  1. Get raw data using GA API
  2. Format to csv with python
  3. Export to GCS
  4. Export from GCS to BigQuery

I will introduce it in this flow!

Get raw data using GA API

GA API Quick Start Please refer to the above page for a quick start. Then, will you get the raw data!

Also install the library.

pip install --upgrade google-api-python-client
pip install oauth2client

I will change this sample to my liking. First of all, I will change the date because the amount that can be acquired at one time is small and I want to update it every day.

from datetime import datetime,timedelta
maxSize = 10000
dt_now = datetime.datetime.now()
yesterday = dt_now - timedelta(days=1)
yesterday = yesterday.strftime("%Y-%m-%d")

... and so far, I realized that there was a great article.

If I had read such a wonderful article, it would have been completed sooner ... lol

Easy-to-understand article (God)

How to export raw data to BigQuery even in the free version using Google Analytics API

the end

So, there was an article without having to write it, so this time! I didn't find a single file in the previous article, so I'll list it in Git for those who don't want to copy and paste.

code

day2

Day2 is over!

First of all, my goal is not to be a shaven for 3 days! Lol

Recommended Posts

Export Google Analytics Standard to BigQuery
Regular export of Google Analytics raw data to BigQuery using cloud functions
[Rails] How to introduce Google Analytics [Easy]
Export access data for each user of Google Analytics.
Get a global IP and export it to Google Spreadsheets
Export pandas dataframe to excel
How to use Google Colaboratory
Decorator to silence standard output
Get conversions and revenue with Google Analytics API and report to Slack