> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crispstats.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Add CrispStats to a Laravel app

> Install CrispStats in a Laravel app by adding the script tag to the head of your Blade layout, then send server-side events from your app with a secret key.

To add CrispStats to a Laravel app, paste the script tag inside `<head>` in the Blade layout your pages share, such as `resources/views/layouts/app.blade.php` or `resources/views/components/layout.blade.php`. Every page rendered with that layout is tracked. For actions that happen on the server, such as a renewal in a webhook, send an event with one HTTP request.

You need your site's public key, which starts with `cs_pk_`. Find it in your site's settings under **Tracking code**, on the **HTML** tab. The key is safe to publish. There is no Composer or npm package to install.

## Add the script

**1. Paste the tag into your layout**

```blade resources/views/layouts/app.blade.php theme={"theme":{"light":"github-light","dark":"github-dark"}}
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
  <head>
    <meta charset="utf-8" />
    <title>@yield('title')</title>
    <script
      defer
      data-site="cs_pk_xxxxxxxx"
      data-domains="example.com"
      src="https://in.crispstats.com/d.js"
    ></script>
  </head>
  <body>
    @yield('content')
  </body>
</html>
```

Replace the key and the domain with yours. If your app has more than one layout (for example a separate one for the admin area), add the tag to each layout you want tracked.

**2. Deploy and open your app**

`php artisan serve` and other local hosts run on `localhost` or `127.0.0.1`, which the script ignores. Deploy, then open your live app in a normal browser window. If you prefer, wrap the tag in `@production` and `@endproduction` so it is only rendered in production.

## Check that it works

* In your browser's developer tools, the **Network** tab shows `d.js` loading from `in.crispstats.com` and a `POST` to `https://in.crispstats.com/e` that gets `202`.
* In CrispStats, **Settings**, **Tracking code** shows **Receiving events.**, and the visit appears in **Realtime** within seconds.

To see events locally, add `data-debug` and `localhost` in `data-domains` while you develop. Every event is logged in the console and nothing is sent. See [localhost and testing](https://docs.crispstats.com/tracking/localhost-and-testing.md#debug-mode).

## How page changes are counted

A classic Blade app does a full page load per page, so each load is one pageview. If your front end changes pages without a reload (with Inertia, or another client-side router) and updates the URL through the History API, the script counts each new URL as a pageview. Put the tag in the root view that wraps the app, once. See [single-page apps](https://docs.crispstats.com/tracking/single-page-apps.md).

## Send custom events

In a Blade view, a `data-cs-event` attribute counts clicks with no JavaScript:

```blade resources/views/pricing.blade.php theme={"theme":{"light":"github-light","dark":"github-dark"}}
<a href="{{ route('register') }}" data-cs-event="signup click" data-cs-prop-plan="pro">Start free</a>
```

From the browser, call `window.crispstats?.("signup", { plan: "pro" })`. See [custom events](https://docs.crispstats.com/track/custom-events.md).

## Send events from your server

Server-side events need a secret API key (`cs_sk_…`) with the **Events** scope, kept in your `.env`, never in a view. Pass the visitor id you saved from `crispstats.id()` so the event joins that visitor's history. With Laravel's HTTP client:

```php app/Services/CrispStats.php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use Illuminate\Support\Facades\Http;

$response = Http::withToken(config('services.crispstats.key')) // cs_sk_…
    ->post('https://in.crispstats.com/e', [
        'k' => 'cs_pk_xxxxxxxx',
        't' => 'event',
        'n' => 'subscription_renewed',
        'u' => '',
        'p' => ['plan' => 'pro'],
        'vid' => $subscription->crispstats_visitor_id,
    ]);
```

A `202` means the event was accepted. [Server-side events](https://docs.crispstats.com/track/server-side-events.md) covers the payload and every status code, and [payment API](https://docs.crispstats.com/revenue/payment-api.md) covers payments from your own billing.

## FAQ

> [accordion] Is there a Laravel package?
>
> No. The script tag and, for server events, one HTTP request are the whole integration.

> [accordion] How do I tie visits to my users?
>
> Add the [queue stub](https://docs.crispstats.com/track/custom-events.md#call-crispstats-before-the-script-loads) above the tag, then, inside `@auth` and `@endauth`, an inline script that calls `crispstats.identify("{{ auth()->id() }}")`. Inline code runs before a deferred script, so without the stub the call is lost. Read [identify signed-in users](https://docs.crispstats.com/track/identify-users.md) first: identify makes those visits personal data.

> [accordion] Can I serve the script from my own domain?
>
> Yes. On nginx, Caddy, Cloudflare or another host in front of your app, add one forwarding rule. See [proxy by host](https://docs.crispstats.com/tracking/proxy.md).

## Next steps

> [card] [Server-side events](https://docs.crispstats.com/track/server-side-events.md)
>
> Send renewals and other backend actions.

> [card] [Proxy with nginx](https://docs.crispstats.com/tracking/proxy/nginx.md)
>
> Serve the script from your own domain.

> [card] [Visitor id at checkout](https://docs.crispstats.com/revenue/visitor-id-at-checkout.md)
>
> Attribute payments to the visit that led to them.

> [!NOTE]
>
> Laravel details (the layout file paths and the `@production` directive) checked against [https://laravel.com/docs/blade](https://laravel.com/docs/blade) on 2026-11-23.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.