Connect to Google Analytics
Before executing this Action, please install the "Google API" inside Python by executing inside the windows shell:
pip.exe install --upgrade google-api-python-client
The "pip.exe" executable is usually inside the directory "<root_of_python_dir>/scripts".
To create your JSON file (with your credentials), the procedure is:
1.You need to first use the setup tool (https://console.developers.google.com/start/api?id=analyticsreporting.googleapis.com&credential=client_key), which guides you through creating a project in the Google API Console, enabling the API, and creating credentials.
2.Open the Credentials page (https://console.developers.google.com/apis/credentials): Click Create credentials and select "Service Account Key": select "JSON format" to store your key and download the JSON file.
3.Open you JSON file inside a text file editor and search for the field: "client_email": This should be something like: "email@example.com"
4.Use the email address obtained on point 3 (just here above) to add a user (https://support.google.com/analytics/answer/1009702) to the Google analytics account you want to access via the API. For this Action only Read & Analyze (https://support.google.com/analytics/answer/2884495) permissions are needed for this user.
The above 4-steps procedure (to get your JSON file with your credentials) is also documented here:
Get your "View ID", using the "account explorer":
If you get the following error message:
"User does not have sufficient permissions for this profile.",
...this means that your "View ID" is incorrect.
It's quite easy to change the Python code to:
•change the analyzed period of time (change "dateRanges"): By default, we are looking at the last 30 days.
•extract new DIMENSIONS and new METRICS out of Google Analytics:
All the available DIMENSIONS and METRICS are visible here: https://www.googleapis.com/analytics/v3/metadata/ga/columns?pp=1
(see the comments in the code to know where to change the code)