Google Ads Purchase Event Conversion Tracking on Shopify using Google Tag Manager
by ShahzadaAliHassan - 6th February 2024
Introduction
Conversion tracking is crucial for e-commerce businesses to measure the success of their campaigns and understand customer behavior. In this guide, we will walk you through configuring Google Tag Manager (GTM) and Google Ads conversion tracking specifically for a Shopify store. This step-by-step tutorial covers setting up GTM, creating data layers, and configuring tags and triggers to accurately track purchase events.
Step 1: Adding Google Tag Manager to Shopify
Get GTM Snippets
- Access Google Tag Manager: Log in to your GTM account and select your container.
- Copy GTM Snippets:
- Click on the container ID in the top right corner.
- Copy the
head
tracking snippet.
Integrate with Shopify
- Navigate to Shopify Admin:
- Go to
Online Store
>Themes
. - Click
Actions
on your current theme and selectEdit Code
.
- Go to
- Insert Snippets:
- In the
theme.liquid
file, find the opening<head>
tag and paste thehead
snippet just below it. - Similarly, find the opening
<body>
tag (usually around line 294) and paste thebody
snippet below it. - Click
Save
.
- In the
Add GTM to Checkout Page
- Go to Shopify Settings:
- Navigate to
Settings
>Checkout
.
- Navigate to
- Insert Snippet in Order Status Page:
- Scroll down to
Order Status Page
and paste both thehead
andbody
snippets. - Click
Save
.
- Scroll down to
Step 2: Verify GTM Installation
- Enter Preview Mode in GTM:
- Click the
Preview
button in GTM to enter debug mode.
- Click the
- Test on Shopify:
- Open your Shopify store and navigate through various pages.
- Ensure the GTM debug window shows that GTM is firing correctly on all pages, including the thank you page after a purchase.
Step 3: Creating Conversion Action in Google Ads
-
Log in to Google Ads:
- Navigate to
Tools
&Settings
>Measurement
>Conversions
.
- Navigate to
-
Create New Conversion Action:
- Click the
+
button to create a new conversion. - Select
Website
and enter your website URL. - Since the purchase event is under the sales category, select
Purchase
. - Configure conversion settings, including the conversion name (e.g., Purchase), value, and any other required details.
- Click
Save and Continue
.
- Click the
-
Obtain Conversion ID and Label:
- Select the option to use Google Tag Manager.
- Copy the
Conversion ID
andConversion Label
.
Step 4: Configure Variables in GTM
- Create User-Defined Variables:
- In GTM, go to
Variables
and create two new variables:- Google Ads Conversion ID: Paste the conversion ID.
- Google Ads Conversion Label: Paste the conversion label.
- In GTM, go to
Step 5: Adding Data Layer Code to Shopify
The provided code snippets aim to integrate the dataLayer
object for Google Tag Manager (GTM) with a Shopify store. The main goal is to send an event called custom_purchase
whenever a user visits the final /thank-you/ page on Shopify after making the payment.
Order Status DataLayer Code
- This script, embedded within a Shopify platform, serves to track purchase-related data for analytics purposes.
- When a user accesses a site for the first time (
first_time_accessed
), the script checks if the user is a registered customer. If so, it fetches the user's order count and total spend. - The script then initializes the
dataLayer
object if it doesn't already exist and populates it with purchase details like transaction ID, total value, shipping, tax, currency, and details of items in the order. - These details include individual product attributes such as the product's ID, SKU, name, price, brand, variant, quantity, and other related info.
Steps to Add the DataLayer Code Snippets in Shopify:
-
Log into Your Shopify Admin Panel:
- Visit your Shopify store's URL followed by
/admin
. - Enter your login credentials to access the admin panel.
- Visit your Shopify store's URL followed by
-
Access Checkout Settings:
- On the left-hand side menu, click on
Settings
. - From the dropdown, select
Checkout
.
- On the left-hand side menu, click on
-
Locate the Additional Scripts Section:
- Scroll down until you find the
Order processing
section. - Within this section, you'll see a text box labeled
Additional Scripts
. This is where you can add scripts that will run on the order status page after a customer completes their purchase.
- Scroll down until you find the
-
Paste Your Script:
- Copy the script you have.
- Paste it into the
Additional Scripts
text box.
-
Save Changes:
- After you've pasted your script, scroll to the bottom of the page and click on the
Save
button.
- After you've pasted your script, scroll to the bottom of the page and click on the
-
Test the Script (Important):
- After saving, make a test purchase to ensure that the script runs as expected on the order status page.
- Check if all data is being collected and pushed to the
dataLayer
as intended by your script.
Note: The Additional Scripts section in the Checkout settings allows you to add scripts that will run after a customer has completed their purchase. This is a safe place to add conversion tracking codes, analytics scripts, or other scripts you want to trigger once a sale is confirmed.
Step 6: Test Data Layer Implementation
- Simulate a Purchase:
- Add a product to the cart and proceed to checkout.
- Complete the purchase using test details (e.g., bogus credit card details for Shopify's test mode).
- Check Data Layer in GTM Debug Mode:
- Ensure the data layer contains all necessary information, such as purchase details and user information, on the thank you page.
Step 7: Create Tags and Triggers in GTM
Create Trigger for Purchase Event
- Create Custom Event Trigger:
- In GTM, go to
Triggers
and create a new trigger. - Name it
Custom Event - Purchase
. - Set the trigger type to
Custom Event
and entercustom_purchase
as the event name. - Save the trigger.
- In GTM, go to
Create Conversion Linker Tag
- Create Conversion Linker Tag:
- In GTM, go to
Tags
and create a new tag. - Select
Google Ads Conversion Linker
. - Name the tag
Google Ads Conversion Linker
and save it. - Set the trigger to fire on all pages.
- In GTM, go to
Create Purchase Conversion Tracking Tag
- Create Google Ads Conversion Tracking Tag:
- In GTM, go to
Tags
and create a new tag. - Select
Google Ads Conversion Tracking
. - Use the previously created variables for the Conversion ID and Conversion Label.
- Map the necessary data layer variables (e.g., transaction value, transaction ID, currency) to the appropriate fields.
- Set the trigger to fire on the
Custom Event - Purchase
trigger. - Save the tag.
- In GTM, go to
Step 8: Final Testing and Publishing
- Debug and Test:
- Use the GTM preview mode to ensure all tags and triggers fire correctly during a test purchase.
- Publish Container:
- Once verified, click
Submit
in GTM to publish the container.
- Once verified, click
Conclusion
By following these detailed steps, you will have successfully configured Google Tag Manager and Google Ads conversion tracking for your Shopify store. Accurate tracking of purchase events will enable you to optimize your campaigns and drive better business decisions. Happy tracking!