TagManager Service (original) (raw)

The Google Tag Manager service provides access to Tag Manager API data for an authorized user. This service lets Tag Manager users manage Tag Manageraccounts,containers,environments,versions,workspaces,folders,variables,triggers,tags, anduser permissions.

This is an advanced service that must be enabled before use.

Reference

For detailed information on this service, see the reference documentation for the Tag Manager API V2.

Like all advanced services in Google Apps Script, the Tag Manager service uses the same objects, methods, and parameters as the public API. For more information, seeHow method signatures are determined.

To report issues and find other support, see theGoogle Tag Manager help center.

Sample code

The following sample code demonstrates how to use a few features of the Tag Manager service.

Creates a container version with a variable, trigger, and tag.

The following sample code 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 these entities, logs the version and returns it for later use.

Publishes a container version and quick previews the current container draft.

The following sample code uses Tag Manager API V2to accept a container version that may have been created in the preceding 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.

The following sample code uses Tag Manager API V2to 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 following sample code uses Tag Manager API V2to 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.