OnyxMetric
Integration Guides

Laravel

Add OnyxMetric analytics to your Laravel app

Laravel pages are built from Blade layouts, so the tag goes in the layout that wraps your site. Read the site ID from config/services.php and .env to keep it out of the template.

Copy your tracking snippet

In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:

<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>

YOUR_SITE_ID is the numeric ID of your site.

Add the snippet to Laravel

Configure the site ID

.env
ONYXMETRIC_SITE_ID=YOUR_SITE_ID
config/services.php
'onyxmetric' => [
    'site_id' => env('ONYXMETRIC_SITE_ID'),
],

Run php artisan config:clear if configuration is cached.

Edit the layout

In a default install this is resources/views/layouts/app.blade.php. Breeze and Jetstream also ship a guest layout, and Inertia apps use resources/views/app.blade.php.

resources/views/layouts/app.blade.php
<head>
    <meta charset="utf-8">
    <title>{{ config('app.name', 'Laravel') }}</title>
    @vite(['resources/css/app.css', 'resources/js/app.js'])

    @production
        <script src="https://app.onyxmetric.com/api/script.js?siteId={{ config('services.onyxmetric.site_id') }}" async></script>
    @endproduction
</head>

@production renders the tag only when APP_ENV=production, so local work is not tracked. Remove it if you want staging data too. With several layouts, add the tag to each or put it in a partial and @include it.

Check that it works

Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.

If nothing arrives:

  • View the page source and search for script.js?siteId= to confirm the tag is present.
  • In the browser's Network tab, check that script.js returns 200 and that requests go to /api/track.
  • Turn off ad blockers, or proxy the script through your own domain.
  • Read script troubleshooting for other causes.

Troubleshooting

  • Missing in production: run php artisan config:clear and php artisan view:clear after editing .env or config/services.php. Cached config and compiled views keep old values.
  • Missing locally: @production hides it unless APP_ENV=production.

Next steps

On this page