Search code examples
pythongoogle-analyticsgoogle-analytics-api

How to use custom_dimension in Google Analytics API with gaapi4py library?


I'm using a gaapi4py library to connect to Google Analytics API and it works fine unless I need to put a user_id in dimension list. My request body is following:

request_body = {
    'view_id': '123456789',
    'start_date': '2022-09-11',
    'end_date': '2022-09-14',
    'dimensions': {
        'ga:date',
        'ga:Browser',
        'ga:city',
        'ga:ga_user_id'
    },
    'metrics': {
        'ga:sessions'
    }

This code does not work since last dimension is a custom one and I get an error: "Unknown dimension(s): ga:ga_user_id". Is there any way to handle with custom dimensions in gaapi4py?


Solution

  • This isn't an issue with the library this is how the api works. customer dimensions use ga:dimensionXX where XX is the number of the Custom dimension configured in your system