Skip to content

Commit 0ed40a6

Browse files
author
Alex Westergaard
committed
Merge remote-tracking branch 'origin/master' into add-badges-middlebranch
2 parents 478de8e + 7860d05 commit 0ed40a6

25 files changed

+593
-516
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
4+
# Maintain dependencies for GitHub Actions
5+
- package-ecosystem: "github-actions"
6+
directory: "/"
7+
schedule:
8+
interval: "monthly"
9+
day: "monday"
10+
assignees:
11+
- "octocat"

.github/workflows/ci.yml

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13-
validate-mergable:
13+
validate-master:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: "Checkout"
@@ -21,8 +21,8 @@ jobs:
2121
- name: "Validate Mergable"
2222
run: git merge origin/master --no-commit --ff-only
2323

24-
render-php:
25-
needs: validate-mergable
24+
phpunit-composer-latest:
25+
needs: validate-master
2626
runs-on: ${{ matrix.operating-system }}
2727

2828
strategy:
@@ -31,7 +31,6 @@ jobs:
3131
matrix:
3232
operating-system: ["ubuntu-latest"]
3333
php-versions: ["8.0", "8.1", "8.2"]
34-
phpunit-versions: ["latest"]
3534

3635
steps:
3736
- name: "Checkout"
@@ -46,7 +45,6 @@ jobs:
4645
extensions: mbstring, intl
4746
ini-values: post_max_size=256M, max_execution_time=180
4847
coverage: xdebug
49-
tools: phpunit:${{ matrix.phpunit-versions }}
5048

5149
- name: "Composer State"
5250
run: composer update --no-install --with-all-dependencies
@@ -62,8 +60,8 @@ jobs:
6260
uses: actions/cache@v3
6361
with:
6462
path: vendor
65-
key: composer-${{ steps.composer-hash.outputs.hash }}
66-
restore-keys: composer-${{ steps.composer-hash.outputs.hash }}
63+
key: composer-default-${{ steps.composer-hash.outputs.hash }}
64+
restore-keys: composer-default-${{ steps.composer-hash.outputs.hash }}
6765

6866
- name: "Install Dependencies"
6967
if: ${{ steps.cache-composer.outputs.cache-hit != 'true' }}
@@ -92,5 +90,58 @@ jobs:
9290
publish_dir: .github
9391
publish_branch: image-data
9492
github_token: ${{ secrets.GITHUB_TOKEN }}
95-
user_name: 'github-actions[bot]'
96-
user_email: 'github-actions[bot]@users.noreply.github.com'
93+
user_name: "github-actions[bot]"
94+
user_email: "github-actions[bot]@users.noreply.github.com"
95+
96+
phpunit-composer-lowest:
97+
needs: validate-master
98+
runs-on: ${{ matrix.operating-system }}
99+
100+
strategy:
101+
max-parallel: 3
102+
fail-fast: true
103+
matrix:
104+
operating-system: ["ubuntu-latest"]
105+
php-versions: ["8.0", "8.1", "8.2"]
106+
107+
steps:
108+
- name: "Checkout"
109+
uses: actions/checkout@v3
110+
with:
111+
fetch-depth: 0
112+
113+
- name: "Setup PHP"
114+
uses: shivammathur/setup-php@v2
115+
with:
116+
php-version: ${{ matrix.php-versions }}
117+
extensions: mbstring, intl
118+
ini-values: post_max_size=256M, max_execution_time=180
119+
coverage: xdebug
120+
121+
- name: "Composer State"
122+
run: composer update --prefer-lowest --no-install --with-all-dependencies
123+
124+
- name: "Composer Name Hash"
125+
id: composer-hash
126+
uses: KEINOS/gh-action-hash-for-cache@main
127+
with:
128+
path: ./composer.lock
129+
130+
- name: "Caching"
131+
id: cache-composer
132+
uses: actions/cache@v3
133+
with:
134+
path: vendor
135+
key: composer-lowest-${{ steps.composer-hash.outputs.hash }}
136+
restore-keys: composer-lowest-${{ steps.composer-hash.outputs.hash }}
137+
138+
- name: "Install Dependencies"
139+
if: ${{ steps.cache-composer.outputs.cache-hit != 'true' }}
140+
run: composer install
141+
142+
- name: "Linux: Restore Vendor Executable"
143+
if: matrix.operating-system == 'ubuntu-latest'
144+
run: chmod -R 0755 vendor
145+
146+
- name: "PHPUnit"
147+
run: ./vendor/bin/phpunit

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Contribute
22

3-
Thank you for being interesting in this package and wanting to contribute to it.
3+
Thank you for being interested in this package and wanting to contribute to it.
44

55
## Coding
66

77
New code should be introduced to the codebase through issues that specify what you are trying to accomplish.
88
I understand that sometimes you need to add/update/delete code otherwhere in the codebase to achieve this goal.
99
This is why my test always merges master in to ensure that your code stays functional/executable during development.
1010

11-
Please adhere these pointers:
11+
**Please adhere these pointers:**
1212
* Support selected PHP Versions | Ref: [Master/Composer.json](https://github.com/AlexWestergaard/php-ga4/blob/master/composer.json)
1313
* Pass current tests without modification; unless clearly explaining why the change is necessary/required | `> vendor/bin/phpunit`
1414
* PHPUnit tests should confidently ensure that code doesn't fail/error in unwated ways (eg. E_WARNINGS or missing paranthesis)

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
PHP Wrapper for Google Analytics 4 with Server Side Tracking
1+
_Package_
22

3-
[![PHP Version](https://img.shields.io/packagist/php-v/alexwestergaard/php-ga4?color=blue&style=for-the-badge)](https://www.php.net/releases/)
4-
[![Release Size](https://img.shields.io/github/languages/code-size/alexwestergaard/php-ga4?color=blue&style=for-the-badge)](https://github.com/AlexWestergaard/php-ga4/releases/latest)
5-
[![Issues](https://img.shields.io/github/issues-raw/alexwestergaard/php-ga4?color=red&style=for-the-badge)](https://github.com/AlexWestergaard/php-ga4/issues)
6-
[![Tests](https://github.com/AlexWestergaard/php-ga4/actions/workflows/ci.yml/badge.svg)](https://github.com/AlexWestergaard/php-ga4/actions/workflows/ci.yml)
3+
[![Version](https://img.shields.io/packagist/v/alexwestergaard/php-ga4?color=blue&label=stable)](https://github.com/aawnu/php-ga4/releases/latest)
4+
[![License](https://img.shields.io/packagist/l/alexwestergaard/php-ga4?color=blue)](https://github.com/aawnu/php-ga4/blob/master/LICENSE)
5+
[![PHPVersion](https://img.shields.io/packagist/php-v/alexwestergaard/php-ga4?color=blue)](https://www.php.net/releases)
6+
[![Size](https://img.shields.io/github/languages/code-size/aawnu/php-ga4?color=blue)](https://github.com/aawnu/php-ga4/releases/latest)
77
![Code Coverage Badge](https://raw.githubusercontent.com/AlexWestergaard/php-ga4/image-data/coverage.svg)
88

9+
_Development_
10+
11+
[![Version](https://img.shields.io/packagist/v/alexwestergaard/php-ga4?color=red&include_prereleases&label=latest)](https://github.com/aawnu/php-ga4/releases)
12+
[![Issues](https://img.shields.io/github/issues-raw/alexwestergaard/php-ga4?color=red&label=issues)](https://github.com/aawnu/php-ga4/issues)
13+
[![Pulls](https://img.shields.io/github/issues-pr/aawnu/php-ga4?color=red&label=pulls)](https://github.com/aawnu/php-ga4/pulls)
14+
[![Contributors](https://img.shields.io/github/contributors/aawnu/php-ga4?color=red)](https://github.com/aawnu/php-ga4/graphs/contributors)
15+
[![LastCommit](https://img.shields.io/github/last-commit/aawnu/php-ga4/master?color=red)](https://github.com/aawnu/php-ga4/commits)
16+
917
```sh
1018
composer require alexwestergaard/php-ga4
1119
```

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"analytics",
1111
"analytics 4",
1212
"google analytics",
13+
"google analytics 4",
1314
"server side tracking",
1415
"tracking",
1516
"ga4",
@@ -41,11 +42,11 @@
4142
}
4243
},
4344
"require": {
44-
"php": "^8.0.0|^8.1.0|^8.2.0",
45+
"php": ">=8.0,<8.3",
4546
"guzzlehttp/guzzle": "^7.0"
4647
},
4748
"require-dev": {
48-
"phpunit/phpunit": "^9.0|^10.0"
49+
"phpunit/phpunit": "^9.5|^10.0"
4950
},
5051
"minimum-stability": "stable",
5152
"prefer-stable": true

phpunit.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
</include>
1818
<exclude>
1919
<directory suffix=".php">./src/Facade</directory>
20+
<file>./src/GA4Exception.php</file>
2021
</exclude>
2122
<report>
22-
<text outputFile="./.phpunit/coverage.txt" showUncoveredFiles="true"
23-
showOnlySummary="false" />
2423
<clover outputFile="clover.xml"/>
2524
</report>
2625
</coverage>

src/Analytics.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ public function setTimestampMicros(int|float $microOrUnix)
7676
$secondInMicro = 1_000_000;
7777
$offsetLimit = (strtotime('-3 days') + 90) * $secondInMicro;
7878

79-
if (!is_numeric($microOrUnix)) {
80-
throw Ga4Exception::throwMicrotimeInvalidFormat();
81-
}
82-
8379
$formattedTime = floor($microOrUnix * $secondInMicro);
8480
if ($formattedTime < $offsetLimit) {
8581
throw Ga4Exception::throwMicrotimeExpired();
@@ -162,10 +158,10 @@ public function post(): void
162158
}
163159
}
164160
}
161+
}
165162

166-
if (Ga4Exception::hasThrowStack()) {
167-
throw Ga4Exception::getThrowStack();
168-
}
163+
if (Ga4Exception::hasThrowStack()) {
164+
throw Ga4Exception::getThrowStack();
169165
}
170166
}
171167

src/Exception/Ga4Exception.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public static function throwMissingApiSecret()
4242
return new static("Timestamp must be numeric", static::REQUEST_MISSING_API_SECRET);
4343
}
4444

45-
public static function throwMicrotimeInvalidFormat()
46-
{
47-
return new static("Timestamp must be numeric", static::MICROTIME_INVALID_FORMAT);
48-
}
49-
5045
public static function throwMicrotimeExpired()
5146
{
5247
return new static("Timestamp is too old, max 3 days", static::MICROTIME_EXPIRED);

src/Exception/Ga4ItemException.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Exception/Ga4UserPropertyException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public static function throwNameTooLong($name)
1313
{
1414
return new static("Name is too long, max is 24: $name", static::PARAM_TOO_LONG);
1515
}
16+
17+
public static function throwNameMissing()
18+
{
19+
return new static("Name is missing", static::PARAM_MISSING);
20+
}
1621
}

0 commit comments

Comments
 (0)