X7ROOT File Manager
Current Path:
/home/gfecatvj/sites/realesbar/platform/plugins/analytics/src
home
/
gfecatvj
/
sites
/
realesbar
/
platform
/
plugins
/
analytics
/
src
/
📁
..
📄
Analytics.php
(6.02 KB)
📄
AnalyticsClient.php
(2.43 KB)
📄
AnalyticsClientFactory.php
(2.06 KB)
📁
Cache
📁
Exceptions
📁
Facades
📄
GoogleClient.php
(1.84 KB)
📁
Http
📄
Period.php
(2.05 KB)
📄
Plugin.php
(850 B)
📁
Providers
Editing: AnalyticsClient.php
<?php namespace Botble\Analytics; use DateTime; use Google_Service_Analytics; use Illuminate\Contracts\Cache\Repository; use stdClass; class AnalyticsClient { /** * @var Google_Service_Analytics */ protected $service; /** * @var Repository */ protected $cache; /** * @var int */ protected $cacheLifeTimeInMinutes = 0; /** * AnalyticsClient constructor. * @param Google_Service_Analytics $service * @param Repository $cache */ public function __construct(Google_Service_Analytics $service, Repository $cache) { $this->service = $service; $this->cache = $cache; } /** * Set the cache time. * * @param int $cacheLifeTimeInMinutes * @return self */ public function setCacheLifeTimeInMinutes(int $cacheLifeTimeInMinutes) { $this->cacheLifeTimeInMinutes = $cacheLifeTimeInMinutes; return $this; } /** * Query the Google Analytics Service with given parameters. * * @param string $viewId * @param DateTime $startDate * @param DateTime $endDate * @param string $metrics * @param array $others * * @return stdClass|null */ public function performQuery( string $viewId, DateTime $startDate, DateTime $endDate, string $metrics, array $others = [] ) { $cacheName = $this->determineCacheName(func_get_args()); if ($this->cacheLifeTimeInMinutes == 0) { $this->cache->forget($cacheName); } return $this->cache->remember($cacheName, $this->cacheLifeTimeInMinutes, function () use ($viewId, $startDate, $endDate, $metrics, $others) { return $this->service->data_ga->get( 'ga:' . $viewId, $startDate->format('Y-m-d'), $endDate->format('Y-m-d'), $metrics, $others ); }); } /** * @return Google_Service_Analytics */ public function getAnalyticsService(): Google_Service_Analytics { return $this->service; } /** * Determine the cache name for the set of query properties given. * @param array $properties * @return string */ protected function determineCacheName(array $properties): string { return 'analytics.' . md5(serialize($properties)); } }
Upload File
Create Folder