AI-generated Key Takeaways
-
The Google Tag Manager service allows authorized users to manage various aspects of their Tag Manager accounts programmatically via the Tag Manager API.
-
This advanced service enables users to create, update, and manage accounts, containers, workspaces, tags, triggers, variables, and user permissions.
-
Developers can use Apps Script to interact with the Tag Manager API, leveraging its objects, methods, and parameters for automating Tag Manager tasks.
-
Sample code is provided to demonstrate how to create and publish container versions, manage environments, and control user permissions.
-
For detailed information and support, refer to the Tag Manager API V2 reference documentation and the Google Tag Manager help center.
The Google Tag Manager service provides access to Tag Manager API data for an authorized user. This service allows Tag Manager users to manage Tag Manager accounts, containers, environments, versions, workspaces, folders, variables, triggers, tags, and user permissions.
Reference
For detailed information on this service, see the reference documentation for the Tag Manager API V2.
Like all advanced services in Apps Script, the Tag Manager service uses the same objects, methods, and parameters as the public API. For more information, see How method signatures are determined.
To report issues and find other support, see the Google Tag Manager help center.
Sample code
The sample code below demonstrates how to use a few features of the Tag Manager service.
Creates a container version with a variable, trigger, and tag.
The sample code below uses Tag Manager API V2 to
first create a container with a name that is timestamped with the current date
to improve the chances of it being unique. The sample then creates a workspace
with a random value variable, and a trigger that fires for any page view. Next,
the sample uses the trigger to create an arbitrary pixel tag that fires a pixel
to //example.com
with a cache buster appended to the end of the URL. Last, the
sample creates a container version with the above entities, logs the version and
returns it for later use.
Publishes a container version and quick previews the current container draft.
The sample code below uses Tag Manager API V2 to accept a container version that may have been created in the above example, and retrieve the account, container, and version ids from the version. The sample utilizes these ids to publish a container version live to the world. Last, the sample creates a quick preview of a new workspace and logs the quick preview.
Creates and reauthorizes a user environment.
The sample code below uses Tag Manager API V2 to accept a container version and extract the account, container, and version ids. The sample utilizes these ids to create a user environment that points to the input container version and logs the user environment. The sample concludes by logging a reauthorized user environment.
Logs all emails and container access permissions within an account.
The sample code below uses Tag Manager API V2 to find a list of all permissions within a Tag Manager account. The sample then logs the user's email address, the container id, and the types of container access permissions for each entry.