Unable to retrieve Audience data from Google Analytics Core Reporting API

Asked 1 years ago, Updated 1 years ago, 108 views

It's just as the subject says.
The language is developed by Javascript.
The code looks like the following

gapi.client.analytics.data.ga.get({
        'ids': 'ga:' + profileId,
        'start-date': $(".start_date input").val(),
        'end-date': $(".end_date input").val(),
        'dimensions': 'ga:userGender',
        'metrics': 'ga:sessions'
    })
        .then(function(response){
            setTimeout(function(){
                var formattedJson=JSON.stringify(response.result, null, 2);
                $('#query-output').html(formattedJson);
                generateTableDataForPage13(response.result["rows"], ".page13-table", sessionCount);
            }, 2000);
        })
        .then(null, function(err){
            // Log any errors.
            console.log(err);
            }
        });

If you run it, it will work until you get the result set.

{
"kind": "analytics#gaData",
"id": "****",
"query": {
"start-date": "2016-08-01",
"end-date": "2016-08-31",
"ids": "ga:****",
"dimensions": "ga:userGender",
"metrics": [
"ga:sessions"
],
"start-index": 1,
"max-results"—1000
},
"itemsPerPage": 1000,
"totalResults": 0,
"selfLink": "https://www.googleapis.com/analytics/v3/data/ga?ids=ga:****&dimensions=ga:userGender&metrics=ga:sessions&start-date=2016-08-01&end-date=2016-08-31",
"profileInfo": {
"profileId": "****",
"accountId": "****",
"webPropertyId": "UA-****-1",
"internalWebPropertyId": "****",
"profileName": "****",
"tableId": "ga:****"
},
"containsSampledData": false,
"columnHeaders":[
{
"name": "ga:userGender",
"columnType": "DIMENSION",
"dataType": "STRING"
},
{
"name": "ga:sessions",
"columnType": "METRIC",
"dataType": "INTEGER"
}
],
"totalsForAllResults": {
"ga:sessions": "0"
}
}

It looks like , but "totalsForAllResults" will be zero.

I thought it might be because "Enable user distribution and interest category reports" was disabled for the GA account being retrieved, but the results were the same when I tried accounts with "User Attributes and Interest Category Reports" enabled.

By the way, I have been able to retrieve data other than Audience without any problems.

Now, how can I get data related to Audience, such as data by gender ratio and age...

Thank you for your cooperation.

google-analytics-api

2022-09-30 21:18

1 Answers

Do you see any Audience-related information (gender, age, etc.) when you look at the report for the account in question on the Web UI?
If you haven't seen it, you might have a configuration problem or you don't have enough traffic to show your gender and age in your report.


2022-09-30 21:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.