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.