0
我能夠獲取代碼示例,將Google Analytics(分析)中的數據引入Google電子表格中(https://developers.google.com/analytics/solutions/articles/reporting-apps-script)但是,我知道我想要的配置文件的ID,我不需要去通過獲得「第一個配置文件」的開銷。我無法得到它的工作,當我嘗試硬編碼像這樣的ID: Google電子表格中的Google Analytics數據
function getReportDataForProfile() {
var profileId = '12345678';
var tableId = 'ga:12345678';
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:visits,ga:keyword', // Sort by visits 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:visits,ga:pageviews', // Comma seperated list of metrics.
optArgs);
if (results.getRows()) {
return results;
} else {
throw new Error('No profiles found');
}
}
可以提供有關錯誤的一些細節?你確定你有正確的個人資料ID嗎? – Pete