Here is the steps to add Google Tag Manager to Shopify.
Google Tag Manager (GTM) offers numerous benefits for tracking events in Shopify eCommerce stores, including easy management of tracking codes, faster website loading, improved data collection, customization, seamless integration with other Google tools, collaboration, and version control.
By using GTM, you can gain valuable insights into customer behavior, enhance your website's performance, and make data-driven decisions to grow your business—all while managing tags efficiently and reducing the risk of errors.
Steps To Add Google Tag Manager To Shopify
Sign up for Google Tag Manager: Go to https://tagmanager.google.com/ and sign up for a free account. If you already have an account, sign in.
Create a new container: After signing in, click "Create Account" and enter your account name. Then, click "Continue." Next, click "Create Container," enter your Shopify store's name, and choose "Web" as the target platform. Click "Create" and accept the terms of service.
Get your container code: You'll see a popup with two code snippets. Copy the first code snippet (starting with "<!-- Google Tag Manager -->").
Add the code to your Shopify store: Log in to your Shopify account. Go to "Online Store" > "Themes." Click "Actions" > "Edit code." Open the "theme.liquid" file. Paste the code snippet right after the opening "<head>" tag. Save your changes.
Add the second code snippet: Go back to the Google Tag Manager popup and copy the second code snippet (starting with "<!-- End Google Tag Manager -->"). In your Shopify "theme.liquid" file, paste this code right after the opening "<body>" tag. Save your changes.
Set up triggers: In Google Tag Manager, triggers are events that cause tags to fire. For our purpose, we'll set up triggers for "Add to Cart," "Order Submission," and "Email Submit."
Add to Cart trigger: In Google Tag Manager, click "Triggers" > "New" > "Trigger Configuration" > "Click - All Elements." Name the trigger "Add to Cart Click." Choose "Some Clicks" and set the conditions: "Click Element" matches CSS Selector ".add-to-cart". Save the trigger.
Order Submission trigger: Create a new trigger, name it "Order Submission Click," and choose "Click - All Elements." Select "Some Clicks" and set the conditions: "Click Element" matches CSS Selector "input[type='submit'][name='checkout']". Save the trigger.
Email Submit trigger: Create another new trigger, name it "Email Submit Click," and choose "Click - All Elements." Select "Some Clicks" and set the conditions: "Click Element" matches CSS Selector "input[type='submit'][name='subscribe']". Save the trigger.
Create tags: In Google Tag Manager, tags are pieces of code that execute when triggers fire. For our purpose, we'll create tags for Google Analytics to track the events.
Add to Cart tag: Click "Tags" > "New" > "Tag Configuration" > "Google Analytics: Universal Analytics." Choose "Event" as the track type. Enter "Add to Cart" as the event category, "Click" as the event action, and "{{Click Text}}" as the event label. Under "Google Analytics Settings," enter your Google Analytics tracking ID. Choose the "Add to Cart Click" trigger and save the tag.
Order Submission tag: Repeat the process for the "Order Submission" event. Use the "Order Submission Click" trigger and save the tag.
Email Submit tag: Repeat the process for the "Email Submit" event. Use the "Email Submit Click" trigger and save the tag.
Publish your changes: Click "Submit" in Google Tag Manager and then "Publish" to make your changes live.
Now your Shopify store has Google Tag Manager set up to track "Add to Cart," "Order Submission," and "Email Submit" events.