// Matomo Reporting API Wrapper
// API Reference: https://developer.matomo.org/api-reference/reporting-api
// Matomo Reporting API Wrapper
// API Reference: https://developer.matomo.org/api-reference/reporting-api
const PERIOD_DAY = 'day';
const PERIOD_WEEK = 'week';
const PERIOD_MONTH = 'month';
const PERIOD_DAY = 'day';
const PERIOD_WEEK = 'week';
const PERIOD_MONTH = 'month';
$date = self::DATE_YESTERDAY,
$period = self::PERIOD_DAY,
$format = self::FORMAT_JSON
$date = self::DATE_YESTERDAY,
$period = self::PERIOD_DAY,
$format = self::FORMAT_JSON
- public function createSite($name, $url, $search = true, $ecommerce = false) {
+ public function createSite($name, $url, $search = true, $ecommerce = false)
+ {
$res = $this->apiCall('SitesManager.addSite', ['siteName' => $name, 'urls' => $url, 'ecommerce' => $ecommerce, 'siteSearch' => $search]);
return $res['value'] ?? null;
}
$res = $this->apiCall('SitesManager.addSite', ['siteName' => $name, 'urls' => $url, 'ecommerce' => $ecommerce, 'siteSearch' => $search]);
return $res['value'] ?? null;
}
- public function createSiteIfNotExistsOrReturnId($name, $url, $search = true, $ecommerce = false) {
+ public function createSiteIfNotExistsOrReturnId($name, $url, $search = true, $ecommerce = false)
+ {
$id = $this->getSiteIdByURL($url);
if (null === $id) {
return $this->createSite($name, $url, $search, $ecommerce);
$id = $this->getSiteIdByURL($url);
if (null === $id) {
return $this->createSite($name, $url, $search, $ecommerce);
$res = $this->apiCall('SitesManager.getSitesIdFromSiteUrl', ['url' => $url]);
return $res[0]['idsite'] ?? null;
}
$res = $this->apiCall('SitesManager.getSitesIdFromSiteUrl', ['url' => $url]);
return $res[0]['idsite'] ?? null;
}
// Note: Passing the parameter 'expanded' => 1 will include the sub-table data
return $this->apiCall('Events.getCategory', $params + ['secondaryDimension' => 'eventName', 'expanded' => 0]);
}
// Note: Passing the parameter 'expanded' => 1 will include the sub-table data
return $this->apiCall('Events.getCategory', $params + ['secondaryDimension' => 'eventName', 'expanded' => 0]);
}
return $this->apiCall('VisitsSummary.get', $params);
}
/**
* @throws \Exception|RequestException
*/
return $this->apiCall('VisitsSummary.get', $params);
}
/**
* @throws \Exception|RequestException
*/
$default = [
'token_auth' => $this->getToken(),
'idSite' => $this->getSiteId(),
$default = [
'token_auth' => $this->getToken(),
'idSite' => $this->getSiteId(),
$options = array_merge($defaultOptions, $options);
$cacheKey = 'matomo_api_call' . hash('sha256', print_r($options, true));
return Cache::remember($cacheKey, $this->getCacheDuration(), function () use ($options, $method) {
$options = array_merge($defaultOptions, $options);
$cacheKey = 'matomo_api_call' . hash('sha256', print_r($options, true));
return Cache::remember($cacheKey, $this->getCacheDuration(), function () use ($options, $method) {
- try {
- $response = $this->client->get('/', $options);
- } catch (RequestException $e) {
- // Just return the error instead of the full message because it contains the URL, which reveals the auth token.
- throw new \Exception("Error: API call for method '{$method}' failed. {$e->getHandlerContext()['error']}");
- }
+ $response = $this->client->get('/', $options);