Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.3'
coverage: none

- name: Install composer dependencies
Expand Down
19 changes: 8 additions & 11 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.1, 8.2]
laravel: [10.*, 11.*]
php: [8.3, 8.4]
laravel: [11.*, 12.*, 13.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
carbon: ^2.67
- laravel: 11.*
testbench: 9.*
carbon: ^2.72.6
exclude:
- laravel: 11.*
php: 8.1
- laravel: 12.*
testbench: 10.*
- laravel: 13.*
testbench: 11.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand All @@ -47,8 +44,8 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/pest --ci
run: vendor/bin/pest --ci --no-coverage
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
],
"require": {
"php": "^8.1",
"google/analytics-data": "^0.9.4",
"illuminate/contracts": "^9.0|^10.0|^11.0|^12.0",
"google/analytics-data": "^0.23.3",
"illuminate/contracts": "^9.0|^10.0|^11.0|^12.0|^13.0",
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
"larastan/larastan": "^3.0",
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.1|^7.0|^8.0",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^8.0|^9.0",
"pestphp/pest": "^1.21|^2.34",
"pestphp/pest-plugin-laravel": "^1.1|^2.3",
"nunomaduro/collision": "^7.0|^8.0|^9.0",
"orchestra/testbench": "^9.0|^10.0|^11.0",
"pestphp/pest": "^2.34|^3.0|^4.0",
"pestphp/pest-plugin-laravel": "^2.3|^3.0|^4.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.6|^10.0",
"rector/rector": "^0.19.2|^1.0"
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.0|^11.0|^12.0",
"rector/rector": "^2.4"
},
"autoload": {
"psr-4": {
Expand Down
36 changes: 17 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticProperties="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="Backstage Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
Expand Down
21 changes: 18 additions & 3 deletions src/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
use Backstage\Analytics\Traits\Analytics\UsersAnalytics;
use Backstage\Analytics\Traits\Analytics\ViewsAnalytics;
use Backstage\Analytics\Traits\ResponseFormatterTrait;
use Google\Analytics\Data\V1beta\BetaAnalyticsDataClient;
use Google\Analytics\Data\V1beta\Client\BetaAnalyticsDataClient;
use Google\Analytics\Data\V1beta\RunRealtimeReportRequest;
use Google\Analytics\Data\V1beta\RunReportRequest;
use Google\ApiCore\ApiException;
use Google\ApiCore\ValidationException;

class Analytics
{
Expand Down Expand Up @@ -61,13 +65,20 @@ public function getPropertyId(): ?int
return $this->propertyId;
}

/**
* @throws ValidationException
*/
public function getClient(): BetaAnalyticsDataClient
{
return new BetaAnalyticsDataClient([
'credentials' => $this->getCredentials(),
]);
}

/**
* @throws ValidationException
* @throws ApiException
*/
public function getReport(GoogleAnalyticsService $googleAnalytics): AnalyticsResponse
{
$client = $this->getClient();
Expand All @@ -87,11 +98,15 @@ public function getReport(GoogleAnalyticsService $googleAnalytics): AnalyticsRes
'keepEmptyRows' => $googleAnalytics->keepEmptyRows,
];

$response = $client->runReport($parameters);
$response = $client->runReport(new RunReportRequest($parameters));

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

/**
* @throws ValidationException
* @throws ApiException
*/
public function getRealtimeReport(GoogleAnalyticsService $googleAnalytics): AnalyticsResponse
{
$client = $this->getClient();
Expand All @@ -111,7 +126,7 @@ public function getRealtimeReport(GoogleAnalyticsService $googleAnalytics): Anal
'keepEmptyRows' => $googleAnalytics->keepEmptyRows,
];

$response = $client->runRealtimeReport($parameters);
$response = $client->runRealtimeReport(new RunRealtimeReportRequest($parameters));

return $this->formatResponse($response);
}
Expand Down
34 changes: 18 additions & 16 deletions src/Traits/Analytics/DemographicAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

use Backstage\Analytics\Enums\Direction;
use Backstage\Analytics\Period;
use Google\ApiCore\ApiException;
use Google\ApiCore\ValidationException;

trait DemographicAnalytics
{
/**
* @throws \Google\ApiCore\ApiException
* @throws \Google\ApiCore\ValidationException
* @throws ApiException
* @throws ValidationException
*/
public function topUsersByLanguage(Period $period, int $limit = 10): array
{
Expand All @@ -25,8 +27,8 @@ public function topUsersByLanguage(Period $period, int $limit = 10): array
}

/**
* @throws \Google\ApiCore\ApiException
* @throws \Google\ApiCore\ValidationException
* @throws ApiException
* @throws ValidationException
*/
public function totalUsersByLanguage(Period $period): array
{
Expand All @@ -40,8 +42,8 @@ public function totalUsersByLanguage(Period $period): array
}

/**
* @throws \Google\ApiCore\ApiException
* @throws \Google\ApiCore\ValidationException
* @throws ApiException
* @throws ValidationException
*/
public function topUsersByCountry(Period $period, int $limit = 10): array
{
Expand All @@ -57,8 +59,8 @@ public function topUsersByCountry(Period $period, int $limit = 10): array
}

/**
* @throws \Google\ApiCore\ApiException
* @throws \Google\ApiCore\ValidationException
* @throws ApiException
* @throws ValidationException
*/
public function totalUsersByCountry(Period $period): array
{
Expand All @@ -72,8 +74,8 @@ public function totalUsersByCountry(Period $period): array
}

/**
* @throws \Google\ApiCore\ApiException
* @throws \Google\ApiCore\ValidationException
* @throws ApiException
* @throws ValidationException
*/
public function topUsersByCity(Period $period, int $limit = 10): array
{
Expand All @@ -89,8 +91,8 @@ public function topUsersByCity(Period $period, int $limit = 10): array
}

/**
* @throws \Google\ApiCore\ApiException
* @throws \Google\ApiCore\ValidationException
* @throws ApiException
* @throws ValidationException
*/
public function totalUsersByCity(Period $period): array
{
Expand All @@ -104,8 +106,8 @@ public function totalUsersByCity(Period $period): array
}

/**
* @throws \Google\ApiCore\ApiException
* @throws \Google\ApiCore\ValidationException
* @throws ApiException
* @throws ValidationException
*/
public function totalUsersByGender(Period $period): array
{
Expand All @@ -120,8 +122,8 @@ public function totalUsersByGender(Period $period): array
}

/**
* @throws \Google\ApiCore\ApiException
* @throws \Google\ApiCore\ValidationException
* @throws ApiException
* @throws ValidationException
*/
public function totalUsersByAge(Period $period): array
{
Expand Down
Loading