Shopify Dynamic Remarketing Setup

Here is how to properly install Dynamic Remarketing Tags on your Shopify store, which will let you run dynamic product ads on the Google Display network.

The code needs to be installed in two places:

  1. At the bottom of your theme.liquid
  2. In the “Additional Scripts” field in your Store’s Admin > Settings > Checkout section

Add the Code to Theme.liquid

Step 1: Create a Remarketing Snippet

In your store’s admin section go to:

  • Online Store > Themes > Edit HTML/CSS
  • Expand the Snippets section and click “Add new snippet”
  • Call the snippet “adwords-remarketing”
  • Paste the following code into the snippet
  • Update the google_conversion_id to use your specific conversion Id (you will find it in your Google AdWords account)
{% comment %} Enter your google conversion id below {% endcomment %}
{% assign google_conversion_id = 0 %}
{% assign shopify_store_country = 'US' %}
{% if shop.currency == 'CAD' %}
{% assign shopify_store_country = 'CA' %}
{% endif %}

<script type="text/javascript">

 {% if template contains 'cart' %}
 var google_tag_params = {
 ecomm_prodid: [{% for item in cart.items %}'shopify_{{ shopify_store_country }}_{{ item.product.id }}_{{ item.variant.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
 ecomm_pagetype: 'cart',
 ecomm_totalvalue: {{ cart.total_price | money_without_currency | remove: ',' }}
 };

 {% elsif template contains 'collection' %}
 var google_tag_params = {
 ecomm_prodid: [{% for item in collection.products limit:5 %}'shopify_{{ shopify_store_country }}_{{ item.id }}_{{ item.variants.first.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
 ecomm_pagetype: 'category',
 ecomm_category: '{{ collection.handle }}'
 };

 {% elsif template contains 'index' %}
 var google_tag_params = {
 ecomm_pagetype: 'home'
 };

 {% elsif template contains 'product' %}
 var google_tag_params = {
 ecomm_prodid: 'shopify_{{ shopify_store_country }}_{{ product.id }}_{{ product.selected_or_first_available_variant.id }}',
 ecomm_pagetype: 'product',
 ecomm_totalvalue: {{ product.selected_or_first_available_variant.price | money_without_currency | remove: ',' }}
 };

 {% elsif template contains 'search' %}
 var google_tag_params = {
 ecomm_prodid: [{% for item in search.results limit:5 %}'shopify_{{ shopify_store_country }}_{{ item.id }}_{{ item.variants.first.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
 ecomm_pagetype: 'searchresults'
 };
 {% else %}
 var google_tag_params = {
 ecomm_pagetype: 'other'
 };

 {% endif %}

 /* <![CDATA[ */
 var google_conversion_id = {{ google_conversion_id }};
 var google_custom_params = window.google_tag_params;
 var google_remarketing_only = true;
 /* ]]> */
</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="//googleads.g.doubleclick.net/pagead/viewthroughconversion/{{ google_conversion_id }}/?value=0&amp;guid=ON&amp;script=0"/></div>
</noscript>

This code is also available on GitHub: Shopify Remarketing Code Snippet

Step 2: Install the snippet in your Theme file

Open up the theme.liquid file and add the following line of code before the closing </body> tag:

<!-- Dynamic Remarketing -->
{% include 'adwords-remarketing' %}

Add the Code to Checkout Scripts

In your Shopify Store’s Admin, go to:

  • Settings > Checkout
  • Scroll down to the “Additional Scripts” field.
  • Copy and paste the code below into the “Additional Scripts” field
  • Make sure you update the code with your own custom google_conversion_id.
<!-- Google Dynamic Remarketing -->
{% comment %} Enter your account specific value below {% endcomment %}
{% assign google_conversion_id = 0 %}
{% assign shopify_store_country = 'US' %}
{% if shop.currency == 'CAD' %}
{% assign shopify_store_country = 'CA' %}
{% endif %}
<script type="text/javascript">
var google_tag_params = {
 ecomm_prodid: [{% for item in order.line_items %}'shopify_{{ shopify_store_country }}_{{ item.product.id }}_{{ item.variant.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
 ecomm_pagetype: 'purchase',
 ecomm_totalvalue: {{ total_price | money_without_currency | remove: ',' }}
};
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = {{ google_conversion_id }};
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</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="//googleads.g.doubleclick.net/pagead/viewthroughconversion/{{ google_conversion_id }}/?guid=ON&amp;script=0"/></div>
</noscript>

Download the code from Github here: Shopify Checkout Remarketing Code

Final Step: Verification

Once you’ve installed all your code, it’s time to run through your site and main pages (collection, product, cart, and purchase pages) with Google Tag Assistant installed. This will help you troubleshoot any errors.

Common errors include:

  • Products not properly uploaded to Google Merchant Center
  • Google Conversion Id not properly set

21 Comments

  1. Good stuff Alex. I am trying to setup dynamic retargeting adds. Installed the code as above but not sure how to proceed with creating an audience of cart abandoners and creating proper tags. Also installed the google tag manager and verified it is working. Help me understand what your code does for retargeting? How we need to use Google Tag manager with the code modification above? Is there any resource i can read to get better at it?

    Like

    Reply

  2. Hi Asif,

    You don’t need Google Tag Manager to use the above code. It should **just work** if you installed it correctly.

    In terms of what the code does, it sets a Google remarketing cookie on your visitors machine, including which specific products the user browsed, and where in the “funnel” they were (product page, cart, purchase, etc…)

    For more information about this checkout Google’s intro to Dynamic Remarketing:
    https://support.google.com/adwords/answer/6077124?hl=en
    https://support.google.com/adwords/answer/6287125?hl=en

    Best,

    Alex

    Like

    Reply

    1. Hi Adrian,

      I checked out your site, and Google Tag Assistant validated all the remarketing tags correctly. Did you get this to work on your end? If you are still seeing no HTTP response detected, try waiting a little longer for the page to completely load — sometimes it could be a temporary connectivity issue that is causing the communication problem. Let me know if you’re still having issues.

      Good luck!
      Alex

      Like

      Reply

  3. Hi Adrian,

    This is usually caused by a typo or bug in the javascript code. (Either the code got messed up during copy/paste, or it’s possible there’s a typo in my code here). If you use Google Chrome, do an “inspect element” and see if there are any JS errors on the page.

    If you mention your site URL I can also take a quick look.

    Best,

    Alex

    Like

    Reply

  4. Hi Alex-

    Great work! The tag manager thinks everything looks great- but I’m still getting issues in Google Adwords itself. I’m currently using a Google Spreadsheet Feed into Google Merch Center. In my shared library- the Remarketing tag reads:

    There are problems with some of your custom parameters for Retail (AdWords)
    The tag is active but we found some issues with your custom parameters.

    Check that all your custom parameters are implemented correctly. Custom parameters are necessary to enable dynamic remarketing.

    Only 187 of 2,894 page visits that have passed an ID (or 6%) match IDs in your Merchant Center feed
    Some values for the custom parameter “ecomm_pagetype” are missing
    The tag is not passing all required values for “ecomm_pagetype”.
    Consider adding the remarketing tag with custom parameter “ecomm_pagetype” to all your webpages. The “ecomm_pagetype” custom parameter is recommended for dynamic remarketing. Learn about the dynamic remarketing tag. Check that you’re using the correct custom parameters using the Tag Assistant Chrome extension.
    View tag implementation instructions
    Top 10 values for “ecomm_pagetype”
    product
    collection
    index
    category
    home
    cart
    product.preorder
    page
    other
    customers/login
    Some values for the custom parameter “ecomm_totalvalue” are invalid
    The tag has passed at least one non-numeric value for “ecomm_totalvalue”.
    Values for the custom parameter “ecomm_totalvalue” need to be numeric. Check that “ecomm_totalvalue” has been implemented correctly using the Tag Assistant Chrome extension. Learn about the dynamic remarketing tag.
    View tag implementation instructions
    Top invalid values for “ecomm_totalvalue”
    (null)
    Top 10 firing ecomm_prodid
    ECOMM_PRODID VIEWS IN FEED
    shopify_US__ 2,084 no
    shopify_US_9516127373_ 1,278 no
    shopify_US_9110597645_ 74 no
    shopify_US_8100132929_ 65 no
    shopify_US_8442699725_ 61 no
    shopify_US_3625864513_ 41 no
    shopify_US_1033952129_ 37 no
    shopify_US_8107397313_ 36 no
    shopify_US_1033949377_ 36 no
    shopify_US_9110616781_ 34 no

    Like

    Reply

  5. Hi Alex,

    Thank You for sharing this code. It is super helpful.
    I have got a quick question that I want to confirm.
    When I check it on the tag assistant. It is working on collections-product-cart pages.
    On the homepage : It is showing in red “some products are not valid”
    website : http://www.shegulny.com

    Kindly advise.

    Like

    Reply

  6. Hi Alex,

    Ignore my previous post. I am abel to sort it out.
    The error on the homepage was because of the merchant center validation that was ticked. Removed that on the tag assistant and it is working now.

    Thank you so much for these steps.
    Much Appreciated!!

    Like

    Reply

  7. Hi, this code and the instructions you have provided are very helpful. I have been searching all day for the best way to implement dynamic remarketing on my site and it is not easy at all.

    I curious if you can help me figure out a small issue I’m having. I do not use the Shopify google shopping app because I have read too much negative feedback about it. Instead, I am uploading my products to the Google merchant center via spreadsheet.

    After implementing your code, tag manager is showing me the error message “Some products are not valid”. I am trying to figure out if the shopify product.id is the same thing as my shopify Variant Sku. In google merchant center I have the “Item ID” for my products set to the same value as my shopify “Variant SKU” in shopify.

    So If I understand correctly, this line of code:

    ecomm_prodid: ‘shopify_{{ shopify_store_country }}_{{ product.id }}_{{ product.selected_or_first_available_variant.id }}’,

    sends adwords the shopify product.id which should match up with a merchant center item id. I have come to learn however that the product.id in shopify may not be the same as the variant sku.

    For example, when I view the xml code for one of my products I see “10369113994” Is this integer important? Is this the reason for the shopify google shopping app? Because it passes this number through to google?

    I’m a bit confused so any help you can offer would be much appreciated. Thanks

    Like

    Reply

    1. Hi Faucetlist,

      This collection template sets the product id to look something like this:

      shopify_US_123456789_987654321

      US == Currency
      First Number == Product Id
      Second Number == Variant Id

      If you want your remarketing product id’s to just be the variant Id, you would change your code to this:

      ecomm_prodid: ‘{{ product.selected_or_first_available_variant.id }}’,

      Hope this helps!

      Best,
      Alex

      Like

      Reply

  8. Hi, thanks for the reply Alex. I was able to get it to work by using: ecomm_prodid: ‘{{ product.variants.first.sku }}’,

    Since my items are set up in merchant center using SKU as the item id this was the easiest solution. I’m putting this here in case it’s useful to anyone else.

    Like

    Reply

  9. This is an amazing blog Alex!!!

    I am having trouble setting up Dynamic Remarketing for Facebook.

    I keep getting the error in product catalog diagnostics.
    “Missing content_type parameter from “AddToCart” in Popek Shopify Feed Pixel”
    “Missing content_ids parameter from “AddToCart” in Popek Shopify Feed Pixel”

    Will you make an article specific to Facebook Dynamic Remarketing? Thanks so much!!!

    Like

    Reply

  10. This is amazing, but my product ID keeps coming out without the country code and I can’t figure out why?

    Like so:
    shopify__11588107731_46058125651

    It should display as
    shopify_AU_11588107731_46058125651

    Like

    Reply

    1. Hi Matt,

      Currently the script is coded to only support USD and CAD (I will update to support AUD shortly). But it’s relatively easy to update yourself:

      Change line 3 from this:
      {% assign shopify_store_country = ‘US’ %}
      To this:
      {% assign shopify_store_country = ‘AU’ %}

      That should do the trick. Let me know if not.

      Best,

      Alex

      Like

      Reply

  11. Hello Alex

    Thank you for useful blog.

    About “Add the Code to Checkout Scripts”, I already added the Google Conversion code in to CHECKOUT/“Additional Scripts” field.

    How do I deal with this case?

    Like

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s