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.
-
When you first open this option everything will be selected. Click the box to de-select everything.
-
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.
-
Click Export in the top right corner. Then click cancel when the popup appears:
-
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.
-
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!
-
With your JSON file downloaded, close this window and now open ‘Import Container’ from the same menu:
-
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!
-
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.
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:
- 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.