How to add analytics to Laravel

In a Laravel app, add the tracker to the Blade layout that wraps your pages. The @production directive keeps it out of local and staging environments.

No cookies, no banner ~3 KB script About 2 minutes

Before you start

Create a free Cool Analytics account and add your site. You'll get a site ID — replace YOUR_SITE_ID in the code below with it. The dashboard shows the snippet with your ID already filled in.

Install on Laravel

  1. 1Open your main Blade layout, e.g. resources/views/layouts/app.blade.php.
  2. 2Paste the snippet inside <head>, wrapped in @production … @endproduction.
  3. 3Deploy. With Livewire's wire:navigate or Inertia, page changes are tracked automatically.
resources/views/layouts/app.blade.php
@production
    <script defer src="https://coolanalytics.dev/hb.js" data-site="YOUR_SITE_ID"></script>
@endproduction

Check that it works

Open your live site in a new tab, then open your Cool Analytics dashboard. Your visit appears on the live map within seconds — with the page you're on, where you came from and your browser.

Nothing showing up? Make sure you're looking at the published site (not a preview or editor), that an ad blocker isn't blocking the script, and that you're not testing on localhost.

Track signups, purchases and clicks

Pageviews, sources, countries and outbound link clicks are tracked automatically. For the moments that matter to you, send a custom event. Events named like a signup show up as signups, and events with an amount show up as revenue — on the live map and per traffic source.

custom events
// anywhere in your Laravel site's browser code
window.hb?.track("signup");

// with an amount, it shows up as revenue
window.hb?.track("purchase", { amount: 49 });

Laravel tips

  • @production renders only when APP_ENV=production.
  • With Inertia (Vue or React), the root template is resources/views/app.blade.php — add it there.

Want to keep your own visits out of the stats? Open your site once with #hb-ignore at the end of the URL. That browser is excluded until you visit with #hb-track.

Laravel analytics FAQ

Can I track server-side events, like a completed order?+

The tracker runs in the browser. Fire hb.track('purchase', { amount: 49 }) on the order confirmation page.

Does it work with Livewire?+

Yes. Full page loads and wire:navigate transitions are both counted.

Do I need a Composer package?+

No. It's one tag in your layout.

See who's on your Laravel site right now.

One line of code. No cookies. 7 days free.