Accept text/plain events from the Plausible tracker #21

Merged
mathiaspalmqvist merged 1 commits from fix-text-plain-events into main 2026-11-12 08:21:32 +00:00
Owner

The Plausible tracker sends events via fetch with Content-Type: text/plain and a JSON body. Laravel doesn't parse that, so every real event failed validation (302 redirect) and never reached Plausible. The tests used postJson(), which hid the bug.

Changes

  • PlausibleEventRequest: decodes the raw body when the request isn't JSON
  • Invalid non-JSON requests get a 400 instead of a redirect (JSON requests still get 422)
  • The event controller trims a trailing slash from the domain, uses a 5s timeout and responds with 502 when Plausible is unreachable
  • New tests for text/plain, invalid body, trailing slash and connection failures

Compared against https://plausible.io/docs/proxy/guides/laravel – everything else already matches.

The Plausible tracker sends events via `fetch` with `Content-Type: text/plain` and a JSON body. Laravel doesn't parse that, so every real event failed validation (302 redirect) and never reached Plausible. The tests used `postJson()`, which hid the bug. ## Changes - `PlausibleEventRequest`: decodes the raw body when the request isn't JSON - Invalid non-JSON requests get a 400 instead of a redirect (JSON requests still get 422) - The event controller trims a trailing slash from the domain, uses a 5s timeout and responds with 502 when Plausible is unreachable - New tests for text/plain, invalid body, trailing slash and connection failures Compared against https://plausible.io/docs/proxy/guides/laravel – everything else already matches.
mathiaspalmqvist added 1 commit 2026-11-12 08:20:17 +00:00
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
a97baf5921
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
mathiaspalmqvist merged commit 16257e3383 into main 2026-11-12 08:21:32 +00:00
mathiaspalmqvist deleted branch fix-text-plain-events 2026-11-12 08:21:32 +00:00
Sign in to join this conversation.