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 %}



 {% 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 %}

 /*  */




<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>

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 %}

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: ',' }}
};


/*  */




<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>

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

54 Comments

  1. Hi Alex,

    Thanks for this great guide and help.

    I have a one question regarding this if you could help me on this. I have followed your guide step by step and implemented the code on my website (https://www.stylenol.com) correctly. But, still I am getting 2 errors in the Tag Assistant as I tried to validate my products by entering my merchant center account ID in tag assistant and the errors are:

    1. Some products are not valid
    2. Tag Parameter object could not be parsed

    If you could help, that would be appreciated.

    Thanks,
    Kamaljit

    Like

    1. Hi Kamaljit,

      Sorry for the delay in replying. I took a look at your site, and the pages I visited appear to be functioning properly (with no errors anyway). Did you manage to resolve this yourself?

      Best,

      Alex

      Like

      1. Hi Alex,

        Thanks for your response!

        I am still getting the same error (Some products are not valid) as before on my Home and Product pages. Is there any problem with the Tag Assistant? Any ideas or suggestions on this would be helpful.

        Looking forward!

        Thanks,
        Kamal

        Like

      2. Hi Kamal,

        I’m not sure. I wasn’t getting any errors when I visited your home page. My suggestion would be:

        1. Do a view source on your page and take a look at what the script is outputting — do the productIds look right?
        2. Compare those product Ids to what you have in your Google Merchant Center — They should be identical

        If both the above are correct and match each other, then it’s either your Tag Assistant that is missfiring for some reason, or there’s a javascript error somewhere in your code.

        Note, also, that the code in this article is starting to become old, and I believe there is a new way that Google recommends for remarketing. I will, at some point, update to the newer code.

        Good luck!
        Alex

        Like

  2. Hi Bro Alex,
    I am stuck on a very small thing.

    My store’s country is Australia And currency is AUD. I have a few questions.

    1) So how this code below will be for me?
    _________________________________
    {% assign shopify_store_country = ‘US’ %}
    {% if shop.currency == ‘CAD’ %}
    {% assign shopify_store_country = ‘CA’ %}

    ============
    Above one changed to Like this?

    {% assign shopify_store_country = ‘AU’ %}
    {% if shop.currency == ‘AUD’ %}
    {% assign shopify_store_country = ‘AU’ %}

    2) Should I use the semicolon (‘ ‘ ) with AUD and AU ?

    3) Should I keep the second bracket with conversion id ( {{ google_conversion_id }}/ ) ? or just remove the whole thing and just put the conversion id?

    Thanks for your Help. I would really appreciate it.
    With best
    Nihar

    Like

    1. Hi Nihar,

      1 + 2: Yes, that code is correct, and you need the currency surrounded by single quotes. To be safe, take a look here: https://github.com/Czarto/ShopifyScripts/blob/master/snippets/adwords-remarketing.liquid for the latest code including AUD support.

      3: It’s up to you, either hard-code your conversion Id, or assign it once to the variable at the top. I prefer assigning it once, as I manage several stores, and this way it is easier to update the conversion id without making mistakes.

      Best,

      Alex

      Like

    1. Hi Ellen,

      I’m not sure exactly what Global site tag / event snippet you are referring to? I *think* the answer is no, you don’t need to include them, but could you include a link to what you are referring to so I can give a definite answer?

      Thanks! 🙂

      Alex

      Like

      1. This is the code that Adwords asks us to install on our website.. instructions are: The AdWords remarketing tags have been replaced by a global site tag and an event snippet. To set up remarketing, you’ll need to add the global site tag and an event snippet on your website. Even though your previous remarketing tags will still work, we recommend that you use the new tag and snippet.

        I tried your Shopify theme changes and had no success getting them to work. I kept getting errors in Google Adwords that the product IDs did not match the ones on my product feed. I ended up installing a shopify app that would code my site correctly for Adwords remarketing, and since then I haven’t got the error in Adwords again.

        Like

      2. Thanks Ellen — I haven’t looked at the default AdWords remarketing code in a while — looks like there were updates made! I’ll update this post once I have things figured out.

        If the app works well for you, then that’s probably the simplest solution.

        Best,
        Alex

        Like

  3. Hey Alex,

    I noticed an issue.. With google tag assistant in chrome the checkout remarketing code is not showing.. I am unsure why. Have you had this issue? I placed it in additional scripts. We are on plus.

    Like

    1. Hi Mjlc,

      Looking into this now. Initial results are that:

      1. If not already done, you need to enable checkout.liquid in your themes (I believe your Merchant Success Manager MSM needs to enable this), and you then need to include the adwords-remarketing snippet to that theme file as well.

      2. I my script currently doesn’t check for “checkout” template type. I need to test this more, as I’m not 100% sure what the name of the template will be on the checkout stage. I will look into this further and get back to you.

      (Related to your other comment about duplication, I don’t think this should be a concern for remarketing purposes. But to explicitly answer your question – no, I do not do any de-duplication on my end)

      Best,

      Alex

      Like

      1. Hey Alex,

        Its enabled. If I add the include to the checkout.liquid it works fine.. But do I need it in the additional scripts?

        Like

    1. Hi Geoffrey,

      Sorry for the late reply.

      I’ll add a note to update the code for more countries.

      Just to confirm however — for this to work in Shopify, you will need a separate Store account for each currency you sell in. Is this the setup you have?

      Best,

      Alex

      Like

  4. Hello Alex,

    I implemented the tag however I’m getting the following errors on the Audiences section of my Adwords:

    -There are problems with some of your custom parameters for Retail (AdWords)
    —ecomm_prodid and Merchant center feed values don’t match
    —some values for ecomm_pagetype are missing

    -There are problems with some of your custom parameters for Retail (Google Analytics)
    (this one is probably leftovers from my previous attempt at getting dynamic remarketing through GA)

    What could the issue be? The SKU’s don’t match.

    Like

    1. Hi Idris,

      ecomm_prodid does not match:
      Both the products in your Google Merchant center, and the code being output on your web pages, should have a product id similar to this:
      shopify_US_12345678_9876543219
      Check in Google AdWords which product id’s are not matching — it may give you a hint into what is going on.

      ecomm_pagetype missing
      I believe this is just AdWords complaining that it has not seen ALL the different page types. But check again in AdWords for the actual values it is receiving to see if you can get any hints into what is going on.

      Sorry I couldn’t help more.

      Best,

      Alex

      Like

  5. Hi Alex,

    Great post, very useful. Unfortunately I’m still getting an error with products being listed as not valid. I’ve checked the id’s against products in my feed and they appear to be correct. Can you think of a reason why Tag Assistant would be reporting this? I’ve only just installed the code so will wait to see if anything changes here.

    Like

  6. Hi Alex,
    Super useful post. I notice in the first snippet of code you have:
    src=”//googleads.g.doubleclick.net/pagead/viewthroughconversion/{{ google_conversion_id }}/?value=0&guid=ON&script=0″

    whereas google now shows this in their remarketing code:
    src=”//googleads.g.doubleclick.net/pagead/viewthroughconversion/{{ google_conversion_id }}/?guid=ON&script=0″

    Is that a big deal to omit value=0& ?

    Like

  7. Hi Alex,
    Thanks for putting this together. I’m having a few issues and hoping its a simple solve. I added the code to both the .theme and checkout additional code sections. When I check the site using Tag Assistant it doesn’t show any errors but in the Audiences section of Adwords, I’m getting tag is active but issues with the custom paratmeters message. Site is https://point6.com. Any suggestions?

    Like

  8. Hey Alex!
    thank you so much for this helpful article 🙂

    I wonder if you could help me –
    I have Shopify store with ILS currency (Israel).
    Google Shopping app will not for me… I get an error “sorry, your country isn’t supported”
    I have read the other article you wrote:
    https://business.czarto.com/2016/06/14/shopify-google-shopping-feed/
    But according to the instructions, I still need to install this app 😦
    Is there any way I can sync my Shopify store (product fee) directly to my Adwords account?

    thanks again,
    Lior

    Like

    1. Hi Lior,

      Sorry for the delayed response.

      You can still use the Shopify feed as described in my article as you mentioned. Even without the Shopify App present, it will still upload products to your Merchant center (make sure you set your currency properly). WIthout the Google Shopping app however, you will need to hard-code (or ignore or set in merchant center) values such as Age, Gender, and Product Categories that are normally set within the Shopping app.

      Hope that helps.

      Alex

      Like

  9. Hey Alex, your website is amazing ! It’s by far the best tutorial online for setting up the google remarketing tag !
    I had a small question, on one of my website, google remarketing tag appear in blue in the google tag manager however on the other one it appears in green do you know why ?

    Thank you,

    Etienne

    Like

    1. Hi Etienne,

      The blue tag means “non-standard implementation”. Generally, if things are working well, you shouldn’t have to worry about it. It means the tag is not a direct copy/paste from what Google expects, and has been modified from the baseline code.

      This is likely because Shopify outputs their Google Analytics code in a non-standard format.

      Best,

      Alex

      Like

  10. 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

  11. 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

    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

  12. 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

  13. 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

  14. 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

    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

  15. 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

  16. 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

  17. 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

  18. 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

    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

  19. 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

  20. 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

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s