Blog Logo

15 August 2024 ~ 3 min read

How to cleanup your GTM container in 30 seconds


sweepy bot

How to use native GTM functionality to remove all unused triggers/variables quickly.

GTM containers naturally build up a lot of clutter through daily updates. Stakeholders are usually very quick when it comes to requesting new vendor implementations, but a lot slower when it comes to removing unused ones.

And when an unused vendor is removed, or a vendor is updated, the variables and triggers that were used are often left gathering dust.

Maintaining a clean container has several benefits:

A smaller JS file for the website to load. Less code running means a faster site. A cleaner workspace. This solution will remove all variables/triggers/templates that aren’t in use. If these resources are being used by a paused tag, they won’t be touched.

Steps to follow: In GTM go to Admin -> Export Container. Select your current workspace. step 1

  1. When you first open this option everything will be selected. Click the box to de-select everything.

  2. Select all tags. You can do this quickly by searching for ‘tag’ and then click the box to select all. Just make sure you don’t have any templates/variables with the name ‘tag’ included. step 2

  3. Click Export in the top right corner. Then click cancel when the popup appears: step 3

  4. A red bar will have now appeared stating “Missing References- Some required references are not selected and will not be exported”. Click the ‘Add All’ button. alt text

  5. After clicking this, GTM will have automatically selected all dependencies that your tags have. We can see how many triggers/variables/templates are actually in use. Click ‘Export’ to download the JSON, we will need this for the next step! alt text

  6. With your JSON file downloaded, close this window and now open ‘Import Container’ from the same menu:

  7. Click ‘Choose Container File’ and select the JSON we just created. For the workspace you can either use the existing or make a new workspace called ‘Cleanup’ for example. Leave the import option on ‘Overwrite’ – this is important! alt text

  8. GTM will now calculate the differences and show the changes that will be made by making the import. This should be deleting all of the resources that currently aren’t in use. alt text

N.B – If you are using templates from the gallery that aren’t up to date, GTM will now update them. It does this by deleting the template and recreating it. Any tags/variables making using of it will also be deleted and recreated with the new version. In this case, we can see that the Unique Event ID from Stape was out of date and is now being updated: alt text

  1. Hit confirm and you are done! Anything currently not being used will now have been deleted.

As always – be sure to check the changes carefully before publishing.


George Clements

Hi, I'm George. I'm a software engineer and data analyst based in Munich. You can connect with me via Linkedin, and see some of my work on GitHub,