Google Analytics API - Are multiple queries possib

2019-06-14 13:36发布

问题:

I would like to generate an API call that looks as follows:

var dataChart5 = new gapi.analytics.googleCharts.DataChart({
    query:
    [
        {
        metrics: 'ga:totalEvents',
        dimensions: 'ga:date',
        'start-date': beginDate,
        'end-date': endDate,
        filters: 'ga:eventAction==Search;ga:eventCategory==Company'
        },
        {
        metrics: 'ga:totalEvents',
        dimensions: 'ga:date',
        'start-date': beginDate,
        'end-date': endDate,
        filters: 'ga:eventAction==Search;ga:eventCategory==Accommodation'
        }
    ],
    chart: {
        container: 'chart5-container',
        type: 'LINE',
        options: {
            width: '100%'
        }
    }
});

You'll notice there are two queries being generated for the chart. When I execute this, nothing is rendered. This tells me either the syntax is wrong or what I'm trying to do isn't supported. Is something like this possible?

回答1:

No, what you're asking is not possible with the Embed API. If you check the documentation for the DataChart component you'll see the query option takes an Object not an Array.

To do what you want, you'd have to make two queries using the Data component and then render the chart yourself.