Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GA Embed API - select Hourly, Day, Week or Month

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

like image 658
GhitaB Avatar asked Jul 15 '15 14:07

GhitaB


1 Answers

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%'
    }
  }
});
like image 175
Philip Walton Avatar answered Sep 28 '22 11:09

Philip Walton