51 Commits
Author SHA1 Message Date
mathiaspalmqvist 6f0c4ad4a8 Merge pull request 'Drop Laravel 11, add PHP 8.5 and merge CI workflows' (#22) from laravel-12-13-ci into main
CI / PHPStan (push) Successful in 49s
CI / Pest (PHP 8.3, Laravel 12.*, prefer-lowest) (push) Successful in 42s
CI / Pest (PHP 8.3, Laravel 12.*, prefer-stable) (push) Successful in 37s
CI / Pest (PHP 8.4, Laravel 12.*, prefer-lowest) (push) Successful in 41s
CI / Pest (PHP 8.4, Laravel 12.*, prefer-stable) (push) Successful in 46s
CI / Pest (PHP 8.5, Laravel 12.*, prefer-lowest) (push) Successful in 48s
CI / Pest (PHP 8.5, Laravel 12.*, prefer-stable) (push) Successful in 43s
CI / Pest (PHP 8.3, Laravel 13.*, prefer-lowest) (push) Successful in 39s
CI / Pest (PHP 8.3, Laravel 13.*, prefer-stable) (push) Successful in 42s
CI / Pest (PHP 8.4, Laravel 13.*, prefer-lowest) (push) Successful in 39s
CI / Pest (PHP 8.4, Laravel 13.*, prefer-stable) (push) Successful in 45s
CI / Pest (PHP 8.5, Laravel 13.*, prefer-lowest) (push) Successful in 47s
CI / Pest (PHP 8.5, Laravel 13.*, prefer-stable) (push) Successful in 43s
Reviewed-on: #22
2026-11-12 10:07:41 +00:00
mathiaspalmqvist d42263023f Move workflows to .gitea/workflows
dependabot-auto-merge / dependabot (pull_request_target) Skipped
CI / PHPStan (push) Successful in 45s
CI / Pest (PHP 8.3, Laravel 12.*, prefer-stable) (push) Successful in 38s
CI / Pest (PHP 8.4, Laravel 12.*, prefer-lowest) (push) Successful in 41s
CI / Pest (PHP 8.3, Laravel 12.*, prefer-lowest) (push) Successful in 41s
CI / Pest (PHP 8.5, Laravel 12.*, prefer-lowest) (push) Successful in 45s
CI / Pest (PHP 8.3, Laravel 13.*, prefer-lowest) (push) Successful in 44s
CI / Pest (PHP 8.3, Laravel 13.*, prefer-stable) (push) Successful in 42s
CI / Pest (PHP 8.4, Laravel 13.*, prefer-stable) (push) Successful in 41s
CI / Pest (PHP 8.5, Laravel 13.*, prefer-lowest) (push) Successful in 46s
CI / Pest (PHP 8.4, Laravel 12.*, prefer-stable) (push) Successful in 45s
CI / Pest (PHP 8.5, Laravel 12.*, prefer-stable) (push) Successful in 43s
CI / Pest (PHP 8.4, Laravel 13.*, prefer-lowest) (push) Successful in 43s
CI / Pest (PHP 8.5, Laravel 13.*, prefer-stable) (push) Successful in 44s
2026-11-12 10:51:27 +01:00
mathiaspalmqvist 7af348cbb4 Name the test matrix jobs Pest
dependabot-auto-merge / dependabot (pull_request_target) Skipped
CI / PHPStan (push) Successful in 47s
CI / Pest (PHP 8.3, Laravel 12.*, prefer-lowest) (push) Canceled after 0s
CI / Pest (PHP 8.3, Laravel 12.*, prefer-stable) (push) Canceled after 0s
CI / Pest (PHP 8.4, Laravel 12.*, prefer-lowest) (push) Canceled after 0s
CI / Pest (PHP 8.4, Laravel 12.*, prefer-stable) (push) Canceled after 0s
CI / Pest (PHP 8.5, Laravel 12.*, prefer-lowest) (push) Canceled after 0s
CI / Pest (PHP 8.5, Laravel 12.*, prefer-stable) (push) Canceled after 0s
CI / Pest (PHP 8.3, Laravel 13.*, prefer-lowest) (push) Canceled after 0s
CI / Pest (PHP 8.3, Laravel 13.*, prefer-stable) (push) Canceled after 0s
CI / Pest (PHP 8.4, Laravel 13.*, prefer-lowest) (push) Canceled after 0s
CI / Pest (PHP 8.4, Laravel 13.*, prefer-stable) (push) Canceled after 0s
CI / Pest (PHP 8.5, Laravel 13.*, prefer-lowest) (push) Canceled after 0s
CI / Pest (PHP 8.5, Laravel 13.*, prefer-stable) (push) Canceled after 0s
2026-11-12 10:39:56 +01:00
mathiaspalmqvist 6d9206df80 Install PHPStan dependencies without the Composer cache action
dependabot-auto-merge / dependabot (pull_request_target) Skipped
CI / PHPStan (push) Canceled after 0s
CI / P8.3 - L12.* - prefer-lowest (push) Canceled after 0s
CI / P8.3 - L12.* - prefer-stable (push) Canceled after 0s
CI / P8.4 - L12.* - prefer-lowest (push) Canceled after 0s
CI / P8.4 - L12.* - prefer-stable (push) Canceled after 0s
CI / P8.5 - L12.* - prefer-lowest (push) Canceled after 0s
CI / P8.5 - L12.* - prefer-stable (push) Canceled after 0s
CI / P8.3 - L13.* - prefer-lowest (push) Canceled after 0s
CI / P8.3 - L13.* - prefer-stable (push) Canceled after 0s
CI / P8.4 - L13.* - prefer-lowest (push) Canceled after 0s
CI / P8.4 - L13.* - prefer-stable (push) Canceled after 0s
CI / P8.5 - L13.* - prefer-lowest (push) Canceled after 0s
CI / P8.5 - L13.* - prefer-stable (push) Canceled after 0s
The runner cannot reach the Actions cache service, so every restore and
save timed out without ever producing a cache hit.
2026-11-12 10:38:14 +01:00
mathiaspalmqvist ded8967551 Point repository links at the new 559342-9607 owner
dependabot-auto-merge / dependabot (pull_request_target) Skipped
CI / PHPStan (push) Canceled after 0s
CI / P8.3 - L12.* - prefer-lowest (push) Canceled after 0s
CI / P8.3 - L12.* - prefer-stable (push) Canceled after 0s
CI / P8.4 - L12.* - prefer-lowest (push) Canceled after 0s
CI / P8.4 - L12.* - prefer-stable (push) Canceled after 0s
CI / P8.5 - L12.* - prefer-lowest (push) Canceled after 0s
CI / P8.5 - L12.* - prefer-stable (push) Canceled after 0s
CI / P8.3 - L13.* - prefer-lowest (push) Canceled after 0s
CI / P8.3 - L13.* - prefer-stable (push) Canceled after 0s
CI / P8.4 - L13.* - prefer-lowest (push) Canceled after 0s
CI / P8.4 - L13.* - prefer-stable (push) Canceled after 0s
CI / P8.5 - L13.* - prefer-lowest (push) Canceled after 0s
CI / P8.5 - L13.* - prefer-stable (push) Canceled after 0s
2026-11-12 10:27:28 +01:00
mathiaspalmqvist e3a0aa54e9 Drop Laravel 11, add PHP 8.5 and merge CI workflows
dependabot-auto-merge / dependabot (pull_request_target) Skipped
CI / PHPStan (push) Canceled after 0s
CI / P8.3 - L12.* - prefer-lowest (push) Canceled after 0s
CI / P8.3 - L12.* - prefer-stable (push) Canceled after 0s
CI / P8.4 - L12.* - prefer-lowest (push) Canceled after 0s
CI / P8.4 - L12.* - prefer-stable (push) Canceled after 0s
CI / P8.5 - L12.* - prefer-lowest (push) Canceled after 0s
CI / P8.5 - L12.* - prefer-stable (push) Canceled after 0s
CI / P8.3 - L13.* - prefer-lowest (push) Canceled after 0s
CI / P8.3 - L13.* - prefer-stable (push) Canceled after 0s
CI / P8.4 - L13.* - prefer-lowest (push) Canceled after 0s
CI / P8.4 - L13.* - prefer-stable (push) Canceled after 0s
CI / P8.5 - L13.* - prefer-lowest (push) Canceled after 0s
CI / P8.5 - L13.* - prefer-stable (push) Canceled after 0s
- Require Laravel 12 or 13 and drop orchestra/testbench 9
- Add PHP 8.5 to the test matrix
- Merge the test and PHPStan workflows into a single CI workflow,
  running PHPStan before the test matrix
- Add manual dispatch and cancel superseded runs
- Update requirements and badge in README
2026-11-12 10:23:16 +01:00
mathiaspalmqvist 16257e3383 Merge pull request 'Accept text/plain events from the Plausible tracker' (#21) from fix-text-plain-events into main
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
Fix PHP code style issues / php-code-styling (push) Canceled after 0s
PHPStan / phpstan (push) Canceled after 2s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
Reviewed-on: #21
2026-11-12 08:21:32 +00:00
mathiaspalmqvist a97baf5921 Accept text/plain events from the Plausible tracker
dependabot-auto-merge / dependabot (pull_request_target) Skipped
Fix PHP code style issues / php-code-styling (push) Successful in 6s
PHPStan / phpstan (push) Successful in 2m38s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 33s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 1s
The Plausible tracker posts its JSON payload with Content-Type text/plain,
  which Laravel does not parse, so every real event failed validation and
  was redirected instead of being forwarded.

  - Decode the raw body when the request is not JSON
  - Respond with 400 instead of a redirect on invalid non-JSON requests
  - Trim trailing slash from the configured domain when forwarding events
  - Add a 5s timeout and respond with 502 when Plausible is unreachable
2026-11-12 09:18:50 +01:00
mathiaspalmqvist c1338fad8b Merge pull request 'Add support for Laravel 13' (#20) from laravel-13 into main
Fix PHP code style issues / php-code-styling (push) Successful in 6s
PHPStan / phpstan (push) Successful in 3m51s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 34s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 2s
Reviewed-on: Github/laravel-plausible-proxy#20
2026-11-12 07:32:30 +00:00
mathiaspalmqvist f235fa0aaa Merge branch 'main' into laravel-13
dependabot-auto-merge / dependabot (pull_request_target) Skipped
Fix PHP code style issues / php-code-styling (push) Successful in 6s
PHPStan / phpstan (push) Successful in 2m42s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 32s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 2s
2026-11-12 07:32:26 +00:00
mathiaspalmqvist 8e7bff9e61 Add support for Laravel 13
dependabot-auto-merge / dependabot (pull_request_target) Skipped
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 33s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 1s
- Allow illuminate/contracts ^13.0
- Allow orchestra/testbench ^11.0 and Pest 4 (with plugins) for dev
- Add Laravel 13 to the CI test matrix
- Update requirements in README
2026-11-12 08:31:34 +01:00
mathiaspalmqvist 77c0e38f84 Merge pull request 'Support custom Plausible script path' (#19) from issue-14-custom-script-path into main
PHPStan / phpstan (push) Successful in 2m41s
Fix PHP code style issues / php-code-styling (push) Successful in 6s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 32s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 2s
Reviewed-on: Github/laravel-plausible-proxy#19
2026-11-12 07:29:22 +00:00
mathiaspalmqvist 91429ccd22 Merge branch 'main' into issue-14-custom-script-path
dependabot-auto-merge / dependabot (pull_request_target) Skipped
2026-11-12 07:29:12 +00:00
mathiaspalmqvist 513ceb61a0 Support custom Plausible script path
dependabot-auto-merge / dependabot (pull_request_target) Skipped
Fix PHP code style issues / php-code-styling (push) Successful in 6s
PHPStan / phpstan (push) Successful in 2m32s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 34s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 2s
Add a PLAUSIBLE_SCRIPT config option so site-specific scripts
(js/pa-XXXXX.js) and legacy script extensions can be proxied. The
script is still served locally from /js/script.js and the cache key
is derived from the script URL so changing the script takes effect
immediately.

Closes #14
2026-11-12 08:27:43 +01:00
mathiaspalmqvist 711c4eafbc Merge pull request 'Rename package to mattitja/laravel-plausible-proxy (v2.0)' (#18) from rename-to-mattitja into main
PHPStan / phpstan (push) Successful in 2m37s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 33s
Fix PHP code style issues / php-code-styling (push) Successful in 6s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 2s
Reviewed-on: Github/laravel-plausible-proxy#18
2026-11-12 07:25:41 +00:00
mathiaspalmqvist a60e4cbdcf Rename package to mattitja/laravel-plausible-proxy
dependabot-auto-merge / dependabot (pull_request_target) Skipped
PHPStan / phpstan (push) Successful in 2m32s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 34s
Fix PHP code style issues / php-code-styling (push) Successful in 6s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 2s
- Rename Composer package to mattitja/laravel-plausible-proxy and
  namespace to Mattitja\LaravelPlausibleProxy
- Point homepage and links to git.mattitja.se
- Forward only User-Agent and visitor IP (X-Forwarded-For) to Plausible
  instead of all request headers
- Forward all event fields and return Plausible's upstream response
- Accept props as array or JSON string
- Drop Laravel 10, upgrade Larastan to 3 and PHPStan plugins to 2
- Remove broken facade alias and dead autoload paths
- Clean up README, issue template and remove invalid FUNDING.yml
2026-11-12 08:24:45 +01:00
github-actions[bot] 7f8eff628f Merge pull request #13 from MattitjaAB/dependabot/github_actions/dependabot/fetch-metadata-2.5.0
Bump dependabot/fetch-metadata from 2.4.0 to 2.5.0
2026-01-12 03:59:10 +00:00
dependabot[bot] 2196ec5d2d Bump dependabot/fetch-metadata from 2.4.0 to 2.5.0
Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 2.4.0 to 2.5.0.
- [Release notes](https://github.com/dependabot/fetch-metadata/releases)
- [Commits](https://github.com/dependabot/fetch-metadata/compare/v2.4.0...v2.5.0)

---
updated-dependencies:
- dependency-name: dependabot/fetch-metadata
  dependency-version: 2.5.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-12 03:58:59 +00:00
github-actions[bot] 364fbe7b4b Merge pull request #9 from MattitjaAB/dependabot/github_actions/aglipanci/laravel-pint-action-2.6
Bump aglipanci/laravel-pint-action from 2.5 to 2.6
2025-07-28 04:38:19 +00:00
dependabot[bot] 576c9803dc Bump aglipanci/laravel-pint-action from 2.5 to 2.6
Bumps [aglipanci/laravel-pint-action](https://github.com/aglipanci/laravel-pint-action) from 2.5 to 2.6.
- [Release notes](https://github.com/aglipanci/laravel-pint-action/releases)
- [Commits](https://github.com/aglipanci/laravel-pint-action/compare/2.5...2.6)

---
updated-dependencies:
- dependency-name: aglipanci/laravel-pint-action
  dependency-version: '2.6'
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-28 04:38:10 +00:00
mathiaspalmqvist f451d4f0b8 Update CHANGELOG 2025-06-25 19:36:20 +00:00
Mathias fa4784c8ec Merge pull request #8 from MattitjaAB/cleanup
Cleanup
2025-06-25 21:34:33 +02:00
mathiaspalmqvist cd00572702 WIP 2025-06-25 21:33:15 +02:00
mathiaspalmqvist 8c042b27cf WIP 2025-06-25 21:31:35 +02:00
mathiaspalmqvist 4aa046d7a7 Merge branch 'cleanup' of https://github.com/MattitjaAB/laravel-plausible-proxy into cleanup 2025-06-25 21:30:22 +02:00
mathiaspalmqvist 859dcf99be Cleanup 2025-06-25 21:30:16 +02:00
mathiaspalmqvist 2893ed0bc6 Fix styling 2025-06-25 19:27:34 +00:00
mathiaspalmqvist 15e9fcc186 Clean 2025-06-25 21:21:07 +02:00
mathiaspalmqvist 42404cc2cc Cleanup 2025-06-25 21:10:11 +02:00
mathiaspalmqvist b53047a28c Update CHANGELOG 2025-06-16 20:38:09 +00:00
Mathias 5eff0cafe5 Merge pull request #7 from MattitjaAB/6-laravel-12
Added support for L12
2025-06-16 22:32:57 +02:00
mathiaspalmqvist 0e25ead520 Added support for L12 2025-06-16 22:30:57 +02:00
github-actions[bot] 67507d036a Merge pull request #4 from MattitjaAB/dependabot/github_actions/dependabot/fetch-metadata-2.4.0
Bump dependabot/fetch-metadata from 2.3.0 to 2.4.0
2025-05-12 03:49:36 +00:00
dependabot[bot] 0ce7b51eff Bump dependabot/fetch-metadata from 2.3.0 to 2.4.0
Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 2.3.0 to 2.4.0.
- [Release notes](https://github.com/dependabot/fetch-metadata/releases)
- [Commits](https://github.com/dependabot/fetch-metadata/compare/v2.3.0...v2.4.0)

---
updated-dependencies:
- dependency-name: dependabot/fetch-metadata
  dependency-version: 2.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-12 03:49:27 +00:00
github-actions[bot] 891c3d8ff8 Merge pull request #3 from MattitjaAB/dependabot/github_actions/aglipanci/laravel-pint-action-2.5
Bump aglipanci/laravel-pint-action from 2.4 to 2.5
2025-02-03 03:46:55 +00:00
dependabot[bot] e2062499ae Bump aglipanci/laravel-pint-action from 2.4 to 2.5
Bumps [aglipanci/laravel-pint-action](https://github.com/aglipanci/laravel-pint-action) from 2.4 to 2.5.
- [Release notes](https://github.com/aglipanci/laravel-pint-action/releases)
- [Commits](https://github.com/aglipanci/laravel-pint-action/compare/2.4...2.5)

---
updated-dependencies:
- dependency-name: aglipanci/laravel-pint-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-02-03 03:46:39 +00:00
mathiaspalmqvist 1f4bbadab7 Update CHANGELOG 2025-01-31 13:19:59 +00:00
Mathias 9c2ebc5db8 Merge pull request #2 from MattitjaAB/Remove-site
Remove site
2025-01-31 14:16:52 +01:00
mathiaspalmqvist 32721b82cc Fix styling 2025-01-31 13:15:16 +00:00
mathiaspalmqvist 6df45258a6 Update README.md 2025-01-31 14:14:55 +01:00
mathiaspalmqvist 6a358d9d65 Removed site from config file 2025-01-31 14:04:07 +01:00
mathiaspalmqvist 6417d3bd6e Update CHANGELOG 2025-01-31 12:15:00 +00:00
mathiaspalmqvist 3b6afc54f9 Merge branch 'main' of github.com:MattitjaAB/laravel-plausible-proxy 2025-01-31 13:10:42 +01:00
mathiaspalmqvist a2c3ad76c0 Added support for 8.3 2025-01-31 13:10:39 +01:00
mathiaspalmqvist 42debe755e Added support for php 8.3 2025-01-31 13:07:08 +01:00
mathiaspalmqvist 9788f6f895 Update CHANGELOG 2025-01-31 11:39:31 +00:00
Mathias 395b15b80b Merge pull request #1 from MattitjaAB/v1.1
Refactor event forwarding and improve test coverage
2025-01-31 12:36:54 +01:00
mathiaspalmqvist 164c3ab5dd Fix styling 2025-01-31 11:36:31 +00:00
mathiaspalmqvist 26454a9501 Refactor event forwarding and improve test coverage
- Updated event forwarding to include request headers
- Refactored validation to improve error handling
- Fixed issue with missing headers in HTTP request
- Improved test cases for event forwarding and caching
- Ensured proper handling of JSON payloads
- Fixed Plausible API URL configuration in tests
2025-01-31 12:36:07 +01:00
mathiaspalmqvist c3033e1093 Ignore Mac DS_Store files 2025-01-31 12:25:47 +01:00
mathiaspalmqvist f622f3152b Update CHANGELOG 2025-01-30 23:15:03 +00:00
30 changed files with 539 additions and 340 deletions

No files matched your search

+88
View File
@@ -0,0 +1,88 @@
name: CI
on:
push:
paths:
- '**.php'
- '.gitea/workflows/ci.yml'
- 'phpunit.xml.dist'
- 'phpstan.neon.dist'
- 'phpstan-baseline.neon'
- 'composer.json'
- 'composer.lock'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
coverage: none
- name: Install composer dependencies
run: composer install --prefer-dist --no-interaction --no-progress
- name: Run PHPStan
run: vendor/bin/phpstan --error-format=github
pest:
name: Pest (PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}, ${{ matrix.stability }})
needs: phpstan
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
php: ['8.3', '8.4', '8.5']
laravel: ['12.*', '13.*']
stability: [prefer-lowest, prefer-stable]
include:
- laravel: '12.*'
testbench: '10.*'
- laravel: '13.*'
testbench: '11.*'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none
- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require \
"laravel/framework:${{ matrix.laravel }}" \
"orchestra/testbench:${{ matrix.testbench }}" \
"nesbot/carbon:^3.8.4" \
--dev --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: List installed dependencies
run: composer show -D
- name: Execute tests
run: vendor/bin/pest --ci
@@ -14,7 +14,7 @@ jobs:
- name: Dependabot metadata - name: Dependabot metadata
id: metadata id: metadata
uses: dependabot/fetch-metadata@v2.3.0 uses: dependabot/fetch-metadata@v2.5.0
with: with:
github-token: "${{ secrets.GITHUB_TOKEN }}" github-token: "${{ secrets.GITHUB_TOKEN }}"
@@ -20,7 +20,7 @@ jobs:
ref: ${{ github.head_ref }} ref: ${{ github.head_ref }}
- name: Fix PHP code style issues - name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@2.4 uses: aglipanci/laravel-pint-action@2.6
- name: Commit changes - name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5 uses: stefanzweifel/git-auto-commit-action@v5
File renamed without changes.
-1
View File
@@ -1 +0,0 @@
github: Mattitja AB
+5 -8
View File
@@ -1,11 +1,8 @@
blank_issues_enabled: false blank_issues_enabled: false
contact_links: contact_links:
- name: Ask a question - name: Ask a question or request a feature
url: https://github.com/mattitjaab/laravel-plausible-proxy/discussions/new?category=q-a url: https://git.mattitja.se/559342-9607/laravel-plausible-proxy/issues
about: Ask the community for help about: Open an issue in the repository
- name: Request a feature
url: https://github.com/mattitjaab/laravel-plausible-proxy/discussions/new?category=ideas
about: Share ideas for new features
- name: Report a security issue - name: Report a security issue
url: https://github.com/mattitjaab/laravel-plausible-proxy/security/policy url: mailto:hej@mattitja.se
about: Learn how to notify us for sensitive bugs about: Please report security issues privately by email
-28
View File
@@ -1,28 +0,0 @@
name: PHPStan
on:
push:
paths:
- '**.php'
- 'phpstan.neon.dist'
- '.github/workflows/phpstan.yml'
jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none
- name: Install composer dependencies
uses: ramsey/composer-install@v3
- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
-55
View File
@@ -1,55 +0,0 @@
name: run-tests
on:
push:
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.4]
laravel: [11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
carbon: ^2.63
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none
- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.os == 'windows-latest' && '^^^' || '' }}${{ matrix.carbon }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: List Installed Dependencies
run: composer show -D
- name: Execute tests
run: vendor/bin/pest --ci
+4
View File
@@ -30,3 +30,7 @@ phpstan.neon
testbench.yaml testbench.yaml
/docs /docs
/coverage /coverage
# Ignore Mac DS_Store files
.DS_Store
**/.DS_Store
+50
View File
@@ -1,3 +1,53 @@
# Changelog # Changelog
All notable changes to `laravel-plausible-proxy` will be documented in this file. All notable changes to `laravel-plausible-proxy` will be documented in this file.
## v1.5 - 2025-06-25
### What's Changed
* Cleanup by @mathiaspalmqvist in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/8
**Full Changelog**: https://github.com/MattitjaAB/laravel-plausible-proxy/compare/v1.4...v1.5
## v1.4 - 2025-06-16
### What's Changed
* Bump aglipanci/laravel-pint-action from 2.4 to 2.5 by @dependabot in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/3
* Bump dependabot/fetch-metadata from 2.3.0 to 2.4.0 by @dependabot in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/4
* Added support for L12 by @mathiaspalmqvist in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/7
### New Contributors
* @dependabot made their first contribution in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/3
**Full Changelog**: https://github.com/MattitjaAB/laravel-plausible-proxy/compare/v1.3...v1.4
## v1.3 - 2025-01-31
### What's Changed
* Remove site by @mathiaspalmqvist in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/2
**Full Changelog**: https://github.com/MattitjaAB/laravel-plausible-proxy/compare/v1.2...v1.3
## v1.2 - 2025-01-31
**Full Changelog**: https://github.com/MattitjaAB/laravel-plausible-proxy/compare/v1.1...v1.2
## v1.1 - 2025-01-31
### What's Changed
* Refactor event forwarding and improve test coverage by @mathiaspalmqvist in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/1
### New Contributors
* @mathiaspalmqvist made their first contribution in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/1
**Full Changelog**: https://github.com/MattitjaAB/laravel-plausible-proxy/compare/v1.0...v1.1
## First release - 2025-01-30
**Full Changelog**: https://github.com/MattitjaAB/laravel-plausible-proxy/commits/v1.0
+63 -46
View File
@@ -1,21 +1,22 @@
# laravel-plausible-proxy # laravel-plausible-proxy
[![Latest Version on Packagist](https://img.shields.io/packagist/v/mattitjaab/laravel-plausible-proxy.svg?style=flat-square)](https://packagist.org/packages/mattitjaab/laravel-plausible-proxy) [![Latest Version on Packagist](https://img.shields.io/packagist/v/mattitja/laravel-plausible-proxy.svg?style=flat-square)](https://packagist.org/packages/mattitja/laravel-plausible-proxy)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/mattitjaab/laravel-plausible-proxy/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/mattitjaab/laravel-plausible-proxy/actions?query=workflow%3Arun-tests+branch%3Amain) [![Tests](https://git.mattitja.se/559342-9607/laravel-plausible-proxy/actions/workflows/ci.yml/badge.svg?branch=main)](https://git.mattitja.se/559342-9607/laravel-plausible-proxy/actions?workflow=ci.yml)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/mattitjaab/laravel-plausible-proxy/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/mattitjaab/laravel-plausible-proxy/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) [![Code Style](https://git.mattitja.se/559342-9607/laravel-plausible-proxy/actions/workflows/fix-php-code-style-issues.yml/badge.svg?branch=main)](https://git.mattitja.se/559342-9607/laravel-plausible-proxy/actions?workflow=fix-php-code-style-issues.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/mattitjaab/laravel-plausible-proxy.svg?style=flat-square)](https://packagist.org/packages/mattitjaab/laravel-plausible-proxy) [![Total Downloads](https://img.shields.io/packagist/dt/mattitja/laravel-plausible-proxy.svg?style=flat-square)](https://packagist.org/packages/mattitja/laravel-plausible-proxy)
A Laravel package for proxying Plausible Analytics, improving performance and privacy. A Laravel package for proxying Plausible Analytics, improving performance and privacy.
## Requirements ## Requirements
- Laravel 11
- PHP 8.4+
## 🚀 Installation - Laravel 12 or 13
- PHP 8.3, 8.4 or 8.5
## Installation
1. Install the package via Composer: 1. Install the package via Composer:
```sh ```sh
composer require mattitjaab/laravel-plausible-proxy composer require mattitja/laravel-plausible-proxy
``` ```
2. Publish the configuration file: 2. Publish the configuration file:
@@ -23,65 +24,86 @@ A Laravel package for proxying Plausible Analytics, improving performance and pr
php artisan vendor:publish --tag=plausible-proxy-config php artisan vendor:publish --tag=plausible-proxy-config
``` ```
3. Add the following environment variables to your `.env` file: 3. Add the following environment variable to your `.env` file:
```env ```env
PLAUSIBLE_DOMAIN=https://plausible.io PLAUSIBLE_DOMAIN=https://plausible.io
PLAUSIBLE_SITE=example.com
``` ```
4. **(Optional)** If you want to use Laravel Queues to send events in the background, ensure your queue driver is set up correctly: ## Configuration
```env
QUEUE_CONNECTION=database
```
Then run migrations to create the necessary queue tables:
```sh
php artisan queue:table
php artisan migrate
```
## ⚙️ Configuration The `config/plausible-proxy.php` file allows you to customize the Plausible domain:
The `config/plausible-proxy.php` file allows you to customize the package settings:
```php ```php
return [ return [
'domain' => env('PLAUSIBLE_DOMAIN', 'https://plausible.io'), 'domain' => env('PLAUSIBLE_DOMAIN', 'https://plausible.io'),
'site' => env('PLAUSIBLE_SITE', 'example.com'), 'script' => env('PLAUSIBLE_SCRIPT', 'js/script.js'),
]; ];
``` ```
## 🔥 Usage `PLAUSIBLE_SCRIPT` is the path of the script on your Plausible instance. Whatever script you choose, it is always served locally from `/js/script.js`.
## Usage
### 1. Proxying the JavaScript file
### **1. Proxying the JavaScript file**
This package proxies Plausible's `script.js` while caching it to improve performance and reduce external requests. This package proxies Plausible's `script.js` while caching it to improve performance and reduce external requests.
After installation, you can include the script like this: After installation, you can include the script like this:
```html ```html
<script defer data-domain="example.com" src="/js/script.js"></script> <script defer data-domain="example.com" src="/js/script.js"></script>
``` ```
The route `/js/script.js` is automatically handled and caches the script for **6 hours**. The route `/js/script.js` is handled automatically and caches the script for 6 hours.
### **2. Sending Events to Plausible** #### Site-specific script (pa-XXXXX.js)
Instead of sending events directly to `plausible.io`, you can now send them to `/api/event`, and they will be queued and processed asynchronously.
Example request: Plausible's current installation instructions use a site-specific script such as `https://plausible.io/js/pa-12345ABCDE.js`, where optional measurements (outbound links, file downloads, etc.) are configured in the Plausible dashboard. To use it, set the script path in your `.env`:
```sh
curl -X POST "https://example.com/api/event" \ ```env
-H "Content-Type: application/json" \ PLAUSIBLE_SCRIPT=js/pa-12345ABCDE.js
-d '{"n":"pageview","u":"https://example.com/page","d":"example.com"}'
``` ```
## ✅ Features Then load it locally and tell it to send events through the proxy with the `endpoint` option:
- 🚀 **Fast & Optimized**: Caches the Plausible script to reduce external calls. ```html
- 🔒 **Privacy-Friendly**: Prevents direct calls to `plausible.io`. <script async src="/js/script.js"></script>
- 📊 **Improved Performance**: Events are processed via Laravel Queues to avoid blocking user interactions. <script>
- 🛠 **Fully Configurable**: Easily set your own Plausible instance and domain via `.env`. window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
plausible.init({ endpoint: '/api/event' })
</script>
```
## 🛠 Testing #### Legacy script extensions
Legacy script variants work the same way, for example:
```env
PLAUSIBLE_SCRIPT=js/script.outbound-links.js
```
### 2. Sending events to Plausible
The script loaded from `/js/script.js` sends events to `/api/event` on your own domain, which forwards them to Plausible. This helps prevent blocking by ad blockers.
Only the visitor's `User-Agent` and IP address (as `X-Forwarded-For`) are forwarded to Plausible, which is what Plausible needs to count unique visitors. Cookies and other request headers are never forwarded.
If your application runs behind a load balancer or reverse proxy, make sure Laravel's [trusted proxies](https://laravel.com/docs/requests#configuring-trusted-proxies) are configured so the correct visitor IP is resolved.
## Upgrading from mattitjaab/laravel-plausible-proxy
Version 2.0 renames the package and its namespace:
1. Replace the package:
```sh
composer remove mattitjaab/laravel-plausible-proxy
composer require mattitja/laravel-plausible-proxy
```
2. If you reference any package classes directly, change the namespace from `MattitjaAB\LaravelPlausibleProxy` to `Mattitja\LaravelPlausibleProxy`.
3. Laravel 10 is no longer supported.
## Testing
You can run tests with:
```sh ```sh
composer test composer test
``` ```
@@ -90,18 +112,13 @@ composer test
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security Vulnerabilities ## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities. Please report security vulnerabilities by email to hej@mattitja.se.
## Credits ## Credits
- [Mathias Palmqvist](https://github.com/mathiaspalmqvist) - [Mathias Palmqvist](https://github.com/mathiaspalmqvist)
- [All Contributors](../../contributors)
## License ## License
+17 -23
View File
@@ -1,14 +1,13 @@
{ {
"name": "mattitjaab/laravel-plausible-proxy", "name": "mattitja/laravel-plausible-proxy",
"description": "A Laravel package for proxying Plausible Analytics, improving performance and privacy.", "description": "A Laravel package for proxying Plausible Analytics, improving performance and privacy.",
"keywords": [ "keywords": [
"Mattitja AB", "Mattitja",
"MattitjaAB",
"laravel", "laravel",
"laravel-plausible-proxy", "laravel-plausible-proxy",
"plausible" "plausible"
], ],
"homepage": "https://github.com/mattitjaab/laravel-plausible-proxy", "homepage": "https://git.mattitja.se/559342-9607/laravel-plausible-proxy",
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
{ {
@@ -18,33 +17,31 @@
} }
], ],
"require": { "require": {
"php": "^8.4", "php": "^8.3",
"spatie/laravel-package-tools": "^1.16", "spatie/laravel-package-tools": "^1.16",
"illuminate/contracts": "^10.0||^11.0" "illuminate/contracts": "^12.0||^13.0"
}, },
"require-dev": { "require-dev": {
"laravel/pint": "^1.14", "laravel/pint": "^1.14",
"nunomaduro/collision": "^8.1.1||^7.10.0", "nunomaduro/collision": "^8.1",
"larastan/larastan": "^2.9", "larastan/larastan": "^3.0",
"orchestra/testbench": "^9.0.0||^8.22.0", "orchestra/testbench": "^10.0||^11.0",
"pestphp/pest": "^3.0", "pestphp/pest": "^3.0||^4.0",
"pestphp/pest-plugin-arch": "^3.0", "pestphp/pest-plugin-arch": "^3.0||^4.0",
"pestphp/pest-plugin-laravel": "^3.0", "pestphp/pest-plugin-laravel": "^3.0||^4.0",
"phpstan/extension-installer": "^1.3", "phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1", "phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^1.3", "phpstan/phpstan-phpunit": "^2.0",
"spatie/laravel-ray": "^1.35" "spatie/laravel-ray": "^1.35"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"MattitjaAB\\LaravelPlausibleProxy\\": "src/", "Mattitja\\LaravelPlausibleProxy\\": "src/"
"MattitjaAB\\LaravelPlausibleProxy\\Database\\Factories\\": "database/factories/"
} }
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"MattitjaAB\\LaravelPlausibleProxy\\Tests\\": "tests/", "Mattitja\\LaravelPlausibleProxy\\Tests\\": "tests/"
"Workbench\\App\\": "workbench/app/"
} }
}, },
"scripts": { "scripts": {
@@ -65,11 +62,8 @@
"extra": { "extra": {
"laravel": { "laravel": {
"providers": [ "providers": [
"MattitjaAB\\LaravelPlausibleProxy\\LaravelPlausibleProxyServiceProvider" "Mattitja\\LaravelPlausibleProxy\\LaravelPlausibleProxyServiceProvider"
], ]
"aliases": {
"LaravelPlausibleProxy": "MattitjaAB\\LaravelPlausibleProxy\\Facades\\LaravelPlausibleProxy"
}
} }
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
+12 -1
View File
@@ -3,6 +3,17 @@
// Config for Laravel Plausible Proxy // Config for Laravel Plausible Proxy
return [ return [
/*
* The Plausible instance to proxy, e.g. https://plausible.io or your
* self-hosted instance.
*/
'domain' => env('PLAUSIBLE_DOMAIN', 'https://plausible.io'), 'domain' => env('PLAUSIBLE_DOMAIN', 'https://plausible.io'),
'site' => env('PLAUSIBLE_SITE', 'example.com'),
/*
* Path of the script to fetch from the Plausible instance. Use this for
* site-specific scripts (e.g. js/pa-12345ABCDE.js) or legacy script
* extensions (e.g. js/script.outbound-links.js). The script is always
* served locally from /js/script.js.
*/
'script' => env('PLAUSIBLE_SCRIPT', 'js/script.js'),
]; ];
-19
View File
@@ -1,19 +0,0 @@
<?php
namespace MattitjaAB\LaravelPlausibleProxy\Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/*
class ModelFactory extends Factory
{
protected $model = YourModel::class;
public function definition()
{
return [
];
}
}
*/
@@ -1,19 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('laravel_plausible_proxy_table', function (Blueprint $table) {
$table->id();
// add fields
$table->timestamps();
});
}
};
+4 -1
View File
@@ -6,7 +6,10 @@ parameters:
paths: paths:
- src - src
- config - config
- database
tmpDir: build/phpstan tmpDir: build/phpstan
checkOctaneCompatibility: true checkOctaneCompatibility: true
checkModelProperties: true checkModelProperties: true
ignoreErrors:
-
identifier: larastan.noEnvCallsOutsideOfConfig
path: config/plausible-proxy.php
+1 -1
View File
@@ -16,7 +16,7 @@
backupStaticProperties="false" backupStaticProperties="false"
> >
<testsuites> <testsuites>
<testsuite name="MattitjaAB Test Suite"> <testsuite name="Mattitja Test Suite">
<directory>tests</directory> <directory>tests</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
View File
Whitespace-only changes.
+2 -22
View File
@@ -1,26 +1,6 @@
<?php <?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Concurrency;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Validator; use Mattitja\LaravelPlausibleProxy\Http\Controllers\PlausibleEventApiController;
Route::post('api/event', function (Request $request) { Route::post('api/event', PlausibleEventApiController::class);
$validator = Validator::make($request->all(), [
'n' => 'required|string',
'u' => 'required|url',
'd' => 'required|string',
'r' => 'nullable|url',
'm' => 'nullable|string',
'p' => 'nullable|array',
]);
if ($validator->fails()) {
return response()->json(['status' => 'error', 'errors' => $validator->errors()], 422);
}
Concurrency::defer(fn () => Http::post(config('plausible-proxy.domain').'/api/event', $request->all()));
return response()->json(['status' => 'queued']);
});
+2 -30
View File
@@ -1,34 +1,6 @@
<?php <?php
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Mattitja\LaravelPlausibleProxy\Http\Controllers\PlausibleScriptProxyController;
Route::get('/js/script.js', function () { Route::get('/js/script.js', PlausibleScriptProxyController::class);
$plausibleDomain = config('plausible-proxy.domain');
if (Cache::has('plausible_script_js')) {
return response(Cache::get('plausible_script_js'))
->header('Content-Type', 'application/javascript')
->header('Cache-Control', 'public, max-age=86400');
}
$response = Http::timeout(5)->get("{$plausibleDomain}/js/script.js");
if ($response->successful()) {
$script = $response->body();
Cache::put('plausible_script_js', $script, now()->addHours(6));
return response($script)
->header('Content-Type', 'application/javascript')
->header('Cache-Control', 'public, max-age=86400');
}
return response('Error fetching Plausible script', 500);
});
Route::get('/api/routes', function () {
return response()->json(
collect(Route::getRoutes())->map(fn ($route) => $route->uri())
);
});
@@ -1,19 +0,0 @@
<?php
namespace MattitjaAB\LaravelPlausibleProxy\Commands;
use Illuminate\Console\Command;
class LaravelPlausibleProxyCommand extends Command
{
public $signature = 'laravel-plausible-proxy';
public $description = 'My command';
public function handle(): int
{
$this->comment('All done');
return self::SUCCESS;
}
}
-16
View File
@@ -1,16 +0,0 @@
<?php
namespace MattitjaAB\LaravelPlausibleProxy\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @see \MattitjaAB\LaravelPlausibleProxy\LaravelPlausibleProxy
*/
class LaravelPlausibleProxy extends Facade
{
protected static function getFacadeAccessor(): string
{
return \MattitjaAB\LaravelPlausibleProxy\LaravelPlausibleProxy::class;
}
}
@@ -0,0 +1,33 @@
<?php
namespace Mattitja\LaravelPlausibleProxy\Http\Controllers;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Mattitja\LaravelPlausibleProxy\Http\Requests\PlausibleEventRequest;
class PlausibleEventApiController
{
public function __invoke(PlausibleEventRequest $request): Response
{
$url = rtrim((string) config('plausible-proxy.domain'), '/').'/api/event';
try {
$upstream = Http::timeout(5)
->withHeaders([
'User-Agent' => (string) $request->userAgent(),
'X-Forwarded-For' => (string) $request->ip(),
])
->post($url, $request->all());
} catch (ConnectionException $e) {
Log::error('Failed to forward Plausible event: '.$e->getMessage());
return response('Bad Gateway', 502);
}
return response($upstream->body(), $upstream->status())
->header('Content-Type', $upstream->header('Content-Type') ?: 'text/plain');
}
}
@@ -0,0 +1,34 @@
<?php
namespace Mattitja\LaravelPlausibleProxy\Http\Controllers;
use Illuminate\Http\Client\RequestException;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class PlausibleScriptProxyController
{
public function __invoke(): Response
{
$url = rtrim((string) config('plausible-proxy.domain'), '/')
.'/'.ltrim((string) config('plausible-proxy.script', 'js/script.js'), '/');
try {
$script = Cache::remember(
key: 'plausible_script_js:'.md5($url),
ttl: now()->addHours(6),
callback: fn () => Http::timeout(5)->get($url)->throw()->body(),
);
} catch (RequestException $e) {
Log::error('Failed to fetch Plausible script: '.$e->getMessage());
return response('Error fetching Plausible script', 500);
}
return response($script)
->header('Content-Type', 'application/javascript')
->header('Cache-Control', 'public, max-age=86400');
}
}
@@ -0,0 +1,61 @@
<?php
namespace Mattitja\LaravelPlausibleProxy\Http\Requests;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
class PlausibleEventRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* The Plausible tracker sends its JSON payload with a text/plain content
* type, which Laravel does not parse automatically.
*/
protected function prepareForValidation(): void
{
if ($this->isJson()) {
return;
}
$payload = json_decode($this->getContent(), true);
if (is_array($payload)) {
$this->merge($payload);
}
}
protected function failedValidation(Validator $validator): void
{
if (! $this->expectsJson()) {
throw new HttpResponseException(response('Bad Request', 400));
}
parent::failedValidation($validator);
}
public function rules(): array
{
return [
'n' => ['required', 'string'],
'u' => ['required', 'url'],
'd' => ['required', 'string'],
'r' => ['nullable', 'url'],
'm' => ['nullable', 'string'],
'p' => ['nullable', function (string $attribute, mixed $value, \Closure $fail) {
if (is_array($value)) {
return;
}
if (! is_string($value) || ! is_array(json_decode($value, true))) {
$fail("The {$attribute} field must be an object or a JSON-encoded object.");
}
}],
];
}
}
-5
View File
@@ -1,5 +0,0 @@
<?php
namespace MattitjaAB\LaravelPlausibleProxy;
class LaravelPlausibleProxy {}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace MattitjaAB\LaravelPlausibleProxy; namespace Mattitja\LaravelPlausibleProxy;
use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider; use Spatie\LaravelPackageTools\PackageServiceProvider;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
use MattitjaAB\LaravelPlausibleProxy\Tests\TestCase; use Mattitja\LaravelPlausibleProxy\Tests\TestCase;
uses(TestCase::class)->in(__DIR__); uses(TestCase::class)->in(__DIR__);
+157 -30
View File
@@ -1,30 +1,61 @@
<?php <?php
use Illuminate\Support\Facades\Cache; use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
it('returns plausible script from cache', function () { it('fetches plausible script and caches it', function () {
Cache::put('plausible_script_js', 'console.log("Cached script");', now()->addHours(6));
$response = $this->get('/js/script.js');
$response->assertStatus(200)
->assertHeader('Content-Type', 'application/javascript')
->assertSee('Cached script');
});
it('fetches plausible script if not cached', function () {
Http::fake([ Http::fake([
'https://plausible.io/js/script.js' => Http::response('console.log("Plausible script");', 200), 'https://plausible.io/js/script.js' => Http::response('console.log("Plausible script");', 200),
]); ]);
$response = $this->get('/js/script.js'); $this->get('/js/script.js')
->assertStatus(200)
$response->assertStatus(200)
->assertHeader('Content-Type', 'application/javascript') ->assertHeader('Content-Type', 'application/javascript')
->assertSee('Plausible script'); ->assertSee('Plausible script');
expect(Cache::get('plausible_script_js'))->toBe('console.log("Plausible script");'); $this->get('/js/script.js')
->assertStatus(200)
->assertSee('Plausible script');
Http::assertSentCount(1);
});
it('fetches a custom script path', function () {
config()->set('plausible-proxy.script', 'js/pa-12345ABCDE.js');
Http::fake([
'https://plausible.io/js/pa-12345ABCDE.js' => Http::response('console.log("Custom script");', 200),
]);
$this->get('/js/script.js')
->assertStatus(200)
->assertSee('Custom script');
Http::assertSent(fn ($request) => $request->url() === 'https://plausible.io/js/pa-12345ABCDE.js');
});
it('handles trailing and leading slashes in domain and script path', function () {
config()->set('plausible-proxy.domain', 'https://plausible.example.com/');
config()->set('plausible-proxy.script', '/js/script.outbound-links.js');
Http::fake([
'https://plausible.example.com/js/script.outbound-links.js' => Http::response('console.log("Outbound");', 200),
]);
$this->get('/js/script.js')->assertStatus(200)->assertSee('Outbound');
});
it('does not serve a cached script after the script path changes', function () {
Http::fake([
'https://plausible.io/js/script.js' => Http::response('console.log("Old script");', 200),
'https://plausible.io/js/pa-12345ABCDE.js' => Http::response('console.log("New script");', 200),
]);
$this->get('/js/script.js')->assertSee('Old script');
config()->set('plausible-proxy.script', 'js/pa-12345ABCDE.js');
$this->get('/js/script.js')->assertSee('New script');
}); });
it('handles failed script fetch', function () { it('handles failed script fetch', function () {
@@ -46,29 +77,125 @@ it('rejects invalid event data', function () {
]); ]);
$response->assertStatus(422) $response->assertStatus(422)
->assertJsonStructure(['status', 'errors']); ->assertJsonValidationErrors(['u' => 'The u field must be a valid URL.']);
}); });
it('accepts valid event data and defers request', function () { it('forwards only user agent and client ip to plausible', function () {
Http::fake(); config()->set('plausible-proxy.domain', 'https://plausible.io');
$concurrencyMock = Mockery::mock('alias:Illuminate\Support\Facades\Concurrency'); Http::fake([
$concurrencyMock->shouldReceive('defer')->once()->andReturnUsing(function ($callback) { 'https://plausible.io/api/event' => Http::response('ok', 202),
$callback(); ]);
$response = $this->withServerVariables(['REMOTE_ADDR' => '203.0.113.7'])
->postJson('/api/event', [
'n' => 'pageview',
'u' => 'https://example.com/page',
'd' => 'example.com',
], [
'User-Agent' => 'TestAgent',
'Cookie' => 'laravel_session=secret',
'Authorization' => 'Bearer secret',
]);
$response->assertStatus(202);
expect($response->getContent())->toBe('ok');
Http::assertSentCount(1);
Http::assertSent(function ($request) {
return $request->url() === 'https://plausible.io/api/event'
&& $request->header('User-Agent') === ['TestAgent']
&& $request->header('X-Forwarded-For') === ['203.0.113.7']
&& ! $request->hasHeader('Cookie')
&& ! $request->hasHeader('Authorization')
&& $request['n'] === 'pageview'
&& $request['u'] === 'https://example.com/page'
&& $request['d'] === 'example.com';
}); });
});
$response = $this->postJson('/api/event', [ it('forwards additional plausible fields', function () {
config()->set('plausible-proxy.domain', 'https://plausible.io');
Http::fake([
'https://plausible.io/api/event' => Http::response('ok', 202),
]);
$this->postJson('/api/event', [
'n' => 'Purchase',
'u' => 'https://example.com/checkout',
'd' => 'example.com',
'i' => false,
'p' => '{"plan":"pro"}',
'$' => ['amount' => '9.99', 'currency' => 'EUR'],
])->assertStatus(202);
Http::assertSent(function ($request) {
return $request['i'] === false
&& $request['p'] === '{"plan":"pro"}'
&& $request['$'] === ['amount' => '9.99', 'currency' => 'EUR'];
});
});
it('rejects invalid props', function () {
$this->postJson('/api/event', [
'n' => 'pageview', 'n' => 'pageview',
'u' => 'https://example.com/page', 'u' => 'https://example.com/page',
'd' => 'example.com', 'd' => 'example.com',
'p' => 'not-json',
])->assertStatus(422)->assertJsonValidationErrors(['p']);
});
it('accepts events sent as text/plain by the plausible tracker', function () {
Http::fake([
'https://plausible.io/api/event' => Http::response('ok', 202),
]); ]);
$response->assertStatus(200) $this->call('POST', '/api/event', [], [], [], ['CONTENT_TYPE' => 'text/plain'], json_encode([
->assertJson(['status' => 'queued']); 'n' => 'pageview',
'u' => 'https://example.com/page',
'd' => 'example.com',
'r' => null,
]))->assertStatus(202);
Http::assertSent(fn ($request) => $request->url() === config('plausible-proxy.domain').'/api/event' && Http::assertSent(fn ($request) => $request->url() === 'https://plausible.io/api/event'
$request['n'] === 'pageview' && $request['n'] === 'pageview'
); && $request['u'] === 'https://example.com/page'
&& $request['d'] === 'example.com');
Mockery::close(); });
it('responds with 400 for invalid text/plain events', function () {
Http::fake();
$this->call('POST', '/api/event', [], [], [], ['CONTENT_TYPE' => 'text/plain'], 'not-json')
->assertStatus(400);
Http::assertNothingSent();
});
it('handles a trailing slash in the domain when forwarding events', function () {
config()->set('plausible-proxy.domain', 'https://plausible.example.com/');
Http::fake([
'https://plausible.example.com/api/event' => Http::response('ok', 202),
]);
$this->postJson('/api/event', [
'n' => 'pageview',
'u' => 'https://example.com/page',
'd' => 'example.com',
])->assertStatus(202);
Http::assertSent(fn ($request) => $request->url() === 'https://plausible.example.com/api/event');
});
it('responds with 502 when plausible is unreachable', function () {
Http::fake(fn () => throw new ConnectionException('Connection refused'));
$this->postJson('/api/event', [
'n' => 'pageview',
'u' => 'https://example.com/page',
'd' => 'example.com',
])->assertStatus(502);
}); });
+2 -12
View File
@@ -1,22 +1,12 @@
<?php <?php
namespace MattitjaAB\LaravelPlausibleProxy\Tests; namespace Mattitja\LaravelPlausibleProxy\Tests;
use Illuminate\Database\Eloquent\Factories\Factory; use Mattitja\LaravelPlausibleProxy\LaravelPlausibleProxyServiceProvider;
use MattitjaAB\LaravelPlausibleProxy\LaravelPlausibleProxyServiceProvider;
use Orchestra\Testbench\TestCase as Orchestra; use Orchestra\Testbench\TestCase as Orchestra;
class TestCase extends Orchestra class TestCase extends Orchestra
{ {
protected function setUp(): void
{
parent::setUp();
Factory::guessFactoryNamesUsing(
fn (string $modelName) => 'MattitjaAB\\LaravelPlausibleProxy\\Database\\Factories\\'.class_basename($modelName).'Factory'
);
}
protected function getPackageProviders($app) protected function getPackageProviders($app)
{ {
return [ return [