Build a GTM container report with Apps script

Business Benefits

Remove manual processes from your workflow by automating tasks.

Create a new Google Sheet, enter the Script Editor via the Tools menu, and name the project.

Don’t close the browser tab with the Google Sheet, or the Script Editor will close as well.

Click the + icon by Services in the editor navigation, select Tag Manager API, and click Add.

Add Tag Manager API to the project

Copy the Apps script source code and replace everything in the Script Editor file with the source code.

Copy the source code and replace everything in the Script Editor file.

Select onOpen from the list of script functions, then click Run to execute the extension code and add it to the Sheets Add-ons menu.

Select onOpen and then click Run

Authorize the Google Sheet to access your Google Tag Manager container.

Click through the prompts to authorize the Sheet’s access to your GTM container. If you see a warning about an unverified app, expand the error message and click the link that says Proceed.

Go back to the browser tab with the Google Sheet and locate your add-on in the Add-ons menu once the script has run successfully.

The name of the Add-on will be whatever you named the project.

Click the Build Hierarchy option in the Add-ons menu to automatically create a new sheet named GTM Hierarchy populated with the Google Tag Manager accounts and containers you have access to.

If you run into a quota or query limit error, log in with a Google Account that has access to a smaller number of containers.

Last edited by @hesh_fekry 2023-11-14T15:10:37Z