Its very useful, when you’re running AdWords campaigns, to correctly track conversions (conversions in eCommerce generally = sales).
If you don’t do this, its hard to optimize your campaigns and make more $$$.
In this post I’m going to show you how to setup AdWords conversion tracking for Shopify.
CRUCIALLY, I’m going to show you how to add code that avoids tracking duplications. That is to say, it will prevent a sale for appearing as 2 or more conversions, when there was only one! (yes, this happens sometimes).
To check if you’ve been getting duplicate conversions in AdWords, go to Tools in the top bar, then conversions. Then from the conversions page, choose webpages from the left side:
Set the time period you’re look at to All Time, or at least 30+ days. This should give us enough conversion data to work with. Then sort the list of results in descending order by clicking All Conversions.
If any of the pages have more than one conversion (such as below), you know you’ve been hit with duplicate Shopify conversions:
In order to setup AdWords conversion tracking correctly, this is the process we are going to follow:
- Get conversion code from AdWords
- Edit the code, so that we add in custom code for Shopify
- Paste the edited code into a box in your Shopify admin panel
1/ Get conversion code from AdWords
In your AdWords account, choose Tools and then Conversions
And then you want to choose + Conversion
Then choose Website Conversion
Then choose the following settings:
- Name: Shopify Sale
- Value: Each conversion has a different value. If there’s no value, use $1
- Count: Every Conversion
- Conversion Window: 30-day conversion window
- Category: Purchase/Sale
- Include in “Conversions”: Yes
- Attribution model: Use “Last Click” model
Then choose Save and continue
At which point you will get the snippet of code that you need:
The code will look like this:
<!-- Google Code for Shopify Sale Conversion Page --> <script type="text/javascript"> /* <![CDATA[ */ var google_conversion_id = your-id; var google_conversion_language = "en"; var google_conversion_format = "3"; var google_conversion_color = "ffffff"; var google_conversion_label = "your-label"; var google_conversion_value = 1.00; var google_conversion_currency = "USD"; var google_remarketing_only = false; /* ]]> */ </script> <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"> </script> <noscript> <div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/your-id/?value=1.00&currency_code=USD&label=your-label&guid=ON&script=0"/> </div> </noscript>
Now we want to modify it with the following changes:
We want to change the line:
var google_conversion_value = 1.00;
to
if ({{ subtotal_price }}) { var google_conversion_value = {{ subtotal_price | money_without_currency | remove: ',' }}; }
Lastly, you’ll want to edit the part of the noscript tag that contains the value. Change
value=1.00
to
value={{ subtotal_price | money_without_currency | remove: ',' }}
Making the above code look like this:
<script type="text/javascript"> /* <![CDATA[ */ var google_conversion_id = your-id; var google_conversion_language = "en"; var google_conversion_format = "3"; var google_conversion_color = "ffffff"; var google_conversion_label = "your-label"; if ({{ subtotal_price }}) { var google_conversion_value = {{ subtotal_price | money_without_currency | remove: ',' }}; } var google_conversion_currency = "USD"; var google_remarketing_only = false; /* ]]> */ </script> <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"> </script> <noscript> <div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/your-id/?value={{ subtotal_price | money_without_currency | remove: ',' }}&currency_code=USD&oid={{order.order_number}}&label=your-label&guid=ON&script=0"/> </div> </noscript>
Next, we want to add some code to track order IDs. This is the bit that will prevent us registering duplicate conversions in AdWords. See the Google article for extended details on how it works.
We will add the following line:
if ({{ order.order_number }}) { var google_conversion_order_id = "{{ order.order_number }}"; }
Essentially the code says; check if the page returns an order number, and if so, pass it to the variable.
You may want to check your order number setup in Shopify, because if you edited it, and want it to match up, you’ll need to add an extra prefix. I don’t think you need it to match up 100% though. All this functions serves to do is ensure the same order number can’t be counted twice.
Then we want to add the corresponding noscript tag:
&oid={{ order.order_number }}
Making the code look like this:
<script type="text/javascript"> /* <![CDATA[ */ var google_conversion_id = your-id; var google_conversion_language = "en"; var google_conversion_format = "3"; var google_conversion_color = "ffffff"; var google_conversion_label = "your-label"; if ({{ subtotal_price }}) { var google_conversion_value = {{ subtotal_price | money_without_currency | remove: ',' }}; } if ({{ order.order_number }}) { var google_conversion_order_id = "{{ order.order_number }}"; } var google_conversion_currency = "USD"; var google_remarketing_only = false; /* ]]> */ </script> <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"> </script> <noscript> <div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/your-id/?value={{ subtotal_price | money_without_currency | remove: ',' }}&currency_code=USD&oid={{ order.order_number }}&label=your-label&guid=ON&script=0"/> </div> </noscript>
At which point we’re nearly there.
Finally, we have the option to add some further code.
Shopify have a snippet of liquid code called first_time_accessed (more info on it here). Code placed within this statement *should* only be displayed once.
Since testing it, I’ve found its not 100% reliable. Hence adding the above order ID code.
But it’s better than nothing for the other codes in your checkout code. Ones that don’t have an order ID parameter that can be added (Bing comes to mind).
All you have to do is surround your conversion code with the statement:
{% if first_time_accessed %}
and then close it with:
{% endif %}
All this code goes in the Additional Scrips box in your Shopify dashboard. This section can be located by going to Settings -> Checkout. Scroll down until you find this box:
If any of the above isn’t clear, leave me a comment, and I’ll clarify + improve it.
Nhân Tov says
So my conversion code will look like this? Is that true? I have install the code without the line “{% if first_time_accessed %}” and “{% endif %}” and Google tag assistant said that “No HTTP response” and “Conversion value not set”. Thank you
{% if first_time_accessed %}
/* */
//www.googleadservices.com/pagead/conversion.js
{% endif %}
John King says
Yeah, that code isn’t correct.
Needs the variables for things like price and product ID.
Nhân Tov says
I don’t know why my comment was be shorten. But here is the full code I have installed in the website. I don’t know why it didnt work.
Sorry that I’m so weak in coding. Thanks for your reply.
Nhân Tov says
https://uploads.disquscdn.com/images/4dc45753f0e6862afd7359e3773af9a99ca4647295dba6e6b6ca48eac7c14f76.jpg
Sang Do says
Hi John, the Google Tag was changed. How do I apply your tutorial?
goog_snippet_vars = function() {
var w = window;
w.google_conversion_id = 856476547;
w.google_conversion_label = “EBy_CPuPonMQg5ezmAM”;
w.google_conversion_value = 1.00;
w.google_conversion_currency = “USD”;
w.google_remarketing_only = false;
}
John King says
Hi Sang.
That code looks like conversion tracking code – rather than retargeting code.
The giveaway is that w.google_remarketing_only = false
For the remarketing code, that value will be set to true.
Try again at finding the remarketing code.
AdWords are running a Beta of the new interface. And whilst its possible to find the correct code in the Beta, it won’t match the screens in my video above. If needs be, switch back to the old interface temporarily.
Sang Do says
Great, John.
I found the tag. Really hate new beta interface.
John King says
Agree – it’ll take a little while to get used to it.
Also worth noting, its actually missing a few features, that you have to go back to the old version to get access to (for now).
msutyler says
How can we track conversions from paypal? This seems to be a big issue. When paypal purchases are absent, the stats are grossly skewed.
John King says
Hi Tyler.
Good question. When customers pay with Paypal on Shopify, when the transaction is successful, they get redirected back to the Shopify order confirmation page. This is where we have our checkout code, including AdWords conversion tracking code. Thus, if the customer pays via the Shopify payment gateway, or via Paypal, the same checkout code tracks both.
A link with a bit more info:
https://ecommerce.shopify.com/c/payments-shipping-fulfilment/t/paypal-auto-return-for-website-payments-149022
msutyler says
Strange. I still find that I miss some paypal conversions. Maybe because the user is never routed back to the site. Is this a setting within Paypal?
John King says
There is a setting within PayPal, but it isn’t used for Shopify. Shopify’s integration uses its own settings, with an automatic redirect.
If I think of anything that could be causing an issue, I’ll let you know.
msutyler says
Yeah. Maybe it’s not a Paypal thing. But I do know for a fact that not all conversions are being counted. In both analytics and adwords.
John King says
So with the AdWords conversion tracking code, it’ll only track conversions where the customer has an AdWords ad cookie stored in their browser. If they find the site via organic search, a link on social media, or type it in directly, it won’t track that conversion.
Analytics should have data for most, if not all conversions. Irregardless of what the source was.
Shilpi Agarwal says
Hi Josh,
If I setup a ‘Placed an Order’ Goal in Google Analytics and link that in Google Adwords, with Dynamic Conversion value on (meaning the value of the conversion will be based on the transaction amount that Google Adwords will get from Google Analytics), do I still need to place a conversion tracking code on my Shopify Checkout page?
John King says
Hi Sheila
Who’s Josh? ;)
No, you don’t need to place AdWords conversion tracking code in your Shopify checkout page if you are tracking conversions separately using Google Analytics.
Alexandre Billaut says
Ho Josh,
> Jose : If you chose one conversion only, then it won’t count your recurrent customers.
> Josh: Could you propose the good code at the end, with all the modifications? We would only have to copy/paste then and change the conversion ID and label ID? W
John King says
The last set of code is essentially there for people who want to copy and paste.
Jose A Apezteguia says
Why choose Every Conversions? Its not better have accurate data with only 1 conversion ? Thanks
John King says
You can, however, if people make multiple purchases, they would only track as one.
msutyler says
Hey John,
I’m getting a ‘tag inactive’ error when looking on my code. What’s weird is that last month it was working fine? I haven’t changed anything?
John King says
Yeah, that’s weird, the tag shouldn’t be inactive. Use Google Chrome tag assistant to make sure the remarketing code is on your websites pages.
Faiysal Kothiwala says
{% if first_time_accessed %} & {% endif %} where do i place these? like before and after the whole code?
John King says
That’s correct!
Rick Frankly Jr. says
Hey John,
Great post. Its crazy how little information is available for integrating Google tags with Shopify. This is a big help.
One thing that I found a bit confusing, you say to make 2 modifications, but looking at your final code there is a 3rd…
if ({{ order.order_number }}) {var google_conversion_order_id = “{{ order.order_number }}”;}
May want to add this, not sure if its mission critical but I almost missed it.
Thanks for the great info!
John King says
Hey Rick! Good spot.
For a while I was using that line to help prevent duplicate conversions. But actually the implementation of that can be more complex than desired (for example if someone uses an order number prefix).
The first_time_accessed script should be enough, so I’ve taken that line out to avoid complications.
Dante says
I think you may have left out the very last part as to where to paste the code snippet? I believe it would go at Settings > Shipping > “Additional Scripts” Box ?
John King says
Yes! Had missed that out. Yes, go to Settings > Checkout > Additional Scripts.
Thanks for pointing that out Dante.
Patrick D. Porter says
Hi John,
Awesome post! First one I’ve found that includes the “order_number” variable in it… a few questions for you:
1) I noticed in the Shopify API documentation there is an “order_number” and also “order_id”. Do you know if both work, or what the difference is? https://help.shopify.com/api/reference/order#index
2) Why does the order_number need to be in double quotes here?
if ({{ order.order_number }}) {var google_conversion_order_id = “{{ order.order_number }}”;}
3) Did you prepend order_number with “order.” because of your website specifically? How do I know if I need to do this?
Thanks,
Patrick
John King says
Hi Patrick,
Thanks for the message.
1) Order ID doesn’t seem to exist in the liquid variables options. You’ve linked to the API which we’re not using.
2) That parameter takes a string value, and strings need to be surrounded by quotation marks.
3) See here:
https://help.shopify.com/themes/liquid/objects/order
We have to prepend with order.
Hope that helps.
Patrick D. Porter says
Thank you, John – very helpful. A couple follow up questions
1) What is the purpose of the “remove: ‘,'” section?
2) So if I used a Shopify theme to build my site, I’ll have to use the “order.order_number” parameter?
Cheers,
Patrick
John King says
1) For numbers that are over 999, Shopify adds a comma. This removes it, so that it can be parsed correctly as a number rather than a string.
2) You don’t have to, but is an option.
Patrick D. Porter says
Thank you John, this worked great. Really appreciate you taking the time to post!