简体   繁体   English

如何将Google Analytics(分析)自动化仪表板中的批量数据逐月划分为数据

[英]How do I separate bulk data in my Google Analytics automated dashboard into month by month data

Hi I've been working on a google analytics dashboard but having a hard time separating data by different months. 嗨,我一直在研究Google Analytics(分析)信息中心,但很难按不同月份分开数据。 The script I have pulls the bulk date from the start to end date and I would like to separate it month by month. 我使用的脚本将批量日期从开始日期拖到结束日期,我想按月分隔它。 Below is the script . 下面是脚本。 Thanks in advance! 提前致谢!

function runDemo() {
  try {

    var firstProfile = getFirstProfile();
    var results = getReportDataForProfile(firstProfile);
    outputToSpreadsheet(results);

  } catch(error) {
    Browser.msgBox(error.message);
  }
}
function getFirstProfile() {
  var accounts = Analytics.Management.Accounts.list();
  if (accounts.getItems()) {
    var firstAccountId = accounts.getItems()[0].getId();

    var webProperties = Analytics.Management.Webproperties.list(firstAccountId);
    if (webProperties.getItems()) {

      var firstWebPropertyId = webProperties.getItems()[0].getId();
      var profiles = Analytics.Management.Profiles.list(firstAccountId, firstWebPropertyId);

      if (profiles.getItems()) {
        var firstProfile = profiles.getItems()[0];
        return firstProfile;

      } else {
        throw new Error('No views (profiles) found.');
      }
    } else {
      throw new Error('No webproperties found.');
    }
  } else {
    throw new Error('No accounts found.');
  }
}
function getReportDataForProfile(firstProfile) {

  var profileId = firstProfile.getId();
  var tableId = 'ga:' + profileId;
  var startDate = getLastNdays(14);   // 2 weeks (a fortnight) ago.
  var endDate = getLastNdays(0);      // Today.

  var optArgs = {
    'dimensions': 'ga:keyword',              // Comma separated list of dimensions.
    'sort': '-ga:sessions,ga:keyword',       // Sort by sessions descending, then keyword.
    'segment': 'dynamic::ga:isMobile==Yes',  // Process only mobile traffic.
    'filters': 'ga:source==google',          // Display only google traffic.
    'start-index': '1',
    'max-results': '250'                     // Display the first 250 results.
  };

  // Make a request to the API.
  var results = Analytics.Data.Ga.get(
      tableId,                    // Table id (format ga:xxxxxx).
      startDate,                  // Start-date (format yyyy-MM-dd).
      endDate,                    // End-date (format yyyy-MM-dd).
      'ga:sessions,ga:pageviews', // Comma seperated list of metrics.
      optArgs);

  if (results.getRows()) {
    return results;

  } else {
    throw new Error('No views (profiles) found');
  }
}

function getLastNdays(nDaysAgo) {
  var today = new Date();
  var before = new Date();
  before.setDate(today.getDate() - nDaysAgo);
  return Utilities.formatDate(before, 'GMT', 'yyyy-MM-dd');
}
function outputToSpreadsheet(results) {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet();

  // Print the headers.
  var headerNames = [];
  for (var i = 0, header; header = results.getColumnHeaders()[i]; ++i) {
    headerNames.push(header.getName());
  }
  sheet.getRange(1, 1, 1, headerNames.length)
      .setValues([headerNames]);

  // Print the rows of data.
  sheet.getRange(2, 1, results.getRows().length, headerNames.length)
      .setValues(results.getRows());
}

Probably the easiest solution is to add ga:month , ga:yearMonth , or ga:nthMonth to your list of dimensions and process the resulting data. 可能最简单的解决方案是将ga:monthga:yearMonthga:nthMonth到维度列表中并处理结果数据。 See https://developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&group=time for available time granularity dimensions. 有关可用的时间粒度维度,请参见https://developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&group=time

暂无
暂无

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

相关问题 Google Analytics _setCustomVar - 我的信息中心中的奇怪数据 - Google Analytics _setCustomVar - strange data in my dashboard 使用Google Analytics(分析)原始数据按月显示图表 - Using Google Analytics raw data to display graph by month 如何在我的网站上嵌入实时Google Analytics(分析)信息中心? - How do I embed a Real-Time Google Analytics Dashboard onto my website? 使用Google Analytics(G)API和Google Visualization - 显示数据,但是从错误的月份开始 - Using Google Analytics (G)API and Google Visualization - Showing data, but from the wrong month 如何基于Month对Json数据进行分组,并使用谷歌图表绘制它 - How to group Json data based on Month and plot it using google chart 如何使用 javascript 从 json 数据中计算一个月每天的项目数 - How do I count the number of items in each day for a month from the json data using javascript 如何使用来自 Facebook 分析的数据显示仪表板 - How to display the dashboard with data from Facebook Analytics 我如何使用谷歌应用程序脚本来修改我从谷歌分析中提取的数据? - How do i use google apps script to modify data that i pull from google analytics? Google Analytics(分析)的数据层何时触发,或者如何测试我的电子商务数据收集脚本? - When is the data layer for Google Analytics fired, or, how can I test my ecommerce data collection script? Google Analytics API JavaScript显示数据而无需登录仪表板上的用户 - Google Analytics API JavaScript show data without login to users on dashboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM