*Update: August 2020: The content of this article is not currently available for newly opened Shopify stores.
What is GTM (Google Tag Manager)?
This may not be necessary for those of you reading this article, but let me first give you an overview of Google Tag Manager (GTM).
Google Tag Manager is a service that allows you to centrally manage tags for Google Analytics, AdWords, and other measurement tools. Previously, you had to add tags directly to the html whenever you added a new tool, but with GTM, you only need to write tags in the html the first time, and you can centrally manage subsequent tag additions and deletions on GTM.
We will not go into detail about how to use and configure GTM itself, as this is outside the scope of this article.
How to set up GTM on Shopify
Now, here we get to the main topic.
Setting up and using GTM with Shopify requires some technical work. The reason is that Shopify has a default setting for Google Analytics, but no setting for GTM. So, I will explain step by step how to set up "what and where" (basically just copy and paste).
You will be switching back and forth between the GTM and Shopify sites, so it is easier to keep them open in separate tabs.
[1] Log in to the GTM page and select your account.
When the screen below appears, click on the container ID.
[2] When you click the container ID, a pop-up will appear with the source code you can paste into your website.
First, copy the entire contents of the box at the bottom.
[3] Next, go to the Shopify admin screen.
Click "Online Store" from the menu on the left, and select "Edit Code" from "Actions" for the theme you're currently using.
[4] Click on “theme.liquid” in the Layout folder to display its contents.
[5] Look for the opening tag of the body. When you find it, paste the code you copied earlier right after it and click the Save button.
[6] Return to the previous GTM screen.
This time, copy only the selected area in the top box.
[7] Go to the Shopify admin screen again.
Next, find the "Google Analytics" settings section in the "Various Settings" under Online Store and click on "Add Custom JavaScript."
[8] Paste the content copied in step 6 and click the Save button at the bottom of the page.
This completes the setup on Shopify.
How do I check my settings?
I would like to introduce a tool that can help you check whether GTM is set up and working correctly. It is a Chrome extension made by Google called " Tag Assistant (by Google) ". Please watch the video in the overview to learn how to use it.
The content introduced in this article is unofficial and not a method officially announced by Shopify. Please note that it may no longer work due to future changes in Shopify specifications.
Also, Shopify's Plus plan allows you to set up GTM by default, so if that doesn't work, please consider this option.