Skip to main content

Connect Google Tag Manager

Sign in with Google to let qbash Tasks read your Tag Manager containers and change the tags, triggers and variables in a workspace. Tasks can also create and publish versions.

Check your Tag Manager permissions​

The connector acts as the Google account you sign in with, so it reaches the Tag Manager accounts and containers that account can open, at the permission level it has in each one. In Tag Manager, open Admin → Container User Management to see it:

Container permissionWhat Tasks can do
ReadList and read tags, triggers, variables, workspaces and versions
EditAlso create workspaces and create, update or delete tags, triggers and variables
ApproveAlso create versions
PublishAlso publish versions

A call above the account's permission fails with a 403 error for that container. The credential keeps working for everything else.

Add the credential in qbash​

  1. Open Connectors → Google Tag Manager → Add Credential.
  2. Name the credential, for example after the site it manages, and select Connect Tag Manager.
  3. Sign in with Google and allow the four Tag Manager permissions Google lists: view containers, manage containers, manage container versions and publish container versions.

Until Google finishes verifying qbash for these permissions, the sign-in screen shows a warning that Google hasn't verified the app.

Read what is live​

Select the credential under your Task's Tools → Integrations. Find the numeric IDs with list_accounts and list_containers, or look a container up by the GTM- ID in its snippet:

container = qbash.integrations.google_tag_manager.lookup_container(tag_id="GTM-QB4SH12")["container"]
live = qbash.integrations.google_tag_manager.get_live_version(
account_id=container["accountId"],
container_id=container["containerId"],
)
qbash.output([tag["name"] for tag in live["version"].get("tag", [])])

Results keep Google's field names (tagId, firingTriggerId, parameter), so a tag you read can be changed and passed back. See the SDK Reference for every method.

Change tags and publish​

Changes go into a workspace and reach the site only when a version is created and published:

  1. list_workspaces returns the container's workspaces. A new container starts with one called Default Workspace. Free Tag Manager accounts allow three workspaces per container.
  2. create_tag, update_tag and the trigger and variable methods change entities in that workspace. update_tag reads the tag first and applies only the fields you pass, so to edit one setting inside parameter, pass the whole parameter list.
  3. get_workspace_status lists the changes waiting in the workspace and any merge conflicts.
  4. create_version turns the workspace into a version. Google then deletes that workspace and can return a new one in new_workspace_path.
  5. publish_version makes the version live. Pass the version's fingerprint so Google refuses the publish if someone changed the version after your Task read it.

To roll back, publish an earlier version from list_version_headers.

Seed test data​

Create a separate container for testing in Tag Manager (Admin → Create Container, target platform Web) and point it at a page you control, or leave it uninstalled. Add a Google tag and a Click trigger in the Default Workspace, then create and publish one version so get_live_version has something to return. Run writes against that container before you run them on a site's real container.

Limits​

  • Google allows 25 Tag Manager API requests per 100 seconds for each app, and every qbash connection shares that allowance. Beyond it, calls fail with a quota error. Wait a minute before retrying, and have Tasks that audit many containers read only the versions they need.
  • List methods return one page. Pass next_page_token back as page_token for the next one.
  • IDs are numbers. container_id is the numeric container ID from list_containers, not the GTM- public ID.
  • The connector can't delete containers, manage users or change account settings. Do those in the Tag Manager web app.