GTM recipes could not exist without export and import features within Google Tag Manager. The ability to extract container’s data as a portable file helps us manage multiple containers, make bulk changes, etc., therefore, makes the work process with GTM much faster.
In this guide, I’ll show you everything you need to know about how to export and import Google Tag Manager container.
Why Is Container Import Useful?
There are several reasons why you should consider using container import in Google Tag Manager:
- Implementing the same tags, triggers, and variable in multiple GTM containers. For example, imagine a healthcare company that has 10 websites which look very similar, and each has its own container. There are two ways you can go:
- You manually do all the changes in GTM and repeat that process 10 times (because there are 10 containers)
- Or you fully set up one container, then export it and import in other 9 containers (+ do minor adjustments, e.g. change Google Analytics Tracking ID). Obviously, this option is the best option.
- Importing new tags, variables, and triggers that have been shared with you. Maybe a colleague has prepared an awesome template that he/she uses for their projects and saves a lot of time.
- Importing ready-made solutions which are available online. I’m talking about GTM recipes (here’s a large collection of them).
- You’re maintaining separate GTM containers in different environments, like a development or staging site, and you want to export data from one environment and import to another.
How to Import Google Tag Manager Container?
#1. Go to GTM container’s Admin section and click Import Container.
#2. Choose container file (JSON) of the container you wish to import. You can get container files from the Library of GTM Recipes, your coworkers, etc.
#3. Choose the workspace that you want to import the file to. If you have no clue what a workspace is, chances are that you’re using only a default one. In that case, click the button Existing under the “Choose workspace” and select “Default workspace”.
If you want to learn more about workspaces, read Simo’s guide.
#4. Choose the import option:
- Overwrite
- Or merge
Overwrite option will delete ALL existing tags, triggers, and variables and import everything that is stored in the container’s JSON file (that you’re trying to import). One of the use cases for this option: a recipe that clears the GTM container.
Merge option will let you keep your existing tags, triggers, and variables, and just add the new ones. If you choose this path, you’ll have to decide what to do with the conflicting tags (which are of the same name). GTM will give you two options:
- Overwrite. If a variable, tag, or trigger in the new container has the same name but the content is different, GTM will remove the old one and insert the new one.
- Rename. If a variable, tag, or trigger in the new container has the same name but the content is different, GTM will keep the old one and rename the new one (think of it as if you were copying a folder on your laptop: folder’s title will change to something like Copy of Important Folder (2)).
Depending on which option you choose, Google Tag Manager will show a quick preview of how tags, triggers, and variables will be saved or removed from the container.
You can also click the View Detailed Changes link to see titles of container’s assets.
#5. Finally, click Confirm button to finalize the import process.
Done! Hit Preview button and test the updates you’ve just imported. If you see an error saying something about {{YOUR_GA_TRACKING_ID}}, read the following chapter to learn the solution.
For Universal Analytics: Change Google Analytics ID in the Imported Container
IMPORTANT: if you have imported a recipe that is related to Google Analytics 4, skip to this chapter.
If you’ve downloaded a Google Tag Manager Recipe which contains at least one Universal Analytics Tag, you’ve probably seen its installation instructions saying something about {{YOUR_GA_TRACKING_ID}}.
This is really important because you need to set the GA Tracking ID in every GA tag within Google Tag Manager. Otherwise, how will GTM know where should it send the tracking data?
There are two ways how you should set the Tracking ID and I’ll explain them both:
- By inserting a Constant Variable called YOUR_GA_TRACKING_ID
- Or by using Google Analytics Settings Variable
Using Constant Variable. In order to create a Constant Variable, go to Variables in your GTM account, scroll down to User-defined section and click New button.
Choose Variable Type Constant and enter the following settings:
Make sure that the variable’s name is exactly as I’ve displayed in the screenshot above (all letters are uppercase). In Value field enter your Google Analytics Tracking ID.
After you’ve completed these steps, refresh the GTM Preview mode and test all changes on the website.
Using Google Analytics Settings Variable. This method is recommended as it will save you more time in the future. If you’re new to GA Settings Variable, read this guide first and create one.
Now, let’ insert it in the GA Tag that you’ve imported from the JSON file. First, open the GA tag. It might look something like this:
The majority of settings (e.g. Track-Type) might be different but that doesn’t make any difference since we’re interested just two fields, Google Analytics Settings drop-down and the checkbox that comes after it.
- Select GA Settings Variable in the Google Analytics Settings drop-down.
- Untick the Enable overriding settings in this tag.
The final result should look like this (in your case, the title of GA Settings Variable might be different).
Important! Double-check if you’ve set GA Settings Variable in the correct field. It’s a pretty common mistake among beginners to insert the Settings Variable in the Tracking ID field.
This will never work. Tracking ID field supports only values of the following structure: UA-XXXXXXX-XX.
Google Analytics Settings Variable must be inserted ONLY in the GA Settings drop-down.
Does the recipe contain GA4 tags?
If the recipe that you have imported is using Google Analytics 4, you will have to select your existing GA4 configuration tag in the GA4 event tags of that recipe. For example, if you have imported an HTML5 video tracking recipe for GA4, you will see an event tag that looks like this:
In the “Configuration tag” field, you have to select your current GA4 config tag (that you are already using in your container). New to this? Then read a blog post on how to install Google Analytics 4 with GTM.
How to Export Google Tag Manager Container?
In the Admin section of GTM, just beneath the Import Container option, there is also an Export Container option. Clicking on it will let you select a container version, a workspace, and then it will generate the JSON file needed to import into another container.
Keep in mind that this feature will always export the entire container, therefore do not keep unwanted tags, triggers or variables in the container during the export.
If you want to export only a part of the container, I’ve explained a workaround by using Simo Ahava’s GTM Tools. Here’s a full guide to that.
Also, you can get a ready-made container from the Library of Google Tag Manager Recipes.
