Laravel
Add Humblytics Analytics to a Laravel Site
1 · Sign up (or log in)
Visit humblytics.com → Start Free Trial. Finish signup—or log in to your existing workspace.
2 · Add your website in Humblytics
In the sidebar, click Add Website.
Domain – enter your site's domain (omit
https://andwww)Site Name – internal label (e.g.
Marketing-Laravel)
Copy the snippet from Install Tracking Code:
html
<!-- Start Humblytics Tracking Code -->
<script async src="https://app.humblytics.com/hmbl.min.js?id=YOUR_ID_HERE"></script>
<!-- End Humblytics Tracking Code -->Keep this tab open—we'll return and click Verify Website once the tag is live.
3 · Add the script to your Laravel project
Option 1: Blade layout (recommended for most apps)
Best for: Traditional Blade template apps
Open your main layout file, typically:
resources/views/layouts/app.blade.phpOr
resources/views/layouts/master.blade.php
Add your Humblytics script just before the closing
</head>tag:
blade
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ config('app.name', 'Laravel') }}</title>
@vite(['resources/css/app.css', 'resources/js/app.js'])
<!-- Humblytics Analytics -->
@production
<script async src="https://app.humblytics.com/hmbl.min.js?id=YOUR_ID_HERE"></script>
@endproduction
</head>
<body>
@yield('content')
</body>
</html>Ensure your pages extend this layout:
blade
@extends('layouts.app')
@section('content')
<!-- Your page content -->
@endsectionNote: The @production directive ensures the script only loads in production, not during local development.
Option 2: Using environment variables (recommended)
Best for: Managing multiple environments (staging, production)
Add your Humblytics ID to
.env:
env
HUMBLYTICS_ID=YOUR_ID_HEREIn your layout file (
resources/views/layouts/app.blade.php):
blade
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ config('app.name', 'Laravel') }}</title>
@vite(['resources/css/app.css', 'resources/js/app.js'])
<!-- Humblytics Analytics -->
@if(config('app.env') === 'production' && env('HUMBLYTICS_ID'))
<script async src="https://app.humblytics.com/hmbl.min.js?id={{ env('HUMBLYTICS_ID') }}"></script>
@endif
</head>
<body>
@yield('content')
</body>
</html>Add to
.env.productionor your production environment
Note: Replace YOUR_ID_HERE with your actual project ID from Humblytics.
Option 3: Blade component (Laravel 8+)
Best for: Modern Laravel apps using Blade components
Create a new component:
bash
php artisan make:component AnalyticsEdit
app/View/Components/Analytics.php:
php
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class Analytics extends Component
{
public function render()
{
return view('components.analytics');
}
public function shouldRender(): bool
{
return app()->environment('production') && config('services.humblytics.id');
}
}Create
resources/views/components/analytics.blade.php:
blade
<script async src="https://app.humblytics.com/hmbl.min.js?id={{ config('services.humblytics.id') }}"></script>Add to
config/services.php:
php
'humblytics' => [
'id' => env('HUMBLYTICS_ID'),
],Add to your layout's
<head>:
blade
<x-analytics />Multiple layouts
If your app uses multiple layout files (e.g., app.blade.php, guest.blade.php, admin.blade.php), add the script to each layout file, or:
Create a partial:
resources/views/partials/analytics.blade.phpAdd the Humblytics script to this file
Include in each layout:
@include('partials.analytics')
4 · Deploy and verify
Clear Laravel caches:
bash
php artisan view:clear
php artisan config:clear
php artisan cache:clearDeploy your changes to production
Return to Humblytics and click Verify Website
Open your live site in a private/incognito window and refresh once
Within ~30 seconds you should see a green Verified badge and live visitor count
If verification fails, check:
Script ID matches your project in Humblytics
You deployed to production (not testing localhost)
You cleared Laravel's view cache
The
@productionor environment check allows the script to loadView page source (right-click → View Page Source) and search for "humblytics"
No ad-blockers or browser extensions are interfering
Debug in Laravel:
bash
# Check if views are cached
php artisan view:clear
# Check config cache
php artisan config:clear
# Verify environment
php artisan env5 · Explore & optimize
Dashboard – see traffic, top pages, and referrers
Heatmaps – auto-generated scroll and click maps
Experiments – run A/B tests directly from Humblytics
Last updated
Was this helpful?