你没有提到你正在使用什么语言,所以我不知道你可以使用什么样的日期争论界面,但ga:week,ga:year
应该为你提供一年中可以插入的一周并允许你适当地建立日期。在 PHP 中,它可能类似于以下内容:
<?php
// assuming use of the official PHP API for Google services, and
// that you've appropriately initialized the connection, and that
// you've chosen to "$client->setUserObjects(true)", and that you've
// initialized the necessary variables...
$results = $service->data_ga->get($analytics_id, $start_date, $end_date, 'ga:visitors',
array('dimensions' => 'ga:week,ga:nthWeek,ga:year'));
$columns = array();
foreach ($results->columnHeaders as $headidx => $col) {
$columns[$col->name] = $headidx;
}
$traffic = array();
foreach ($results->rows as $idx => $week) {
$date = new DateTime;
$date->setISODate($week[$columns['ga:year']], $week[$columns['ga:week']]);
$traffic[$week[$columns['ga:nthWeek']]] = array('date' => $date, 'visitors' => $week[$columns['ga:visitors']], 'visits' => $week[$columns['ga:visits']], 'pageviews' => $week[$columns['ga:pageviews']]);
}
ksort($traffic);
// $traffic now holds a sorted array of your week by week traffic, with the full
// date in the DateTime object that you can access and format however you please
?>