Add Google Ads conversion tracking to Shopify quickly. Choose from three versions:
- Additional Scripts: Deprecated but still installable.
- Shopify Pixel: Direct installation with Google Ads, excluding enhanced conversions.
- Shopify Pixel with Enhanced Conversion & Micro Conversions + GA4: Available when installing via Google Tag Manager.
The Shopify Pixel Code is compatible with Shopify checkout extensibility.
Please note that users checking the code with Tag Assistant or developer tools will not be able to see the code, as Shopify pixels run in sandbox mode, which is not viewable.
Please also note that if you are installing this with Google Analtyics 4, that you will not be able to view the debug mode in GA4. But you can view the realtime data to verify it’s tracking.
Enhanced conversions will be reflected in the status details within a week, depending on your sales volume.
Shopify Pixel + Enhanced Tracking + Micro Conversions + GA4
If you have multiple Google Merchant Center accounts and or you have different feeds, contact us for custom coding. You may also contact us for any other custom coding.
What is New?
- V1.05+ now supports cart data, for using cost of goods based bidding strategy in Google Ads
- V1.07+ now supports micro conversions + bug fixes
- V1.08+ now supports Google Analtyics 4 (optional)
What is the difference between Micro and Macro Conversions?
When it comes to advertising, we have two types of conversions. Macro and Micro conversions. Macro conversions are the website’s primary conversions, such as completing an order or submitting a lead form. Micro conversions are smaller actions such as add to cart, view cart, add a delivery address, etc.
Requirements
You need access to the following accounts.
- Google Tag Manager
- Google Ads
- Google Analytics 4
- Shopify (Customer Events)
Let’s get started!
If you have not yet created a Google Tag Manager account, create one now.
Once the account is created, you should see a popup with your GTM tag, if you don’t see this, don’t worry, simply go to Admin > Install Google Tag Manager
Copy the tag id without GTM- as highlighted in the image below
Replace the following values in the settings:
- GOOGLE_TAG_MANAGER_ID
- Add your GTM tag ID
- GOOGLE_MERCHANT_CENTER_ID
- Add your Google Merchant Center account ID
- PRODUCT_COUNTRY_CODE
- Set your default country ISO2 code, for usage in product IDs
- ESTIMATED_SHIPPING_TIME
- Add your estimated shipping time
- GRANT_CONSENT
- Defaulted to false, if you set it to true, you are forcing to set consent_mode v2 to true, regardless what the use selected (not recommended)
- ID_TYPE
- Set your Google Merchant Center product ID format
- CAPITALIZE_SKU
- If you are not using the default Shopify IDs and you are using SKUs, you can choose to uppercase the value
In the code below replace GTM-123456 with your GTM tag ID
// Code Created By FeedArmy V1.0814 (please don't remove the creator)
// Copyright FeedArmy Co., Ltd.
const GOOGLE_TAG_MANAGER_ID = 'GTM-123456';
const GOOGLE_MERCHANT_CENTER_ID = '123456789';
const PRODUCT_COUNTRY_CODE = 'US';
const ESTIMATED_SHIPPING_TIME = 5;
const GRANT_CONSENT = false; // Use false or true
// for the ID_TYPE, if your products look like shopify_US_123456789_123456798 add the word shopify
// if your products are sku's add the value sku -- const ID_TYPE = 'sku';
// if your proudcts use the variant id use the value variant_id -- const ID_TYPE = 'variant_id';
// if your proudcts use the parent id use the value parent_id -- const ID_TYPE = 'parent_id';
const ID_TYPE = 'shopify';
// If you want to capitalize the SKU set CAPITALIZE_SKU to true, if you don't want to change anything set to false
const CAPITALIZE_SKU = false;
// SETTINGS END
// SETTINGS END
// Define dataLayer and the gtag function.
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
//Initialize GTM tag
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer', GOOGLE_TAG_MANAGER_ID);
if (GRANT_CONSENT === true){
//Google Consent Mode v2
gtag('consent', 'update', {
'ad_storage': 'granted',
'analytics_storage': 'granted',
'ad_user_data': 'granted',
'ad_personalization': 'granted',
});
}
const createLineItemsData = (lineItems, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU) => {
return lineItems.map((item) => {
let itemId;
if (ID_TYPE === "shopify") {
itemId = "shopify_" + PRODUCT_COUNTRY_CODE + "_" + item.variant?.product?.id + "_" + item.variant?.id;
} else if (ID_TYPE === "parent_id") {
itemId = item.variant?.product?.id;
} else if (ID_TYPE === "sku") {
itemId = item.variant?.sku;
if (CAPITALIZE_SKU) {
itemId = itemId.toUpperCase();
}
} else {
itemId = item.variant?.id;
}
// check for discount
let discount = item.discountAllocations?.reduce((total, discountAllocation) => {
return total + parseFloat(discountAllocation.amount.amount);
}, 0) || 0;
// calculate price
let price = parseFloat(item.variant?.price?.amount) - discount;
return {
item_id: itemId,
item_name: item.variant?.product?.title,
price: price,
quantity: item.quantity
};
});
};
const createLineItemsDataCart = (lineItems, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU) => {
return lineItems.map((item) => {
let itemId;
if (ID_TYPE === "shopify") {
itemId = "shopify_" + PRODUCT_COUNTRY_CODE + "_" + item.merchandise?.id + "_" + item.merchandise?.product?.id;
} else if (ID_TYPE === "parent_id") {
itemId = item.merchandise?.id;
} else if (ID_TYPE === "sku") {
itemId = item.merchandise?.sku;
if (CAPITALIZE_SKU) {
itemId = itemId.toUpperCase();
}
} else {
itemId = item.merchandise?.product?.id;
}
return {
item_id: itemId,
item_name: item.merchandise?.product?.title,
price: item.cost?.totalAmount?.amount,
quantity: item.quantity
};
});
};
const createLineItemsDataAddToCart = (item, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU) => {
let itemId;
if (ID_TYPE === "shopify") {
itemId = "shopify_" + PRODUCT_COUNTRY_CODE + "_" + item.merchandise?.id + "_" + item.merchandise?.product?.id;
} else if (ID_TYPE === "parent_id") {
itemId = item.merchandise?.id;
} else if (ID_TYPE === "sku") {
itemId = item.merchandise?.sku;
if (CAPITALIZE_SKU) {
itemId = itemId.toUpperCase();
}
} else {
itemId = item.merchandise?.product?.id;
}
return {
item_id: itemId,
item_name: item.merchandise?.product?.title,
price: item.cost?.totalAmount?.amount,
quantity: item.quantity
};
};
const createLineItemsDataProductView = (item, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU) => {
let itemId;
if (ID_TYPE === "shopify") {
itemId = "shopify_" + PRODUCT_COUNTRY_CODE + "_" + item.product?.id + "_" + item.id;
} else if (ID_TYPE === "parent_id") {
itemId = item.product?.id;
} else if (ID_TYPE === "sku") {
itemId = item.sku;
if (CAPITALIZE_SKU) {
itemId = itemId.toUpperCase();
}
} else {
itemId = item.id;
}
return {
item_id: itemId,
item_name: item.product?.title,
price: item.price?.amount,
quantity: 1
};
};
const calculateTotalDiscount = (lineItems) => {
let totalDiscount = 0;
lineItems.forEach(item => {
item.discountAllocations.forEach(discount => {
totalDiscount += parseFloat(discount.amount.amount);
});
});
return totalDiscount.toFixed(2); // Convert to string with 2 decimal places
};
analytics.subscribe("checkout_completed", (event) => {
const lineItemsData = createLineItemsData(event.data?.checkout?.lineItems, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU);
const email = event.data?.checkout?.email;
const phone = event.data?.checkout?.phone;
const address = event.data?.checkout?.shippingAddress;
const totalDiscountAmount = calculateTotalDiscount(event.data?.checkout?.lineItems);
let shopifyPixelData = {
currency: event.data?.checkout?.subtotalPrice?.currencyCode,
value: event.data?.checkout?.subtotalPrice?.amount,
transaction_id: event.data?.checkout?.order?.id,
shipping: event.data?.checkout?.shippingLine?.price?.amount,
tax: event.data?.checkout?.totalTax?.amount,
};
if (email) {
shopifyPixelData.email = email;
}
if (phone) {
shopifyPixelData.phone = phone;
}
if (address) {
let addressData = {};
if (address.firstName) addressData.first_name = address.firstName;
if (address.lastName) addressData.last_name = address.lastName;
if (address.address1) addressData.street = address.address1;
if (address.city) addressData.city = address.city;
if (address.province) addressData.region = address.province;
if (address.zip) addressData.postal_code = address.zip;
if (address.provinceCode) addressData.province_code = address.provinceCode;
if (address.country) addressData.country = address.country;
if (address.countryCode) addressData.country_code = address.countryCode;
if (Object.keys(addressData).length > 0) {
shopifyPixelData.address = addressData;
}
}
shopifyPixelData.aw_merchant_id = GOOGLE_MERCHANT_CENTER_ID;
shopifyPixelData.aw_feed_country = address.countryCode;
shopifyPixelData.discount = totalDiscountAmount;
shopifyPixelData.shipping = event.data?.checkout?.shippingLine?.price?.amount;
shopifyPixelData.estimated_shipping_time = ESTIMATED_SHIPPING_TIME;
shopifyPixelData.items = lineItemsData;
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: "purchase",
url: event.context.document.location.href,
ecommerce: shopifyPixelData
});
});
analytics.subscribe("product_added_to_cart", (event) => {
dataLayer.push({ ecommerce: null });
const items = createLineItemsDataAddToCart(event.data?.cartLine, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU);
dataLayer.push({
event: "add_to_cart",
url: event.context.document.location.href,
ecommerce: {
currency: event.data?.cartLine?.merchandise?.price?.currencyCode,
value: event.data?.cartLine?.merchandise?.price?.amount,
items: items
}
});
});
analytics.subscribe("cart_viewed", (event) => {
dataLayer.push({ ecommerce: null });
const items = createLineItemsDataCart(event.data?.cart?.lines, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU);
dataLayer.push({
event: "view_cart",
url: event.context.document.location.href,
ecommerce: {
currency: event.data?.cart?.cost?.totalAmount?.currencyCode,
value: event.data?.cart?.cost?.totalAmount?.amount,
items: items
}
});
});
analytics.subscribe("checkout_started", (event) => {
dataLayer.push({ ecommerce: null });
const items = createLineItemsData(event.data?.checkout?.lineItems, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU);
dataLayer.push({
event: "begin_checkout",
url: event.context.document.location.href,
ecommerce: {
currency: event.data?.checkout?.currencyCode,
value: event.data?.checkout?.subtotalPrice?.amount,
items: items
}
});
});
analytics.subscribe("payment_info_submitted", (event) => {
dataLayer.push({ ecommerce: null });
const items = createLineItemsData(event.data?.checkout?.lineItems, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU);
dataLayer.push({
event: "add_payment_info",
url: event.context.document.location.href,
ecommerce: {
currency: event.data?.checkout?.currencyCode,
value: event.data?.checkout?.subtotalPrice?.amount,
items: items
}
});
});
analytics.subscribe("checkout_shipping_info_submitted", (event) => {
dataLayer.push({ ecommerce: null });
const items = createLineItemsData(event.data?.checkout?.lineItems, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU);
dataLayer.push({
event: "add_shipping_info",
url: event.context.document.location.href,
ecommerce: {
currency: event.data?.checkout?.currencyCode,
value: event.data?.checkout?.subtotalPrice?.amount,
items: items
}
});
});
analytics.subscribe("search_submitted", (event) => {
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: "search_submitted",
url: event.context.document.location.href,
ecommerce: {
query: event.data?.searchResult?.query,
}
});
});
analytics.subscribe("collection_viewed", (event) => {
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: "view_collection",
url: event.context.document.location.href,
ecommerce: {
collection_id: event.data?.collection?.id,
collection_title: event.data?.collection?.title,
}
});
});
analytics.subscribe("product_viewed", (event) => {
dataLayer.push({ ecommerce: null });
const items = createLineItemsDataProductView(event.data?.productVariant, ID_TYPE, PRODUCT_COUNTRY_CODE, CAPITALIZE_SKU);
dataLayer.push({
event: "view_item",
url: event.context.document.location.href,
ecommerce: {
currency: event.data?.productVariant?.price?.currencyCode,
value: event.data?.productVariant?.price?.amount,
items: items
}
});
});
analytics.subscribe("page_viewed", (event) => {
window.dataLayer.push({
event: "page_view",
url: event.context.document.location.href
});
});
Go to Shopify > Settings > Customer Events
Click on add custom pixel
Paste your code, click on save and then connect.
In Google Tag Manager, go to admin > and click on import container.
GTM JSON File
If you have already installed a previous version, please merge the new file. The only thing you need to do after mergin, is to re-updated the Conversion ID and Conversion Label
Download the json upgrade from V1.07 to V1.0813 and v1.0814
Download the full json file V1.0813 and v1.0814
In Google Tag Manager select the file you uploaded.
Chosing your workspace, click on existing and choose default workspace
Select Merge as the import option
Click on confirm
Go to Workspace > Tags > Click on Google Ads Shopify Pixel Conersion Tracking By FeedArmy
Hover over the tag and click on edit
Add your Google Ads conversion ID and Label when creating a new conversion.
In Google Ads go to Goals > Summary > Click on New Conversion Action
Select website
Enter any website domain, and click on scan
Scroll to the bottom of the page and click on Add a conversion action manually
Add your conversion action details:
For Goal and action optimization select purchase
For Conersion name, add any name, I recommend Shopify GTM Pixel
For the Value select Use different values for each conversion
Click on Done, then click on save and continue
Select Google Tag Manager and copy your id and label from Google Ads and paste it in Google Tag Manager
Now repeat the steps for the micro tracking (optional) (view the instructions video for more details) and ensure everything is set to secondary as goal, unless you know what you are doing:
- Add To Cart
- Cart Viewed
- Begin Checkout
- Add Shipping Info
- Payment Submitted
- Search
- View Collection
Save the tag, and now lets publish the GTM container by clicking on Submit
Add a version name and click on publish
Let’s enable enhanced conversions in Google ads by clicking on done, then select your conversion action and click on ehanced conversions.
Check the box next to Turn on enhanced coversions
Check the radio button for Google tag or Googel Tag Manager and select next
Enter just a letter d, and click on check URL, as we want to force an error.
We can now click on select one manually
Click on Google Tag Manager > Next and click on save
You are now finished with the whole setup. Please leave a review to help my business and to continue to provide great free content
Google Analytics 4 Setup
If you are not upgrading from a previous version simple skip the below steps until you read, continue GA4 Installation.
If you are upgrading from V1.07 to v1.08, make sure to copy full Shopify Pixel code, or you can just replace everything below the settings of the code (only the code has changed not the settings)
Then in Google Tag Manager, import the upgrade file and edit the following two tags by adding the Google Analytics Measurement ID:
Continue GA4 Installation: We now need to add our Measurement ID
- Tags:
- Google Analytics 4 Data
- Google Analytics 4 Page View
You can find your Google Analytics Measurement ID by going to:
- Google Analytics
- Cog Icon (admin)
- Under Data collection and modification, choose Data Streams
- Click on your data stream
- Now you can view and copy your measurement id
Now click on both tags, and add replace the G-1234 that I added, with your own measurement ID.
Support My Work!
https://www.trustpilot.com/review/feedarmy.com
or here : https://g.page/r/CbGZ-JICOoh1EAg/review
Trouble Shooting
Browser Console Log (developer tools)
Because Shopify pixels run in sandbox mode, for privacy reasons you will not be able to view data layers in your browser.
Conversion Not Working
If your conversions are not working, then most likely your theme checkout and thank you page are not published.
Go to Shopify > Online Store > Themes > Click on Customize
Click on the home page drop down and select Checkout and new customer accounts
Click on checkout drop down and choose thank you and or checkout (whichever says unpublished)
Click on the sections button and publish.
Google Analytics Average Engagement Time Per Session
When using Shopify Pixels / Customer Events, and due to Shopify using sandbox environment, automatic events, including engagement event for Google Analytics aren’t triggered.
Change Log
- 2nd September 2024: v1.0814 Fixed the pixel code to correctly show the item_id instead of the id (For GA4).
- 2nd September 2024: V1.0813 Fixed an issue with event naming convention
- 25th August 2024: V1.08+ now supports Google Analytics 4
- 8th August 2024: V1.07+ now supports micro conversions + bug fixes
- 16th July 2024: Updated GTM enhanced conversion data to be lowercase, as per documentation and highlighted by Lowie Verschelden
- 14th July 2024: Added V1.05 cart data, so that you can use Google Ads cost of goods based bidding.
- 18th June 2024: Added conditional checks for enhanced data to avoid listing empty values
- 10th June 2024 : Updated GTM Container, incorrect mapping of some variables (to update please delete all variables in GTM, and re-import with merge option)
Shopify Pixel
This Shopify Pixel / Customer Event code, has been tested and verified as working for Shopify merchants that have enabled Checkout Extensibility.
The first step is to get your conversion id and label.
Log in to Google Ads and go to Goals > Conversions > Summery
Click on the blue button that says + New conversion action
Select Website as your conversion method.
Enter your website address, and scan.
If you see a banner that says to use Google Analytics, then click on Use Google Ads only
Click on +Add conversion action manually.
- Choose Purchase as your Goal and action optimization
- Enter any conversion name, I will call it Shopify Pixel
- Select Use different values for each conversion
- Leave the rest unchanged and click on done
Click on See event snippet
Copy the code and paste in a temporary text file, we will copy some details at a later stage.
Click on Done.
Now go to Shopify > Settings > Customer Events
And click on Add custom pixel
You can give it any pixel name, but I will call it Google Ads Conversion. Now click on Add pixel.
When editing the code below, please do not remove or change the author, and respect who built it.
// Created by FeedArmy V1.04
Paste the below code in the Shopify pixel.
// Created by FeedArmy V1.05
const script = document.createElement('script');
script.setAttribute('src', 'https://www.googletagmanager.com/gtag/js?id=AW-123456789');
script.setAttribute('async', '');
document.head.appendChild(script);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-123456789', {'allow_enhanced_conversions':true});
analytics.subscribe("checkout_completed", (event) => {
gtag('set', 'user_data', {
email: event.data?.checkout?.email,
phone: event.data?.checkout?.phone,
address: {
first_name: event.data?.checkout?.shippingAddress?.firstName,
last_name: event.data?.checkout?.shippingAddress?.lastName,
street: event.data?.checkout?.shippingAddress?.address1,
city: event.data?.checkout?.shippingAddress?.city,
region: event.data?.checkout?.shippingAddress?.province,
postal_code: event.data?.checkout?.shippingAddress?.zip,
provinceCode: event.data?.checkout?.shippingAddress?.provinceCode,
country: event.data?.checkout?.shippingAddress?.country,
countryCode: event.data?.checkout?.shippingAddress?.countryCode,
}
});
gtag('event', 'conversion', {
send_to: 'AW-123456789/abcdefg123456789',
transaction_id: event.data?.checkout?.order?.id,
value: event.data?.checkout?.subtotalPrice?.amount,
currency: event.data?.checkout?.subtotalPrice?.currencyCode,
});
});
From your previously copied code from Google Ads, copy the AW-123456789 id highlighted in the image below.
And paste it twice on row 3, and row 10, by replacing the existing ID AW-123456789 (shown in red in the image above)
Go back to your Google Ads code and now copy the full ID and Label as highlighted in the image below.
Replace the send_to value between the quotes on row 14. (shown in red in the above image)
Now click on save in the top right corner followed by clicking on Connect, accept Shopify terms and conditions. And you are all done.
Testing
You can’t test code on Shopify’s checkout thank you page because it’s in sandbox mode, meaning tools like Google Tag Assistant or GTM Preview Mode won’t work. While you could use console.log to check data, I think it’s unnecessary effort. The code does work. Simply wait for a sale to confirm that it’s tracked in Google Ads as a conversion when it comes from an ad click or wait until you have any sale, Google Ads will show the code is detected.
Change Log
- V1.05 – 20 May 2024: Changed the order of gtags
- V1.04 – 20 May 2024: Added user_data values after Sve (comment below) confirmed Google’s own version. I already built this months ago, but needed confirmation it’s correct.
- V1.03 – 02 March 2024 : Supports multicurrency and used subtotal price instead of total
- V1.02 – 27 February 2024 : Public Release
Support My Work!
My conversion tracking code is constantly updated and provided free for anyone to use. As I don’t ask for any monitary value in return, I would be grateful if you consider leaving a review: https://www.trustpilot.com/review/feedarmy.com
Additional Scripts
Supported Functions
- Automatically supports multi currencies.
- Automatically converts European prices with commas to dots.
- Optional choice for disabling tax and shipping in your checkout value.
- Includes the new Google Ads enhanced conversion option
Requirements
- Access to Google Ads > Conversions
- Access to Shopify > Settings
Step 1: Open Shopify Checkout Settings
Open a new tab in your browser and log in to your Shopify Admin Panel
Navigate to Settings (Gear Icon) and choose Checkout
Step 2: Setup & Copy Your Google Ads Conversion Code
In a second browser tab, login to Google Ads and click on the tools and settings menu in the top right corner and select Conversions under the Measurement column.
Click on the big blue plus sign (New Conversion Action).
Now select website as your tracking template.
It will now ask you to scan your website URL. Enter your URL and click on scan.
Scroll to the bottom and choose to install the conversion action manually.
Then do the following :
- Conversion name
- enter any name
- Category
- Purchase / Sale
- Value
- Use different values for each conversion
- Attribution model
- Choose Position-Based (recommended for growth based businesses)
- The rest can be as default
I have written a great article on how to choose your attribution model.
Click on Create and continue
Now you can click on Save And Continue
Click on See Event Tag
Copy your Event Snippet and save it in a temporary file, for later use.
Click on Done
Click on the recently added conversion action
Enabling Enhanced Conversions is optional and not required. Some accounts may not see this option yet. So you can continue the steps below, excluding those related to enhanced conversions. (Skip to Step 3)
Now go to Tools and Settings > conversions > settings or click here: https://ads.google.com/aw/conversions/customersettings
By enabling enhanced conversions you allow Google to improve its accuracy to track conversions. This seems to be required due to Apple’s IOS14 no tracking prompt.
After you have checked the box and clicked on save, you will get a terms and conditions prompt, read it and confirm.
Now choose Google Tag and click on Tag Details.
Now check the box next to Specify CSS selectors or JavaScript variables
- Change CSS selector to Global Javascript variable
- Enter the following values for Email
- enhanced_conversion_data.email
Repeat the steps for Phone number and Name and Address
- Phone
- enhanced_conversion_data.phone_number
- First name
- enhanced_conversion_data.first_name
- Last name
- enhanced_conversion_data.last_name
- Street address
- enhanced_conversion_data.home_address.street
- City
- enhanced_conversion_data.home_address.city
- State
- enhanced_conversion_data.home_address.region
- Country
- enhanced_conversion_data.home_address.country
- Postal code
- enhanced_conversion_data.home_address.postal_code
You might ask, why the javascript values? Well on your thank you page, the javascript selector for all the values is added as a javascript variable when using the conversion tracking code below (From V1.5). This will only work if you use the code below.
Step 3: Editing and Pasting Your Google Ads Conversion Tracking
Go back to Shopify and scroll down until you see Order Processing (from step 1), at the bottom of this section you will have a field where you can paste code that is labeled Additional Scripts.
If you have two fields such as post purchase and order status, then add the code to the order status field.
Copy the send_to value (image below) and replace fa_send_to value with your value in the code template below.
- replace the value for fa_send_to
- replace the value AW-123456789/abcdefghijlklmnopq with your event snippet send_to value
- Choose yes or no for fa_include_tax_and_shipping
- choose yes if you want to include tax and shipping in the checkout value or no to not include tax and shipping values.
Sometimes on rare occasions, when you set fa_include_tax_and_shipping to no, it would still include the shipping. I’m not sure why this sometimes happens, but it might have to do with the account country. So if you notice shipping is included, set the value to yes, and it will remove shipping.
Code Template (change the fa_send_to value with your code snippet send_to value)
<!-- FEEDARMY START Global site tag (gtag.js) - Google Ads V2.2 -->
<!-- For the latest and updated code or tutorial: https://feedarmy.com/kb/adding-adwords-conversion-tracking-to-shopify/ -->
{% assign fa_send_to = 'AW-123456789/abcdefghijlklmnopq' %}
{% comment %}DO NOT EDIT BELOW{% endcomment %}
{% if fa_google_coding %}{% assign fa_google_coding = true %}{%- else -%}{% assign fa_google_coding = false %}{%- endif -%}
{% assign fa_google_ids = fa_send_to | split: "/" %}
{% if fa_google_coding == false %}
<script async src="https://www.googletagmanager.com/gtag/js?id={{fa_google_ids[0]}}"></script>
{%- endif -%}
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{fa_google_ids[0]}}', {'allow_enhanced_conversions':true});
var checkout = window.Shopify.checkout;
</script>
{% if first_time_accessed %}
<script>
gtag('event', 'conversion', {
'send_to': '{{ fa_send_to }}',
'value': checkout.total_price_set.presentment_money.amount,
'currency': checkout.total_price_set.presentment_money.currency_code,
'transaction_id': '{{ order_id }}',
});
var enhanced_conversion_data = {
{% unless billing_address.first_name == blank %}"first_name": "{{ billing_address.first_name }}",{% endunless %}
{% unless billing_address.last_name == blank %}"last_name": "{{ billing_address.last_name }}",{% endunless %}
{% unless checkout.email == blank %}"email": "{{ checkout.email }}",{% endunless %}
{% unless billing_address.phone == blank %}"phone_number": "{{ billing_address.phone }}",{% endunless %}
"home_address": {
{% unless billing_address.street == blank %}"street": "{{ billing_address.street }}",{% endunless %}
{% unless billing_address.city == blank %}"city": "{{ billing_address.city }}",{% endunless %}
{% unless billing_address.province_code == blank %}"region": "{{ billing_address.province_code }}",{% endunless %}
{% unless billing_address.zip == blank %}"postal_code": "{{ billing_address.zip }}",{% endunless %}
{% unless billing_address.country_code == blank %}"country": "{{ billing_address.country_code }}"{% endunless %}
}
};
</script>
{% endif %}
<!-- FEEDARMY END Global site tag (gtag.js) - Google Ads V2.2 -->
Verifying and Testing
Verifying
You can verify if the code is working if you go to Google Ads > Tools and Settings > Conversions > here check if the status is verified.
Testing
First open up Tag Assistant when the new window opens up make a test payment to check if the conversion tracking is correctly installed. When you are on the final thank you page check the data within Tag Assistant.
Tip:
first_time_accessed
is for the page, not for the customer. Subsequent orders will run afirst_time_access
again for the same person if it is a new browser session.
Trouble Shooting Enhanced Conversions
Make sure you have waited at least 3 to 7 days. Google requires time to compile the data.
Coverage:
You may encounter issues with regard to coverage. This can happen when customers pay through a third-party payment processor (PayPal), which may require that they enter customer data on a different domain instead of directly on your website like they do when they do not use a third-party payment processor.
Match status:
If you are having issues with the match status, not all users fill out all the fields in your checkout. What you could do is remove the attributes in your Google Ads conversion list to only track emails or only track mandatory fields in your checkout.
By removing non-mandatory fields, you will avoid submitting empty fields to Google.
Change Log
- 8th September 2023 – updated the steps for enhanced conversion tracking
- V2.2 – 11 July 2023 – updated code to validate every value
- V2.1 – 24 June 2023 – updated checkout price to use presentment_money
- V1.8 – 10 August 2022 – Added enhanced conversion checks for email and phone number
- V1.7 – 07 June 2022 – Fixed incorrect total value when changing shipping and tax settings
- V1.6 – 28 April 2022 – Fixed the country code not adding the value correctly as highlighted by Jon Yildiz
- V1.5 – 27 July 2021 – Added Enhanced Conversions using Javascript and removed CSS
- V1.4 – 21 July 2021 – Added Enhanced Conversions using CSS
- Due to server migration, older changes are not listed
Support My Work!
My conversion tracking code is constantly updated and provided free for anyone to use. As I don’t ask for anything in return, I would be grateful if you consider leaving a review: https://www.trustpilot.com/review/feedarmy.com
Enable Google Ads Remarketing Pixel For Shopify
Track your existing website visitors by installing remarketing for Shopify. A returning visitor is twice as likely to convert as a first-time visitor. Use this data for display remarketing ads and audience targeting.
Enable Micro Conversions
If you like to track more minor conversion actions ie, micro-conversions such as add to cart, view cart, add a delivery address. Then install Google Analytics Goals.
THere’s a variable for referrer, but not in In the data Layer, so far I found 3 useless variable in your file:
feedarmy-shopify-page-referrer –> Unfound Data Layer
feedarmy-new-returning-customer –> Custom JS
feedarmy-customer-lifetime-value –> Custom JS
Btw In a case of multiple countries/languages I’ve made a code tha works with your that change the Prod id through the web pixel, lmk if you’re interested 😀
I have not yet setup the two custom JS files, these are just there for when I have added the code in the pixel.
As to shopify page referrer, this is also not added yet.
As to your customization, yes happy to have community members collaborate, to improve this code. Please reach out to [email protected]
Thank you.
Hello! Thank you very much for your work, I’m sure it helps many people in the world.
I would like to know if to use optimized conversions in sandbox I need to disable the Google YouTube app from Shopify or disable the app’s conversions.
Yes, you need to disable the app, or disconnected the google ads connection or set the old conversion action to secondary, or delete the old conversion action. All of these will be ok.
Hi, shouldn’t we disable the app once the GTM setup is confirmed to work? Or the conversion value and enhanced data will not feed until the app is disabled? I am stuck at measuring conversions but not measuring any conversion value.
You can disconnect Google Ads in youtube and shopping app, or if you do not use the data feed option, you can delete it, yes.
If you have no conversion values, make sure you did not accidentally selected a specific value instead of dynamic in the conversion action settings (google ads) Also make sure you have waited until you get a sale from an ad to see the data.
After setting v1.0813 up do you recommend removing the google & youtube pixel app?
Also for the url’s that the sandbox pixel generates in GA4 will the code you provided address cleaner url’s or should we manually try shopify’s workaround:
https://help.shopify.com/en/manual/promoting-marketing/pixels/custom-pixels/gtm-tutorial#:~:text=Cleaner%20page%20URLs
Hello Sean, once confirmed that all the new tracking is working, yes remove the google and youtube app, assuming you have a different data feed solution.
As to the URLs I have implemented a method to clean up the URLs.
Hi Emmanuel, first of all: Amazing Video! Thanks a lot!
Unfortunately, I am facing some issues here. The purchase tag is not firing when I go into debug mode and do a test conversion. I think, the GTM is not even integrated in the thank you page. The page is published tho. Can you help me with this? Could it be that it doesn’t work because I don’t have Shopify Plus?
Make sure you have published the thank you and order page, check for details at the bottom of this article. If you continue to have issues, feel free to reach out at [email protected]
I don’t know if it is an usual issue, but GTM pixels all working well, except for Purchase pixel. It detects conversions but do not receive any conversion value (and I guess any currency information neither).
Do a test by clicking on your own ad, then making a purchase if you are unsure it works.
I can’t test it easily without VPN, the ad is set for other countries. However, the shopify app purchase pixel is detecting value and conversions. The Feedarmy GTM pixel is detecting conversions but no conversion value. Same issue reported by ylc 9 days ago. All codes were refreshed 2 days ago, all tracking IDs revised. Will give 2 days more to see if any change but there has been conversions detected without value…
If there are no values, make sure you did not accidentally have chosen a specific value in your conversion setup. If you continue to have issues, I am available to check at [email protected]
Hi, ive followed the instructions but when I test this in tag assistant I get the “This conversion action wasn’t detected” error. I have published the checkout and thank you page etc.
Also in Google Ads all my statuses are “inactive” im not sure where ive gone wrong.
Thanks
Please note that Shopify pixels work in sandbox mode, as such viewing data layers, is blocked by shopify.
If your setup does not work, I do offer a service which you can get at [email protected]
Hi. My conversions are not getting recorded in the conversion goal. I have followed all the steps correctly
For a service request, please reach out at [email protected]
Hi! I installed your code and settings in GTM and it’s working, but when testing I noticed that Begin Checkout conversion fires also on the purchase confirmation page together with the purchase event (I see this in GTM assistant and in the dev tools – network). In GTM these conversions have different corresponding settings. I wonder if you have any thoughts on what could be causing this?
My coding uses the official triggers from shopify mentioned here: https://help.shopify.com/en/manual/promoting-marketing/pixels/custom-pixels/gtm-tutorial
If there are bugs, with triggers, than I recommend reporting them to Shopify. Because when a trigger is active, can not be changed on my end, only on Shopify’s end.
Ok, thank you!
Hello!
I did everything and its showing that the conversion tag status is ‘Inactive’
Try to do a test purchase.
It doesn’t seem to be working. I’ve set it up for 3 days, and there have been purchases on Shopify, but the new purchase conversion in Google Ads remains at 0. Although it shows as running, there is still no data.
If it’s says it’s detected, that means it is working. If you have zero purchases that means, no ad click converted to a sale. I recommend you do a test by clicking on your own ad, than make a purchase. However, just visiting the checkout page, will verify that begin checkout works. So no need to also check the purchase. But that is up to you, if you want to speed up the process.
My conversions is seen double in Google Ads.
Every conversion is first without value and then second conversion is same purchase but with value.
Example:
shop.com/checkouts/1234566/thank-you (registered as 1 conversion but without value)
shop.com/wpm(at)123456/web-pixel/sandbox/44346436/thank-you (registered as 1 conversion with value)
That would only be possible if you have multiple conversion actions. Or if you have installed the same conversion label multiple times.
There should be only 1 conversion count and only 1 conversion value, if that is not the case, something else might be doing this. Double check you have nothing else installed.
hello, on Google Ads, all conversion actions are “active” except View Collection which remains “Inactive”, I have implemented the code more than a week ago. Can you help me ?
Double check you added the correct conversion id and label. If you are still stuck, feel free to reach out at [email protected]
Resolved, Thank you for your help and work !
Pleasure, and great to hear.
Is this set-up specifically for the Checkout Extensibility upgrade or will it work across all of Shopify’s cart systems?
It will work with everything, but I never tested it with post-purchase apps, and I think it does not work with this. However, I will look into this in the future.
the new edition of the code, do not send the Conversion value to google ads, only send Conversions.
My apologies; I don’t know what happened. The event triggers were not changed in the file I uploaded, but they were correct in my final version. I think something happened when I exported that I chose the wrong version. This is now correct. Please download the upgrade file for v1.0813. Thank you for reporting the issue.
for v1.0813 aslo same error, now only V1.081 working
I will check again, in a few days. Considering data is not live in Google Ads. It always requires at least 1 day before you can verify it works or not. I will update the code or json file if it’s wrong this week. But as of writing it should work.
Hello, do you mean that all the versions from 5 minutes ago were incorrect? I downloaded your code yesterday, so do I also need to reset it?
No, not all versions, only version 1.812 was incorrect where it did not match up the event naming convention in GTM. But yes, just update the JSON file with the upgrade file, and the pixel script, just to be on the safe side.
So I upload this v1.0813 file to GTM Container and replace it with the v1.08 tags etc.?
Update both the code in Shopify, and JSON container in GTM.
Hi I just imported the V1.0813 last night. Will I have the same issue that it wont send conversion value to google ads? If so, do I download the current JSON file for v1.0813 and then what do I do? Will I have to go through and add in all conversion ID and labels to each tag again?
To upgrade to V1.08 please have a look at this video for instructions: https://www.youtube.com/watch?v=SLdb26tAoEE&t=36s
No, the conversion value should work correctly.
Hi Emmanuel, first of all, thank you for this guide, you are AMAZING and you will be our go to person for hired help. I have a question about the ID_Type. How do you know which id_type you have? Also, if consent mode is set to false, will it affect ad performance? Thanks in advance for your help!
Hello Sam, Thank you kindly. It’s my pleasure. To find out what ID format you are using, either go to Google Merchant Center > Products or go to Google Ads > click on a shopping or PMax campaign > click on products.
If forced consent mode is set to false, it means the cookie consent popup you are using will be the one that determines if it tracks or not. If you set it to true, it will set consent mode to true and ignore anything the customer has chosen if you are using a cookie banner. The cookie banner should handle it. There are plenty of apps that can do this.
Thanks for the quick response! Last question about this I promise. It appears that we have product IDs that are a combination of custom product IDs (ie PPDF54784754) because some products were uploaded manually, and shopify product ids (ie shopify_US_XXXX format) for products that came in via the Content API. In the case where we have a blend like this, what should we use for the ID_Type?
In that case choose one or the other, but I would say use the Shopify ID. It is recommended to avoid having different types of ID’s as this will only hurt your remarketing and cart data tracking.
Can you please help me understand how this function works using for feedarmy-new-returning-customer function variable? I don’t see anything regarding this in the datalayer code.
function () {
if (customer.ordersCount > 1) {
return true
} else {
return false
}
}
Currently this is not a supported function.
Thank you for this detailed guide. Unfortunately I am getting the “attention required” error in the Google Tag Manager. I have pages which aren’t tagged and the other error says consentmodus has been installed in the wrong order.
I don”t even know how to install the consentmodus, i just followed the steps in this guide.
Then in Google Ads as I am just copying everything you say should i enable enhanced conversions also for Cart Viewed, Payment Submitted, Search, Shipping and View Collection? What value should I choose? For GTM Pixel Purchase you said to use different values but i’m confused about the others.
Then the last two questions which show how much of a noob I am, should the the code which you paste under the part in your theme editor also be added? Or is it added already because of the code we pasted in the shopify pixel?
And is it normal that in the Tag Manager Admin center I have my account and container which is okay but then the next tab which says “Google-Tags”‘ there aren’t any google tags there.
Thank you for the help
Hello, yes, some pages are not tagged on pixel codes V1.07 and below, all pages are tagged for v1.08 and above.
Regarding consent mode, best to use an app to help guide you what to do and if you are still stuck, contact the app support team.
For micro conversions keep it as default, and only use these conversion actions for advanced campaign management.
Do not add any coding in the theme editor. All the necessary coding is within my code for the Shopify pixel.
I am not sure about your Google-Tags question, that requires investigation. You may reach out to me at [email protected] for personal service.
I used Google Tag Manager to test, and I found that if the following two pieces of code are not set in my Shopify theme, it cannot connect to the website.I noticed that the code you provided does not include the second piece of code. Could this be the reason?
<!– Google Tag Manager (noscript) –>
<noscript>https://www.googletagmanager.com/ns.html?id=GTM-XXXXX</noscript>
<!– End Google Tag Manager (noscript) –>
I would not add the no script. Please remember, you can not use GTM preview tool because Shopify runs in sandbox mode. Meaning you can’t see it.
If you want to check the results, you need to wait and see in your accounts, not using tools.
Hi Emmanuel! Thank you so much for this solution! However, we’re encountering one problem – when a user goes to the product page, the view_item event fires and all the item data is recorded, but when they switch to variant of the product, it doesn’t work. Although the information on the page changes and the url as well (page path changes from /layout-2-seat-sectional to /layout-2-seat-sectional?variant=123456789), apparently the page doesn’t fully reload. Is there a way to fix this and make view content fire on this variants as well?
Hello Anna, currently the triggers will only fire on page reloads / loads. I’m sure there is a way to get this working, however that requires custom coding, as each merchant will have different variant option tags.
Got it, thanks!
Shouldn’t there be a tag for “Product viewed”? It’s missing. Only “Collection viewed” is available.
I don’t see the benefit of tracking product views, considering a click on a shopping ad goes directly to the product page, meaning it won’t give you more info than you already know. Or are you talking from the perspective of advertising text ads for other pages, than seeing if they reach the product page?
The tags are not firing, what could it be?
For example, a step was not taken correctly. And are you aware you can not view tags when using pixels. Shopify runs this in sandbox mode, which is privacy locked. Thus you can’t view the results using the console. You will need to wait a day, and view the results in Google Ads.
Hi the web agency I work with set up a pixel already to track purchases on GA4 which I working okay. However for GAds I want to use your one as it includes enhanced conversions and cart data. Will me uploading this interfer with their pixel tracking? I’m worried the purchase event will fire twice since it looks like you are using the same naming structure now. Could I just stick to version 1.07? Thanks so much for this by the way it is amazing!
For V1.07 it will not double track as the event names are non default, but for V1.08 I had to change it to be default event naming convention, which will cause issues if you already have GA4 installed via GTM. In this case if you would like to upgrade, best to pause your existing GA4 integration in GTM.
Is it necessary to do this if I already have the Google & YouTube app installed? And if so, do I have to disconnect the app?
No, it is not necessary. Merchants install my version of the script because the Google and YouTube Apps can randomly stop working. You don’t need to disconnect the app; you can simply delete the old conversion actions in Google Ads.
Great! Thank you very much for replying, I really appreciate it.
Pleasure
How do we add a new Customer variable like we used to do in Additional Script?
That is being tested currently.
Hi – If I already have V1.5+ setup, is it ok to just go over the process above again? I.e., uploading the json file to GTM won’t cause any conflicts with previous uploaded file? Thanks.
You will need to delete the old conversion tag, because I changed the naming convention of all the tags. So if you import and don’t remove the old tag, then you have 2 tags causing double tracking. But that is it.
Can you please provide me with the json file you imported in GTM?
Here you go: https://feedarmy.com/wp-content/uploads/2024/08/GTM-Shopify-Google-Ads-Enhanced-Conversion-Tracking-Pixel-v1.07.zip
i think there’s an issue in the latest version, since the import gives back: JSON parsing error: mismatched input ‘7’ expecting {‘{‘, ‘[‘}. Earlier versions work fine.
I just did a test on a clean workspace, by importing the migraion file and the full version, with no errors. I believe you may have encountered an issue that is not related to the JSON file itself. Feel free to contact me at [email protected] if you need assistance.
Hi Emmanuel, thanks for your help, we use your work daily – it’s genuinely amazing.
We’ve followed the steps from v1.07. However, I can’t see any of the events in the summary section of GTM debug (eg view product, add to cart, start checkout, purchase). Why this might be? Also the google tag is not present when doing a purchase? Do you know any ways to fix this?
Again many thanks for your contributions to the community.
Felix
Thank you kindly Felix 🙂
When using GTM debug, and because Shopify Pixels run in privacy mode (sandbox mode) no data is visible and no coding is visible.
To ensure it works, wait a day for conversions to show up, and wait a week or so for enhanced conversions to show up.
Understood! Thanks a ton. Also we don’t know the const ID_TYPE as this client is not eligible for google merchant centre. How may we find out if its whether sku, parent, or variant? Appreciate you man!
If you are not using Google Merchant Center, then the product ID is irrelevant and as you can imagine, you can not know what the ID is. Only by having a GMC account, can you know what the ID is being used.
Hey Emmanuel, thanks for this, we use your work daily – it’s amazing!
I had a question:
After following the steps. When previewing with Google Tag Manager, I don’t see the google tag being found (there’s the gtm and Google Analytics tag only). Do I need to install the Google Tag in the script?
Please let me know, thanks again for your contributions to the community.
Felix
Thank you again for the reply.
When using GTM debug, and because Shopify Pixels run in privacy mode (sandbox mode) no data is visible and no coding is visible.
To ensure it works, wait a day for conversions to show up, and wait a week or so for enhanced conversions to show up.
Hi Emmanuel,
I went ahead and added your code to my shopify site, imported your JSON file successfully into my GTM account, and created an appropriate purchase Conversion in my Google Ads account. After completing those steps, my Conversion has a status of “Inactive” and displays “We haven’t verified your tag yet, which usually takes up to 3 hours after someone visits your page containing the tag. To help speed this up, you can visit the page to trigger the tag.” When I hover over the status. This is typical after immediately making the change, correct? If so, do you know roughly how long it takes for the Conversion to become “Active”. Thanks for the help!
If you have waited 2 days, and it is not working. Than contact me at [email protected]
Hi Emmanuel,
Thank you for your content!.
Can enhanced conversions be enabled simply by checking the “Enhanced Conversion Setup” checkbox on the Google Conversion action page for a Shopify app-based conversion action, without using GTM?
In the Google Ads account I manage, conversion tracking was implemented using the Shopify app without GTM before I took over.
It is tracking sales revenue correctly
Two days ago, I enabled “Use enhanced conversions” for this conversion action, and the enhanced conversion status is now “Managed Through Google Tag. Enhanced Conversions are being recorded.”
How can I ensure that enhanced conversions are indeed working? Should GTM also be installed as described in your post?
Thanks
If you are using a Shopify app to track conversions, you will need to check with the app support to see if enhanced conversions is supported.
Normally you can view the diagnostics of the conversion action to check if enhanced conversions is working or not. But what data is submitted I would not know. With my coding, I am maximizing the data sent to Google to allow for maximum tracking.
Hey Emmanuel
We are huge fans of your work! I have a question about the consent mode settings in the new code – my understanding is that this is set when someone enters the website but I can see that the new code updates this consent when someone purchases – is that correct?
So technically if someone does not consent when entering the site but then makes a purchase, this code will update their consent to ‘yes’ without them knowing?
Thanks so much
Hannah
Good question. I’m not 100% knowledgeable about consent; I followed Shopify’s documentation here: https://help.shopify.com/en/manual/promoting-marketing/pixels/custom-pixels/gtm-tutorial
I will do more research about consent mode, and see what I need to do. You may remove the consent mode update if you want.
Good to know and thank you for the response 🙂 appreciate it!
Pleasure