md jakaria
md jakaria

Reputation: 75

How to extract google analytics dimensions and metrics with python?

I was going to extract data from google analytics with Python and google analytics report api v4, in the middle I need the Google analytics Dimensions and matrix there for a specific purpose(so that I can give user to select for which dimensions and matrix he need data). Also the Google analytics Dimensions and matrix has some valid combinations too. So is there any available REST API or library for that to collect all the dimensions and matrix from google analytics? (Acknowledge: There exists Python library for Service account but there is no library for web with python). I am done with authentication part with auth2. Now I need those available dimensions and matrix for the next progress. References: 1.https://ga-dev-tools.web.app/dimensions-metrics-explorer/ 2.https://developers.google.com/analytics/devguides/reporting/core/v4

Upvotes: 1

Views: 614

Answers (1)

md jakaria
md jakaria

Reputation: 75

Yes, finally It helped me---

  1. https://developers.google.com/analytics/devguides/reporting/metadata/v3/reference/metadata/columns/list
  2. https://sodocumentation.net/google-analytics-api/topic/7297/metadata-api

sample code:

    def get_objects(self):
        report_type = 'ga'
        access_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
        data_api_url = f'https://www.googleapis.com/analytics/v3/metadata/{report_type}/columns?access_token={access_token}'
        print("data api_____", data_api_url)
        response_api = requests.get(data_api_url)
        data = data_api_url.text
        print("________RESPONSE__________", data)
        parse_json = json.loads(data)
        return parse_json

Upvotes: 1

Related Questions