---
title: "Tracking script — Plausible for Laravel | Roundly"
description: "Render the official hosted Plausible script with @plausibleScript or <x-plausible-script>, configured from one place."
url: https://roundly-consulting.com/open-source/docs/plausible-for-laravel/tracking-script
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Plausible for Laravel](https://roundly-consulting.com/open-source/docs/plausible-for-laravel.md)

# 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):

```blade
{{-- 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:

```html
<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:

```php
use RoundlyConsulting\Plausible\Facades\Plausible;

Plausible::script();                // HtmlString; empty when no domain is configured
Plausible::script('my-site.com');   // explicit domain
```

## Customising 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.

```bash
php artisan vendor:publish --tag="plausible-views"
```

```blade
{{-- 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:

```bash
PLAUSIBLE_SCRIPT_DOMAIN=my-site.com
PLAUSIBLE_SCRIPT_SRC=https://analytics.example.com/js/script.tagged-events.js
```

## Show 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 crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/plausible-for-laravel.md)
