ArtisanPack UI
DocsGoogle Tag ManagerFacade

Facade

Google Tag Manager v1.0.0

, aliased as in the app config, resolves the container binding — an instance of . All three return the same singleton. Returns the snippet renderer...

ArtisanPackUI\GoogleTagManager\Facades\GoogleTagManager, aliased as GoogleTagManager in the app config, resolves the container binding google-tag-manager — an instance of ArtisanPackUI\GoogleTagManager\GoogleTagManager.

Access patterns

use ArtisanPackUI\GoogleTagManager\Facades\GoogleTagManager;

// Via facade
$gtm = GoogleTagManager::getFacadeRoot();

// Via helper
$gtm = googleTagManager();

// Via container
$gtm = app( 'google-tag-manager' );

All three return the same singleton.

GoogleTagManager class

snippet(): SnippetRenderer

Returns the snippet renderer. Always available — the snippet installer works without the base package.

googleTagManager()->snippet()->render();

client(): ?TagManagerClient

Returns the Tag Manager API client, or null when the base package isn't installed. Callers should feature-detect via hasApi().

if ( googleTagManager()->hasApi() ) {
    $accounts = googleTagManager()->client()->listAccounts( $connection );
}

hasApi(): bool

Whether the server-side API surface is usable — true when the base package is installed and a TagManagerClient is bound.

Callers should prefer this over a null-check on client() because it re-runs BaseInstalled::check() on every call — that means it responds to BaseInstalled::setForTesting() flips in tests without cache-busting, and it stays honest when a downstream service provider fake-detaches the base at runtime.

Stay in the Loop

Monthly tips, tutorials and package updates — plus a free Quick Start cheat sheet.

Subscribe
Edit this page on GitHub