Disclosure: Please note that this article may contain affiliate links. You can read my full disclosure here.Need help with the Tech-side of blogging? Join my Facebook Group and get some answers.
If you are like me you may have been playing around in Google Tag Manager. The full featured web application by Google to help you manage your website. While playing around or testing things out you may end up adding several different tags, triggers or variables and now you need a quick method to clean it all up.
I first starting using Google Tag Manager last May, when the GDPR rules went into enforcement, so I could control when cookies would be fired and applied to visitors computers. If you are curious about being compliant for GDPR, I highly recommend that you check out Lucrenzia’s GDPR Compliance course., I was a complete wreck at first as I had believed so much hype that was not true. She set me straight and I updated my rules to be less strict – so that all our sites meet the GDPR guidelines, but still can function correctly.
But it is so cumbersome to try to delete tags, triggers, variables – the objects of Google Tag Manager. You have to click into the objects one at a time, click delete, save, then go back to the main screen to click into the next.
I am trying to prepare a generic container with just the basic starter tags so I can share this awesome tool with others who are just learning. Trying to clear out all my site specific items before I found the bulk method took hours.
Then I went to export the container and I noticed and thought to myself “Hey, this is just a JSON file, I bet we can edit this”… I was off and running. My first edit, I must have been too eager, turned out I was missing one comma or maybe a bracket somewhere that was making the new file invalid. My first thought was that I was on the wrong track and that maybe we cannot edit this file afterall.
But, I started over and tried again. This time, testing on the follow JSON validator site:https://json-csv.com/editor after the first, second, fifth edits and each time coming back valid. Okay. So maybe this is possible.
I tested importing my updated JSON file into Google Tag Manager and low and behold, it was accepted and applied the changes.
I went back to the JSON file and finished deleting the objects I no longer needed and within 10-15 minutes time I had deleted and cleaned up my Tag Manager container and the changes were applied, then imported once more to Google Tag Manager.
Steps to bulk edit Google Tag Manager GTM Tags
- First you need to export your current GTM Container
- Click on Admin tab on the upper menu
- Choose your Version of Workspace that you want to export
- Lastly click the Export button
This way you have the original to go back to if something goes wrong.
The objects all start and end on the same indentation. So in this case if you look at the code for the example tag, delete from the opening bracket (first highlight) to the last bracket (last highlight).
Next copy and paste your code into the html textbox to test your code on the JSON validator https://json-csv.com/editor, to make sure your code is still valid.
If your file is still valid, then continue on through the JSON file, checking after every few changes again.
Note: If any tags depend on a specific trigger, you cannot delete the trigger with this method — unless you first clear the dependency on the tag, that may be more complicated. But, play around and test with the validator.
Now that your changes are done and verified in the validator. Import your edited JSON file into Google Tag Manager.
Now that your updated container is uploaded to Google Tag Manager, test to make sure that the tags are firing. Preview your space and/or test with the Chrome extension Tag Assistant.