Google Tag Manager - v1.0.0

Tag Manager Client

ArtisanPackUI\GoogleTagManager\Api\TagManagerClient wraps the Tag Manager API v2.

Registered as a singleton. Requires the base artisanpack-ui/google package to be installed and a connected GoogleConnection for every call.

use ArtisanPackUI\Google\Models\GoogleConnection;
use ArtisanPackUI\GoogleTagManager\Api\TagManagerClient;

$client = app( TagManagerClient::class );
$connection = GoogleConnection::query()->where( 'user_id', auth()->id() )->first();

$accounts = $client->listAccounts( $connection );

Availability

isAvailable(): bool

true when the base package is installed and a TokenManager is bound. false otherwise — callers that don't check this and try to make a request will get BaseNotInstalledException.

Listing

Every list method takes a connection and returns a list of typed DTOs. Pagination via nextPageToken is handled transparently — you get every result in one call.

listAccounts( GoogleConnection $connection ): list<AccountData>

listContainers( GoogleConnection $connection, string $accountId ): list<ContainerData>

listWorkspaces( GoogleConnection $connection, string $accountId, string $containerId ): list<WorkspaceData>

listTags( GoogleConnection $connection, string $accountId, string $containerId, string $workspaceId ): list<TagData>

listTriggers( GoogleConnection $connection, string $accountId, string $containerId, string $workspaceId ): list<TriggerData>

listVariables( GoogleConnection $connection, string $accountId, string $containerId, string $workspaceId ): list<VariableData>

latestVersionHeader( GoogleConnection $connection, string $accountId, string $containerId ): ?ContainerVersionHeaderData

Returns the published version header, or null when the container has never been published.

Caching

Successful responses are cached at google-tag-manager.api.cache_ttl seconds (default 300) using the app's default cache store. Cache keys include the connection ID so each user has their own view.

Set cache_ttl to 0 in config to disable caching entirely.

Error handling

Every network or upstream failure surfaces as ArtisanPackUI\GoogleTagManager\Exceptions\ApiException:

  • getMessage() — a human-readable error string
  • $status — public readonly int property; HTTP status code when the failure came from the upstream API, null on transport / config / connection failures

Common cases:

  • 401 — token invalid; ask the user to reconnect via the base package
  • 403 — Tag Manager API not enabled on the Cloud project, OR user doesn't have access to the container
  • 404 — account/container/workspace ID doesn't exist
  • 429 — rate limit; back off and retry

When the base package's TokenManager throws TokenRefreshException, it's re-wrapped as ApiException with the same message.

When the base package is missing, calls throw BaseNotInstalledException before any HTTP request is made.