Last Updated: April 8, 2019

Here is how to properly install Google Ads Dynamic Remarketing Tags on your Shopify store.

The code needs to be installed in two places:

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

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

{% assign shopify_store_country  = 'US' %}
{% if shop.currency == 'CAD' %}
{% assign shopify_store_country  = 'CA' %}
{% elsif shop.currency == 'AUD' %}
{% assign shopify_store_country  = 'AU' %}
{% endif %}

<!-- Global site tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-{{ google_conversion_id }}"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'AW-{{ google_conversion_id }}');
</script>

<script>
  function getUserId() {
    if(typeof __st !== 'undefined' && __st["cid"]) {
      return __st["cid"];
    } else {
      return;
    }
  }

  var _data = {'send_to': 'AW-{{ google_conversion_id }}', 'ecomm_pagetype':'other', 'user_id': getUserId()};

{% if template contains 'cart' %}
  _data["ecomm_pagetype"] = 'cart';
  _data["ecomm_prodid"] = [{% for item in cart.items %}'shopify_{{ shopify_store_country  }}_{{ item.product.id }}_{{ item.variant.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}];
  _data["ecomm_totalvalue"] = '{{ cart.total_price | money_without_currency  | remove: ','  }}';
  
{% elsif template contains 'collection' %}
  var _prodid = [{% for item in collection.products limit:5 %}'shopify_{{ shopify_store_country  }}_{{ item.id }}_{{ item.variants.first.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}];
  _data["ecomm_pagetype"] = 'category';
  _data["ecomm_category"] = '{{ collection.handle }}';
  
{% elsif template contains 'index' %}
  _data["ecomm_pagetype"] = 'home';
  
{% elsif template contains 'product' %}
  _data["ecomm_prodid"] = 'shopify_{{ shopify_store_country  }}_{{ product.id }}_{{ product.selected_or_first_available_variant.id }}';
  _data["ecomm_pagetype"] = 'product';
  _data["ecomm_totalvalue"] = '{{ product.selected_or_first_available_variant.price | money_without_currency  | remove: ','  }}';
  
{% elsif template contains 'search' %}
  _data["ecomm_prodid"] = [{% for item in search.results limit:5 %}'shopify_{{ shopify_store_country  }}_{{ item.id }}_{{ item.variants.first.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}];
  _data["ecomm_pagetype"] = 'searchresults';
		
{% endif %}

  gtag('event', 'page_view', _data);
</script>

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

Step 2: Include the snippet in your Theme file

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

{% include 'adwords-remarketing' %}

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 and google_conversion_label
  • NOTE: The code below also includes Google Ads Conversion Tracking. If you already have conversion tracking installed, make sure you are not duplicating conversions.
{% if first_time_accessed %}
{% comment %} Enter your account specific values below {% endcomment %}
{% assign google_conversion_id = 123456789 %}
{% assign google_conversion_label = "abcdefghijklmnop" %}

{% assign shopify_store_country  = 'US' %}
{% if shop.currency == 'CAD' %}
{% assign shopify_store_country  = 'CA' %}
{% elsif shop.currency == 'AUD' %}
{% assign shopify_store_country  = 'AU' %}
{% endif %}


<!-- Global site tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-{{ google_conversion_id }}"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'AW-{{ google_conversion_id }}');
</script>

<!-- Event snippet for Web Order conversion page -->
<script>
    function getUserId() {
      if(typeof __st !== 'undefined' && __st["cid"]) {
        return __st["cid"];
      } else {
        return;
      }
    }

    // Conversion
    gtag('event', 'conversion', {
        'send_to': 'AW-{{ google_conversion_id }}/{{ google_conversion_label }}',
        'value': {{ checkout.subtotal_price | money_without_currency | remove: ',' }},
        'currency': '{{ shop.currency }}',
        'transaction_id': '{{ order.order_number }}'
    });

    // Remarketing
    gtag('event', 'page_view', {
        'send_to': 'AW-{{ google_conversion_id }}',
        'user_id': getUserId(),
        'ecomm_pagetype': 'purchase',
        'ecomm_prodid' : [{% for item in order.line_items %}'shopify_{{ shopify_store_country }}_{{ item.product.id }}_{{ item.variant.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
        'ecomm_totalvalue' : '{{ total_price | money_without_currency | remove: ',' }}'
    });
</script>

{% endif %}

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.

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 )

Connecting to %s