Looking to hire Laravel developers? Try LaraJobs

laravel-gtm-load-logger maintained by hadiabedzadeh

Description
Log the real loading status of Google Tag Manager directly into your Laravel database.
Author
Hadi Abedzadeh
Last update
2026/07/07 10:53 (dev-main)
License
Links
Downloads
0

Comments
comments powered by Disqus

Laravel GTM Load Logger

Log the real loading status of Google Tag Manager directly into your Laravel database.

This package helps you detect when GTM:

  • loads successfully
  • fails due to network, DNS, or AdBlock
  • times out
  • partially loads

It is useful for debugging analytics issues in countries where GTM may be blocked or unstable.

Installation

composer require hadiabedzadeh/laravel-gtm-load-logger

Publish config and migration

php artisan vendor:publish --tag=gtm-load-logger-config
php artisan vendor:publish --tag=gtm-load-logger-migrations
php artisan migrate

Environment

GTM_LOAD_LOGGER_ENABLED=true
GTM_LOAD_LOGGER_ID=GTM-W8W7BWH
GTM_LOAD_LOGGER_TIMEOUT=7000
GTM_LOAD_LOGGER_TABLE=gtm_load_logs
GTM_LOAD_LOGGER_ROUTE_PREFIX=gtm-load-logger

Usage

Put this inside your main Blade layout <head>:

@include('gtm-load-logger::script')

Put this immediately after <body> if you also want the normal GTM noscript fallback:

@include('gtm-load-logger::noscript')

Route

The package automatically registers:

POST /gtm-load-logger/log
GET  /gtm-load-logger/log

Route name:

route('gtm-load-logger.log')

Logged fields

The package stores:

  • GTM ID
  • status: success, partial, error, timeout, unknown
  • reason
  • page URL
  • user agent
  • visitor IP
  • noscript flag
  • timestamps

Example SQL analytics

SELECT
    COUNT(*) AS total,
    SUM(CASE WHEN status = 'success' THEN 1 ELSE 0 END) AS success,
    SUM(CASE WHEN status <> 'success' OR status IS NULL THEN 1 ELSE 0 END) AS failed,
    ROUND(100.0 * SUM(CASE WHEN status = 'success' THEN 1 ELSE 0 END) / COUNT(*), 2) AS success_percent,
    ROUND(100.0 * SUM(CASE WHEN status <> 'success' OR status IS NULL THEN 1 ELSE 0 END) / COUNT(*), 2) AS failed_percent
FROM gtm_load_logs;

SQL Server table

Laravel migration is recommended. If you want a manual SQL Server table:

CREATE TABLE [dbo].[gtm_load_logs](
    [id] [bigint] IDENTITY(1,1) NOT NULL,
    [gtm_id] [nvarchar](50) NULL,
    [status] [nvarchar](20) NOT NULL,
    [reason] [nvarchar](max) NULL,
    [url] [nvarchar](max) NULL,
    [user_agent] [nvarchar](max) NULL,
    [ip] [varchar](45) NULL,
    [noscript_enabled] [bit] NOT NULL CONSTRAINT [DF_gtm_load_logs_noscript_enabled] DEFAULT 0,
    [created_at] [datetime2](7) NULL,
    [updated_at] [datetime2](7) NULL,
    PRIMARY KEY CLUSTERED ([id] ASC)
);

Packagist publishing checklist

  1. Create a GitHub repository, for example: hadiabedzadeh/laravel-gtm-load-logger
  2. Push this package code.
  3. Create a release tag:
git tag v1.0.0
git push origin v1.0.0
  1. Submit the GitHub repository URL in Packagist.
  2. Install it in Laravel projects:
composer require hadiabedzadeh/laravel-gtm-load-logger

License

MIT