Search code examples
google-analyticsgoogle-analytics-sdkgoogle-analytics-filters

Extract member info from Google Analytics


I am trying to get all data from my Google Analytics account to a database using their Reporting API v4. In the below request and response, I see a number in the values attribute. I want to get member specific data for that number? For example, value is 65 for dimension 20130101. I want to get data of those 65 members that accessed my website that day (2013-01-01 - the specified dimension in the request). Any data that GA has will suffice. For example, the Gender of those 65 members, their session Id, age etc.

Google Analytics Reporting API Request:

{
"reportRequests": [
    {
        "viewId": "345",
        "dateRanges": [
            {
                "startDate": "daysAgo",
                "endDate": "yesterday"
            }
        ],

        "metrics": [
            {
                "expression": "ga:users"
            }
        ],
        "dimensions":[
            {
              "name":"ga:date"
            }
        ]
    }
]

}

Response

{
"reports": [
    {
        "columnHeader": {
            "dimensions": [
                "ga:date"
            ],
            "metricHeader": {
                "metricHeaderEntries": [
                    {
                        "name": "ga:users",
                        "type": "INTEGER"
                    }
                ]
            }
        },
        "data": {
            "rows": [
                {
                    "dimensions": [
                        "20130101"
                    ],
                    "metrics": [
                        {
                            "values": [
                                "65"
                            ]
                        }
                    ]
                },
                {
                    "dimensions": [
                        "20130102"
                    ],
                    "metrics": [
                        {
                            "values": [
                                "69"
                            ]
                        }
                    ]
                },
                {
                    "dimensions": [
                        "20130103"
                    ],
                    "metrics": [
                        {
                            "values": [
                                "48"
                            ]
                        }
                    ]
                }
            ],
            "totals": [
                {
                    "values": [
                        "490"
                    ]
                }
            ],
            "rowCount": 3,
            "minimums": [
                {
                    "values": [
                        "44"
                    ]
                }
            ],
            "maximums": [
                {
                    "values": [
                        "94"
                    ]
                }
            ],
            "isDataGolden": true
        }
    }
]

}


Solution

  • Google Analytics reporting api don't provide single rows reports, that means that all the data that you can collect is gruped by the dimension.

    In that case, if you want to retrieve al this data in a single report, you have to implement a custom dimension to a users level to identify each one, one option is send the client id (the _ga cookie) to the platform and add that dimension

    Here is a good post of how to implement this https://www.simoahava.com/analytics/add-clientid-to-custom-dimension-gtag-js/

    Have in mind that you can expect others on the reports in that case, due the high cardinality.

    https://support.google.com/analytics/answer/1009671?hl=en

    For premium users you can export the data via BigQuery

    Greetings