如何将我的 Google Analytics(分析)自动化仪表板中的批量数据分成逐月数据
Posted
技术标签:
【中文标题】如何将我的 Google Analytics(分析)自动化仪表板中的批量数据分成逐月数据【英文标题】:How do I separate bulk data in my Google Analytics automated dashboard into month by month data 【发布时间】:2014-08-13 17:42:06 【问题描述】:您好,我一直在研究谷歌分析仪表板,但很难按不同月份分隔数据。我拥有的脚本将批量日期从开始日期拉到结束日期,我想逐月分开。下面是脚本。提前致谢!
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());
【问题讨论】:
【参考方案1】:可能最简单的解决方案是将ga:month
、ga:yearMonth
或ga:nthMonth
添加到维度列表并处理生成的数据。有关可用的时间粒度维度,请参阅 https://developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&group=time。
【讨论】:
以上是关于如何将我的 Google Analytics(分析)自动化仪表板中的批量数据分成逐月数据的主要内容,如果未能解决你的问题,请参考以下文章
我们可以将 Google Analytics(分析)数据转移到其他帐户吗?
Google Analytics for Firebase:如何分析事件 [关闭]
通过将 BigQuery 链接到 Google Analytics 来回填数据是不是需要付费?