Tracking script
Render the official hosted Plausible script in your layout with the @plausibleScript directive or the <x-plausible-script> component. No JavaScript is bundled — it just emits the standard script tag built from your config (script.domain and script.src):
{{-- uses script.domain (or falls back to site) --}}
@plausibleScript
{{-- or override the domain --}}
@plausibleScript('my-site.com')
{{-- component form --}}
<x-plausible-script />
<x-plausible-script domain="my-site.com" />Each form renders:
<script defer data-domain="my-site.com" src="https://plausible.io/js/script.js"></script>The domain is the explicit argument, else script.domain, else the default site. With none of them set, nothing is rendered — so the tag can stay in the layout for local environments. Values are HTML-escaped.
Outside Blade
In Inertia, a plain PHP template or a JSON payload, ask the facade for the same tag. The directive and the component both render Plausible::script(), so rebinding the manager changes all three:
use RoundlyConsulting\Plausible\Facades\Plausible;
Plausible::script(); // HtmlString; empty when no domain is configured
Plausible::script('my-site.com'); // explicit domainCustomising the markup
Plausible::script() renders the plausible::components.script view with $domain and $src. Publish it and edit resources/views/vendor/plausible/components/script.blade.php to change the markup everywhere — add a data-api attribute for a proxy, say. With no domain, nothing is rendered.
php artisan vendor:publish --tag="plausible-views"{{-- resources/views/vendor/plausible/components/script.blade.php --}}
{{-- Variables: $domain (the data-domain) and $src (plausible.script.src) --}}
<script defer data-domain="{{ $domain }}" src="{{ $src }}"></script>Self-hosted or a script variant
Point script.src at your self-hosted instance or a Plausible script variant:
PLAUSIBLE_SCRIPT_DOMAIN=my-site.com
PLAUSIBLE_SCRIPT_SRC=https://analytics.example.com/js/script.tagged-events.jsShow your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.