Google Tag Manager - v1.0.0
Installation
Install via Composer
composer require artisanpack-ui/google-tag-manager
The package auto-registers via Laravel's package discovery:
- Service provider:
ArtisanPackUI\GoogleTagManager\GoogleTagManagerServiceProvider - Facade alias:
GoogleTagManager(ArtisanPackUI\GoogleTagManager\Facades\GoogleTagManager)
The base artisanpack-ui/google package is pulled in as a hard dependency. You still need to publish its migrations and register your OAuth client — the Google base package page walks through that.
No manual changes to config/app.php are required in a standard Laravel app.
Publish the config (optional)
php artisan vendor:publish --tag=google-tag-manager-config
Publishes config/google-tag-manager.php. Override the container ID, snippet enable flag, API base URL / timeout / cache TTL, contributed scopes, or route prefix / middleware here. Full reference: Configuration.
Publish the views (optional)
php artisan vendor:publish --tag=google-tag-manager-views
Copies the Livewire component's Blade views to resources/views/vendor/google-tag-manager/. Only needed if you want to customize the container overview or tag list markup.
Publish the JS components (optional)
php artisan vendor:publish --tag=google-tag-manager-js
Copies the React and Vue component sources to resources/js/vendor/google-tag-manager/. Skip this step if you'd rather point your bundler at the package's resources/js/ directly. See Components.
Configure your container ID
The client-side snippet only needs a container ID:
GTM_CONTAINER_ID=GTM-XXXXXXX
Or in config/google-tag-manager.php after publishing:
'snippet' => [
'enabled' => true,
'container_id' => env( 'GTM_CONTAINER_ID' ),
],
Both enabled: false and a missing container ID cause @gtmSnippet, @gtmSnippetHead, @gtmSnippetBody, and the React/Vue snippet components to render nothing, so they're safe in shared layouts.
Set up the base google package
The server-side Tag Manager API and the Livewire/React/Vue admin components require the base artisanpack-ui/google package to be configured with an OAuth 2.0 client.
Follow the base package's documentation to:
- Publish and run its migrations:
php artisan vendor:publish --tag=google-migrations && php artisan migrate. - Enable the Tag Manager API in the Google Cloud Console, under APIs & Services → Library. This is separate from adding the scope — the API must be explicitly enabled on your Cloud project or all requests will 403.
- Add the
https://www.googleapis.com/auth/tagmanager.readonlyscope on the OAuth consent screen (this package contributes it automatically to the scope registry, but Google's consent screen must know it too). - Register your OAuth client ID / secret / redirect URI via your chosen credential driver.
Once a user is connected via the base package, this package's routes, Livewire components, and API client will function.
Apply route middleware (optional)
The package registers two web routes under google-tag-manager.routes.prefix (default /google-tag-manager) with [ 'web', 'auth' ] middleware. Adjust if your app needs tenant-scoped or admin-only routes:
// config/google-tag-manager.php
'routes' => [
'enabled' => true,
'prefix' => 'admin/gtm',
'middleware' => [ 'web', 'auth', 'can:view_tag_manager' ],
],
Set 'enabled' => false for headless / API-only apps that don't need the Livewire/React/Vue admin surfaces.
Route reference: HTTP Routes.
Verify the install
Run:
php artisan route:list --path=google-tag-manager
You should see:
GET google-tag-manager/container-overview google-tag-manager.container-overview
GET google-tag-manager/tags google-tag-manager.tags
And in a Blade view:
@gtmSnippet
If your container ID is set, view source should show the standard GTM <script> and <noscript> blocks.
Deeper topics
- Requirements — PHP, Laravel, and peer-package versions in full detail.
- Configuration — full
config/google-tag-manager.phpreference. - Environment variables — every env var the package reads.
- Google base package — what to configure on the base package for this integration to work.
Continue to Snippet Installer →