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 permission | What Tasks can do |
|---|---|
| Read | List and read tags, triggers, variables, workspaces and versions |
| Edit | Also create workspaces and create, update or delete tags, triggers and variables |
| Approve | Also create versions |
| Publish | Also 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
- Open Connectors → Google Tag Manager → Add Credential.
- Name the credential, for example after the site it manages, and select Connect Tag Manager.
- 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:
list_workspacesreturns the container's workspaces. A new container starts with one called Default Workspace. Free Tag Manager accounts allow three workspaces per container.create_tag,update_tagand the trigger and variable methods change entities in that workspace.update_tagreads the tag first and applies only the fields you pass, so to edit one setting insideparameter, pass the wholeparameterlist.get_workspace_statuslists the changes waiting in the workspace and any merge conflicts.create_versionturns the workspace into a version. Google then deletes that workspace and can return a new one innew_workspace_path.publish_versionmakes the version live. Pass the version'sfingerprintso 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_tokenback aspage_tokenfor the next one. - IDs are numbers.
container_idis the numeric container ID fromlist_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.