5

I use GA Embed API (https://developers.google.com/analytics/devguides/reporting/embed/v1/) to have some charts in my website. I can select date range (start date and end date) for each report.

I want these "Hourly", "Day", "Week", "Month" in my reports charts. I think there must be a parameter for grouping data by time unit, but I can't find it. How can I add option to select time unit in charts?

Example

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
GhitaB
  • 3,275
  • 3
  • 33
  • 62

1 Answers1

5

This is definitely possible with the Embed API, and mostly so out of the box. You just have to explore the various time dimensions and pick which one you want.

To create an Embed API DataChart instance that shows sessions by hour over the past 7 days, you would do something like this:

var dataChart = new gapi.analytics.googleCharts.DataChart({
  'query': {
    'ids': 'ga:XXXX',
    'metrics': 'ga:sessions',
    'dimensions': 'ga:dateHour',
    'start-date': '7daysAgo',
    'end-date': 'yesterday'
  },
  'chart': {
    'container': 'chart-container',
    'type': 'LINE',
    'options': {
      'width': '100%'
    }
  }
});
Philip Walton
  • 29,693
  • 16
  • 60
  • 84