Skip to main content
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

resources/views/layouts/app.blade.php
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.

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.

Send custom events

In a Blade view, a data-cs-event attribute counts clicks with no JavaScript:
resources/views/pricing.blade.php
From the browser, call window.crispstats?.("signup", { plan: "pro" }). See custom events.

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:
app/Services/CrispStats.php
A 202 means the event was accepted. Server-side events covers the payload and every status code, and payment API covers payments from your own billing.

FAQ

No. The script tag and, for server events, one HTTP request are the whole integration.
Add the queue stub 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 first: identify makes those visits personal data.
Yes. On nginx, Caddy, Cloudflare or another host in front of your app, add one forwarding rule. See proxy by host.

Next steps

Server-side events

Send renewals and other backend actions.

Proxy with nginx

Serve the script from your own domain.

Visitor id at checkout

Attribute payments to the visit that led to them.
Laravel details (the layout file paths and the @production directive) checked against https://laravel.com/docs/blade on 2026-11-23.
Last modified on November 23, 2026