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?
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%'
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With