Skip to content

Commit 471fdb4

Browse files
committed
Update "google/analytics-data"and support Laravel 13
1 parent 16f7b86 commit 471fdb4

8 files changed

Lines changed: 158 additions & 131 deletions

File tree

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
],
1818
"require": {
1919
"php": "^8.1",
20-
"google/analytics-data": "^0.9.4",
21-
"illuminate/contracts": "^9.0|^10.0|^11.0|^12.0",
20+
"google/analytics-data": "^0.23.3",
21+
"illuminate/contracts": "^9.0|^10.0|^11.0|^12.0|^13.0",
2222
"spatie/laravel-package-tools": "^1.14.0"
2323
},
2424
"require-dev": {
25+
"larastan/larastan": "^3.0",
2526
"laravel/pint": "^1.0",
2627
"nunomaduro/collision": "^6.1|^7.0|^8.0",
27-
"nunomaduro/larastan": "^2.0.1",
2828
"orchestra/testbench": "^8.0|^9.0",
2929
"pestphp/pest": "^1.21|^2.34",
3030
"pestphp/pest-plugin-laravel": "^1.1|^2.3",
3131
"phpstan/extension-installer": "^1.1",
32-
"phpstan/phpstan-deprecation-rules": "^1.0",
33-
"phpstan/phpstan-phpunit": "^1.0",
32+
"phpstan/phpstan-deprecation-rules": "^2.0",
33+
"phpstan/phpstan-phpunit": "^2.0",
3434
"phpunit/phpunit": "^9.6|^10.0",
35-
"rector/rector": "^0.19.2|^1.0"
35+
"rector/rector": "^2.4"
3636
},
3737
"autoload": {
3838
"psr-4": {

src/Analytics.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
use Backstage\Analytics\Traits\Analytics\UsersAnalytics;
1212
use Backstage\Analytics\Traits\Analytics\ViewsAnalytics;
1313
use Backstage\Analytics\Traits\ResponseFormatterTrait;
14-
use Google\Analytics\Data\V1beta\BetaAnalyticsDataClient;
14+
use Google\Analytics\Data\V1beta\Client\BetaAnalyticsDataClient;
15+
use Google\Analytics\Data\V1beta\RunRealtimeReportRequest;
16+
use Google\Analytics\Data\V1beta\RunReportRequest;
17+
use Google\ApiCore\ApiException;
18+
use Google\ApiCore\ValidationException;
1519

1620
class Analytics
1721
{
@@ -61,13 +65,20 @@ public function getPropertyId(): ?int
6165
return $this->propertyId;
6266
}
6367

68+
/**
69+
* @throws ValidationException
70+
*/
6471
public function getClient(): BetaAnalyticsDataClient
6572
{
6673
return new BetaAnalyticsDataClient([
6774
'credentials' => $this->getCredentials(),
6875
]);
6976
}
7077

78+
/**
79+
* @throws ValidationException
80+
* @throws ApiException
81+
*/
7182
public function getReport(GoogleAnalyticsService $googleAnalytics): AnalyticsResponse
7283
{
7384
$client = $this->getClient();
@@ -87,11 +98,15 @@ public function getReport(GoogleAnalyticsService $googleAnalytics): AnalyticsRes
8798
'keepEmptyRows' => $googleAnalytics->keepEmptyRows,
8899
];
89100

90-
$response = $client->runReport($parameters);
101+
$response = $client->runReport(new RunReportRequest($parameters));
91102

92103
return $this->formatResponse($response);
93104
}
94105

106+
/**
107+
* @throws ValidationException
108+
* @throws ApiException
109+
*/
95110
public function getRealtimeReport(GoogleAnalyticsService $googleAnalytics): AnalyticsResponse
96111
{
97112
$client = $this->getClient();
@@ -111,7 +126,7 @@ public function getRealtimeReport(GoogleAnalyticsService $googleAnalytics): Anal
111126
'keepEmptyRows' => $googleAnalytics->keepEmptyRows,
112127
];
113128

114-
$response = $client->runRealtimeReport($parameters);
129+
$response = $client->runRealtimeReport(new RunRealtimeReportRequest($parameters));
115130

116131
return $this->formatResponse($response);
117132
}

src/Traits/Analytics/DemographicAnalytics.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
use Backstage\Analytics\Enums\Direction;
66
use Backstage\Analytics\Period;
7+
use Google\ApiCore\ApiException;
8+
use Google\ApiCore\ValidationException;
79

810
trait DemographicAnalytics
911
{
1012
/**
11-
* @throws \Google\ApiCore\ApiException
12-
* @throws \Google\ApiCore\ValidationException
13+
* @throws ApiException
14+
* @throws ValidationException
1315
*/
1416
public function topUsersByLanguage(Period $period, int $limit = 10): array
1517
{
@@ -25,8 +27,8 @@ public function topUsersByLanguage(Period $period, int $limit = 10): array
2527
}
2628

2729
/**
28-
* @throws \Google\ApiCore\ApiException
29-
* @throws \Google\ApiCore\ValidationException
30+
* @throws ApiException
31+
* @throws ValidationException
3032
*/
3133
public function totalUsersByLanguage(Period $period): array
3234
{
@@ -40,8 +42,8 @@ public function totalUsersByLanguage(Period $period): array
4042
}
4143

4244
/**
43-
* @throws \Google\ApiCore\ApiException
44-
* @throws \Google\ApiCore\ValidationException
45+
* @throws ApiException
46+
* @throws ValidationException
4547
*/
4648
public function topUsersByCountry(Period $period, int $limit = 10): array
4749
{
@@ -57,8 +59,8 @@ public function topUsersByCountry(Period $period, int $limit = 10): array
5759
}
5860

5961
/**
60-
* @throws \Google\ApiCore\ApiException
61-
* @throws \Google\ApiCore\ValidationException
62+
* @throws ApiException
63+
* @throws ValidationException
6264
*/
6365
public function totalUsersByCountry(Period $period): array
6466
{
@@ -72,8 +74,8 @@ public function totalUsersByCountry(Period $period): array
7274
}
7375

7476
/**
75-
* @throws \Google\ApiCore\ApiException
76-
* @throws \Google\ApiCore\ValidationException
77+
* @throws ApiException
78+
* @throws ValidationException
7779
*/
7880
public function topUsersByCity(Period $period, int $limit = 10): array
7981
{
@@ -89,8 +91,8 @@ public function topUsersByCity(Period $period, int $limit = 10): array
8991
}
9092

9193
/**
92-
* @throws \Google\ApiCore\ApiException
93-
* @throws \Google\ApiCore\ValidationException
94+
* @throws ApiException
95+
* @throws ValidationException
9496
*/
9597
public function totalUsersByCity(Period $period): array
9698
{
@@ -104,8 +106,8 @@ public function totalUsersByCity(Period $period): array
104106
}
105107

106108
/**
107-
* @throws \Google\ApiCore\ApiException
108-
* @throws \Google\ApiCore\ValidationException
109+
* @throws ApiException
110+
* @throws ValidationException
109111
*/
110112
public function totalUsersByGender(Period $period): array
111113
{
@@ -120,8 +122,8 @@ public function totalUsersByGender(Period $period): array
120122
}
121123

122124
/**
123-
* @throws \Google\ApiCore\ApiException
124-
* @throws \Google\ApiCore\ValidationException
125+
* @throws ApiException
126+
* @throws ValidationException
125127
*/
126128
public function totalUsersByAge(Period $period): array
127129
{

0 commit comments

Comments
 (0)