Support custom Plausible script path #19

Merged
mathiaspalmqvist merged 2 commits from issue-14-custom-script-path into main 2026-11-12 07:29:23 +00:00
Owner

Closes #14

Summary

Adds a PLAUSIBLE_SCRIPT config option so the package can proxy Plausible's site-specific scripts (js/pa-XXXXX.js) and legacy script extensions (e.g. js/script.outbound-links.js).

  • New config key script (env PLAUSIBLE_SCRIPT), default js/script.js, so existing installs are unaffected
  • The script is still served locally from /js/script.js
  • Leading/trailing slashes in domain and script are normalised
  • Cache key is derived from the script URL, so changing the script takes effect immediately instead of serving the old cached script for up to 6 hours
  • README documents the site-specific script setup, including plausible.init({ endpoint: '/api/event' }) so events go through the proxy

Testing

  • composer test: 10 passed (new tests for custom path, slash normalisation, cache invalidation on script change and caching)
  • composer analyse: no errors
  • vendor/bin/pint --test: passed

To verify before merge

  • That the endpoint option in plausible.init() is the correct way to route events from the new pa- script through the proxy (not tested against a real pa- script).
Closes #14 ## Summary Adds a `PLAUSIBLE_SCRIPT` config option so the package can proxy Plausible's site-specific scripts (`js/pa-XXXXX.js`) and legacy script extensions (e.g. `js/script.outbound-links.js`). - New config key `script` (env `PLAUSIBLE_SCRIPT`), default `js/script.js`, so existing installs are unaffected - The script is still served locally from `/js/script.js` - Leading/trailing slashes in `domain` and `script` are normalised - Cache key is derived from the script URL, so changing the script takes effect immediately instead of serving the old cached script for up to 6 hours - README documents the site-specific script setup, including `plausible.init({ endpoint: '/api/event' })` so events go through the proxy ## Testing - `composer test`: 10 passed (new tests for custom path, slash normalisation, cache invalidation on script change and caching) - `composer analyse`: no errors - `vendor/bin/pint --test`: passed ## To verify before merge - That the `endpoint` option in `plausible.init()` is the correct way to route events from the new `pa-` script through the proxy (not tested against a real `pa-` script).
mathiaspalmqvist added 1 commit 2026-11-12 07:27:54 +00:00
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
513ceb61a0
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
mathiaspalmqvist added 1 commit 2026-11-12 07:29:12 +00:00
Merge branch 'main' into issue-14-custom-script-path
dependabot-auto-merge / dependabot (pull_request_target) Skipped
91429ccd22
mathiaspalmqvist merged commit 77c0e38f84 into main 2026-11-12 07:29:23 +00:00
mathiaspalmqvist deleted branch issue-14-custom-script-path 2026-11-12 07:29:23 +00:00
Sign in to join this conversation.