How to add Google Dynamic Remarketing code in Shopify

I suggest stores just setup their analytics correctly then using remarketing through that as opposed to the dynmaic remarketing code.

Run Google Shopping ads? Get the free definitive guide to Google Shopping for Shopify (no optin required): https://www.digitaldarts.com.au/google-shopping
1 Like
Shopify Partner
51 1 4

Don't forget the code to include on your checkout page:

https://github.com/Czarto/ShopifyScripts/blob/master/settings/checkout/adwords-remarketing.liquid

 

Digital Marketing @ Manitobah.ca | Pendleton.ca | Aigle.ca
0 Likes
New Member
4 0 0

everyone is giving different answers and we are getting confused...

0 Likes
Shopify Partner
51 1 4

Hi Yasir,

Here is a writeup on how I implement dynamic remarketing on the sites I manage, and it works as it is supposed to:

https://business.czarto.com/2017/02/07/shopify-dynamic-remarketing-setup/

In a nutshell, you need to install this code in your checkout scripts (available on github here):

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

Then you need to install this code at the bottom of your theme.liquid (available on github here):

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

 

IMPORTANT: Update your google_conversion_id and with the value specific to your adwords account.

Hope this helps.

Alex

Digital Marketing @ Manitobah.ca | Pendleton.ca | Aigle.ca
0 Likes
New Member
4 0 0

Alex,

Thanks for the detailed write-up.  I noticed that the instructions you posted here are slightly different than the ones posted on your Website that you linked to.  The good news is I followed the instructions on your Website, and the tag assistant is finally coming back clean!  I did have two questions about the script for the "settings > checkout > additional scripts" section though:

1) You have: 

{% assign shopify_store_country = "CA" %}

Should the "CA" be "US" for US stores?  You built in an "if" statement for the theme file/snippet, but it's not included here.  I manually changed it to "US" instead of "CA" anyway, and it seems to be working...

2) You mention (on the Website) to make sure and change the "google_conversion_label".  You don't mention this on your post here.  I couldn't find anything about "google_conversion_label" in the script, so I was wondering if that was correct.

0 Likes
Shopify Partner
51 1 4

Hi Zoo,

Good catches. Thanks.

1) Yes, CA is for Canadian stores, and US for US stores. I've updated the code on github, on my blog, and on here. I've replaced it with an if statement that changes the country value based on shop currency. (But also fine to just hardcode it like you did)

2) google_conversion_label is not needed. I initially had it included there because I posted a sample of how your Google AdWords conversion tracking script should look like (which uses the conversion label). If interested in the script, it's available here: https://github.com/Czarto/ShopifyScripts/blob/master/settings/checkout/adwords-conversion.liquid (It includes total checkout price, as well as order number that Google uses to deduplicate conversions)

Thanks for catching the errors!

 

Digital Marketing @ Manitobah.ca | Pendleton.ca | Aigle.ca
0 Likes
Shopify Partner
6 0 0

Hi Alex,

I get and error "No HTTP response detected" when using your code in the Google Tag Assistant.

0 Likes
Highlighted
Tourist
29 0 3

This worked First time - thank you so much! 

(UPDATE) For some reason code from the tag is now diplayed below my footer - wierdly its just a little bit of the tag - Here.

Anyone else had this problem / Know how to fix this?

Thanks!  

 

0 Likes
Tourist
4 0 2

In the example above, if your product variants have different prices, you will need to use this code:

product.selected_or_first_available_variant.price

... instead of this code:

product.price

Thrivous is a human enhancement company. Its mission is to help people access technology with the greatest potential to improve their brains and bodies. In pursuit of that mission, it develops and distributes evidence-based nootropics for cognitive enhancement, including Clarity, the daily nootropic to improve focus, memory, and mood, and to support brain function.
0 Likes