Google Tag Manager - v1.0.0

Livewire

Two Livewire 3 components ship with the package. Both extend Livewire\Component and use the shared HandlesTagManagerRefresh concern for connection detection and error handling.

google-tag-manager::container-overview

Renders the container overview panel: container name, public ID, workspace name, tag/trigger/variable counts, and the latest published version.

Mounting

<livewire:google-tag-manager::container-overview
    account-id="123456"
    container-id="654321"
    workspace-id="1" />

Props:

Prop Type Required Purpose
accountId string Yes GTM account ID.
containerId string Yes GTM container ID (numeric, not the public GTM-XXXX).
workspaceId string | null No Specific workspace. When null, the fetcher uses the default workspace.

Actions

  • refresh() — re-fetches from the API. Useful on a poll or after a user action.

Published state (Livewire-visible properties)

  • name, publicId, workspaceName
  • tagCount, triggerCount, variableCount
  • latestVersionName, latestVersionId (nullable — a container that has never been published has neither)
  • hasDatatrue once the initial fetch completes successfully
  • errorMessage — a human-readable string when the fetch fails
  • baseInstalledfalse when the base package isn't installed; the view renders a call-to-action

google-tag-manager::tag-list

Renders every tag in a workspace with client-side sort and pagination.

Mounting

<livewire:google-tag-manager::tag-list
    account-id="123456"
    container-id="654321"
    workspace-id="1" />

Props:

Prop Type Required Purpose
accountId string Yes GTM account ID.
containerId string Yes GTM container ID.
workspaceId string Yes Workspace ID — required (unlike container overview).

Actions

  • refresh() — re-fetches the tag list from the API.
  • sortByColumn( string $column ) — sorts by name, type, or status. Second click on the same column flips direction. Unknown columns are ignored.
  • nextPage() / previousPage() — client-side pagination over the already-fetched rows.

Published state

  • rows — the full list of tags with firing triggers already joined by name
  • sortBy, sortDir, page, perPage — the visible sort / pagination state
  • errorMessage, baseInstalled — same semantics as the container overview

The paginated / sorted view is computed in render() and passed to the view as $visibleRows and $totalPages — the $rows array is never mutated by sort or pagination.

Customizing the views

Publish the views:

php artisan vendor:publish --tag=google-tag-manager-views

The templates land at resources/views/vendor/google-tag-manager/livewire/. Edit them freely — the Livewire class contract stays the same, so your custom markup drives the same actions.

Testing

Use Livewire's test helpers:

use Livewire\Livewire;

Livewire::test( 'google-tag-manager::tag-list', [
    'accountId'   => '1',
    'containerId' => '2',
    'workspaceId' => '3',
] )
    ->assertSet( 'baseInstalled', true )
    ->call( 'sortByColumn', 'name' )
    ->assertSet( 'sortDir', 'asc' );

See Testing for the full test setup including how to stub the TagManagerClient so tests don't hit the network.