GTM Template Uploader
This skill uploads a GTM custom template file (.tpl) to a Google Tag Manager container.
Workflow
- •
Identify Target:
- •Ask the user for the GTM Account ID, Container ID, and Workspace ID.
- •Alternatively, the user can provide a GTM URL like
https://tagmanager.google.com/#/container/accounts/4701768861/containers/32205981/workspaces/29. Parse the Account, Container, and Workspace IDs from this URL. - •If the user only provides a name (e.g., "demo analytics pioneers ssgtm account"), use the
gtm accounts listcommand to find the Account ID. Then, usegtm containers listandgtm workspaces listto find the remaining IDs.
- •
Set Defaults:
- •Once all IDs are confirmed, use
gtm config setto set thedefaultAccountId,defaultContainerId, anddefaultWorkspaceId. This simplifies subsequent commands.
- •Once all IDs are confirmed, use
- •
Identify Template File:
- •Ask the user for the path to the
.tplfile they want to upload.
- •Ask the user for the path to the
- •
Check for Existing Template:
- •Before uploading, check if a template with the same name already exists in the workspace.
- •The template name is the
displayNamefrom the___INFO___section of the.tplfile. Parse the file to get this name. - •Run
gtm templates listand check if any of the existing templates have a matching name.
- •
Create or Update:
- •If the template exists: Use the
gtm templates updatecommand. You will need thetemplateIdfrom thelistcommand.bashgtm templates update --template-id <TEMPLATE_ID> --template-data "$(cat <FILE_PATH>)"
- •If the template does not exist: Use the
gtm templates createcommand.bashgtm templates create --name "<TEMPLATE_NAME>" --template-data "$(cat <FILE_PATH>)"
- •Note on
Promise.create: The local test environment might requirenew Promiseinstead ofPromise.create. Before uploading, ensure the.tplfile usesPromise.createas this is the correct API for the GTM online environment.
- •If the template exists: Use the
Session Persistence
Once the Account, Container, and Workspace IDs are set as defaults, you must continue to use them for all subsequent gtm-cli commands in the current session. Do not ask for these IDs again unless the user explicitly asks to target a different account or container.