public function dataExplorerAction()
{
$config = Google\Analytics::getSiteConfig($this->getSite());
$startDate = date("Y-m-d", time() - 86400 * 31);
$endDate = date("Y-m-d");
$metric = "ga:pageviews";
$dimension = "ga:date";
$descending = true;
$limit = 10;
if ($this->getParam("dateFrom") && $this->getParam("dateTo")) {
$startDate = date("Y-m-d", strtotime($this->getParam("dateFrom")));
$endDate = date("Y-m-d", strtotime($this->getParam("dateTo")));
}
if ($this->getParam("dimension")) {
$dimension = $this->getParam("dimension");
}
if ($this->getParam("metric")) {
$metric = $this->getParam("metric");
}
if ($this->getParam("sort")) {
if ($this->getParam("sort") == "asc") {
$descending = false;
}
}
if ($this->getParam("limit")) {
$limit = $this->getParam("limit");
}
if ($filterPath = $this->getFilterPath()) {
$filters[] = "ga:pagePath==" . $filterPath;
}
$opts = ["dimensions" => $dimension, "max-results" => $limit, "sort" => ($descending ? "-" : "") . $metric];
if (!empty($filters)) {
$opts["filters"] = implode(";", $filters);
}
$result = $this->service->data_ga->get("ga:" . $config->profile, $startDate, $endDate, $metric, $opts);
$data = [];
foreach ($result["rows"] as $row) {
$data[] = ["dimension" => $this->formatDimension($dimension, $row[0]), "metric" => (double) $row[1]];
}
$this->_helper->json(["data" => $data]);
}