简体   繁体   English

GA嵌入API - 选择每小时,每天,每周或每月

[英]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. 我使用GA嵌入API( https://developers.google.com/analytics/devguides/reporting/embed/v1/ )在我的网站上添加了一些图表。 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. 使用Embed API绝对可以实现这一点,而且大多数都是开箱即用的。 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: 要创建一个在过去7天内按小时显示会话的Embed API DataChart实例,您可以执行以下操作:

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%'
    }
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM