generated from vormkracht10/laravel-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Resource analytics skeleton class * Fix styling * Fix styling * wip * Get top refererers * Fix styling * Get top traffic sources and landingspages * Fix styling * Get top backlinks * Add more period methods * Add realtime analytics * Fix styling --------- Co-authored-by: Baspa <[email protected]>
- Loading branch information
Showing
5 changed files
with
177 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\Analytics\Traits\Analytics; | ||
|
||
use Illuminate\Support\Arr; | ||
use Vormkracht10\Analytics\Period; | ||
|
||
trait RealtimeAnalytics | ||
{ | ||
/** | ||
* @throws \Google\ApiCore\ApiException | ||
* @throws \Google\ApiCore\ValidationException | ||
*/ | ||
public function activeUsers(Period|null $period = null): int | ||
{ | ||
if (is_null($period)) { | ||
$period = Period::minutes(30); | ||
} | ||
|
||
$googleAnalytics = $this->googleAnalytics | ||
->setDateRange($period) | ||
->addMetrics('activeUsers'); | ||
|
||
$result = $this->getReport($googleAnalytics) | ||
->dataTable; | ||
|
||
return (int) Arr::first(Arr::flatten($result)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\Analytics\Traits\Analytics; | ||
|
||
use Vormkracht10\Analytics\Enums\Direction; | ||
use Vormkracht10\Analytics\Period; | ||
|
||
trait ResourceAnalytics | ||
{ | ||
public function getTopReferrers(Period $period, int $limit): array | ||
{ | ||
$googleAnalytics = $this->googleAnalytics | ||
->setDateRange($period) | ||
->addMetrics('sessions') | ||
->addDimensions('pageReferrer') | ||
->orderByMetric('sessions', Direction::DESC) | ||
->limit($limit); | ||
|
||
return $this->getReport($googleAnalytics) | ||
->dataTable; | ||
} | ||
|
||
public function getLandingPages(Period $period, int $limit): array | ||
{ | ||
$googleAnalytics = $this->googleAnalytics | ||
->setDateRange($period) | ||
->addMetrics('sessions') | ||
->addDimensions('landingPage') | ||
->orderByMetric('sessions', Direction::DESC) | ||
->limit($limit); | ||
|
||
return $this->getReport($googleAnalytics) | ||
->dataTable; | ||
} | ||
|
||
public function getTopTrafficSources(Period $period, int $limit): array | ||
{ | ||
$googleAnalytics = $this->googleAnalytics | ||
->setDateRange($period) | ||
->addMetrics('sessions') | ||
->addDimensions('defaultChannelGroup') | ||
->orderByMetric('sessions', Direction::DESC) | ||
->limit($limit); | ||
|
||
return $this->getReport($googleAnalytics) | ||
->dataTable; | ||
} | ||
|
||
public function getTopBacklinks(Period $period, int $limit): array | ||
{ | ||
$googleAnalytics = $this->googleAnalytics | ||
->setDateRange($period) | ||
->addMetrics('sessions') | ||
->addDimensions('sessionSourceMedium') | ||
->orderByMetric('sessions', Direction::DESC) | ||
->limit($limit); | ||
|
||
return $this->getReport($googleAnalytics) | ||
->dataTable; | ||
} | ||
} |