Categories
Digital Marketing Google Ads Shopify

Google Ads Dynamic Remarketing for Shopify

How to properly install Google Ads Dynamic Remarketing on your Shopify store.

Last Updated: September 25, 2020

STEP 1
Activate Dynamic Remarketing in Google

  1. Go to Google Ads > Tools & Settings > Shared Library > Audience Manager > Audience Sources
  2. Click Set up tag in the “Google Ads tag” card
  3. Remarketing: Choose “Collect data on specific actions…
  4. Business Type: Choose “Retail
  5. Retail Parameters: Select All Parameters
  6. Click Save and continue.
  7. Click on Install Tag Yourself
  8. In the first code box, look for the number at the end of the first line of code and write it down or copy it. This is your Google Conversion Id — you will need it in the next step.
<!-- Global site tag (gtag.js) - Google Ads: 123456789 -->
  1. Click Continue and then Done

STEP 2
Install the Remarketing Code in Theme.liquid

In your store’s admin section go to:

  • Online Store > Themes > Actions > Edit Code
  • Expand the Snippets section and choose Add new snippet
  • Call the snippet “adwords-remarketing
  • Paste the code below into the snippet
  • Enter your google_conversion_id that you obtained in Step 1.8 above.
{% comment %}
Google Ads Dynamic Remarketing Script by Alex Czartoryski
https://business.czarto.com/2017/02/07/shopify-dynamic-remarketing-setup/

This version: Sept 30, 2020
The latest version of this script available here:
https://github.com/Czarto/ShopifyScripts/blob/master/snippets/adwords-remarketing.liquid
{% endcomment %}

{% comment %}Set to false if GTAG is already loaded on the page. Leave to true if unsure.{%endcomment%}
{% assign load_gtag = true %}

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

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

{% assign google_event = false %}
{% assign google_items = false %}
{% assign google_value = false %}
{% if template contains 'cart' %}
	{% assign google_event = 'add_to_cart' %}
	{% capture google_items %}{% for item in cart.items %}{'id':'shopify_{{ shopify_store_country  }}_{{ item.product.id }}_{{ item.variant.id }}','google_business_vertical': 'retail'}{% unless forloop.last %}, {% endunless %}{% endfor %}{% endcapture %}
	{% assign google_value = cart.total_price %}
{% elsif template contains 'collection' %}
	{% assign google_event = 'view_item_list' %}
	{% capture google_items %}{% for item in collection.products limit:5 %}{'id':'shopify_{{ shopify_store_country  }}_{{ item.id }}_{{ item.variants.first.id }}','google_business_vertical': 'retail'}{% unless forloop.last %}, {% endunless %}{% endfor %}{% endcapture %}
{% elsif template contains 'product' %}
	{% assign google_event = 'view_item' %}
	{% capture google_items %}{'id':'shopify_{{ shopify_store_country  }}_{{ product.id }}_{{ product.selected_or_first_available_variant.id }}','google_business_vertical': 'retail'}{% endcapture %}
	{% assign google_value = product.selected_or_first_available_variant.price %}
{% elsif template contains 'search' %}
	{% assign google_event = 'view_search_results' %}
	{% capture google_items %}{% for item in search.results limit:5 %}{'id':'shopify_{{ shopify_store_country  }}_{{ item.id }}_{{ item.variants.first.id }}','google_business_vertical': 'retail'}{% unless forloop.last %}, {% endunless %}{% endfor %}{% endcapture %}
{% endif %}

{% if google_event %}
<script>
	gtag('event', '{{ google_event }}', {
	  'send_to': 'AW-{{ google_conversion_id }}',
	  {% if google_value %}'value': '{{ google_value | divided_by: 100.0 }}',{% endif %}
	  'items': [{{ google_items }}]
	});
</script>
{% endif %}

The latest version of this code is available on Github

Add snippet to your Theme file

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

{% include 'adwords-remarketing' %}

STEP 3
Install Remarketing in the Checkout Scripts

  • In the very bottom left hand corner the Shopify Admin choose Settings and then Checkout
  • Scroll down to the Additional Scripts section.
  • Copy and paste the code below into the “Additional Scripts” field and update google_conversion_id with your value from step 1.8 as before.
{% comment %}
Google Ads Dynamic Remarkting Script by Alex Czartoryski https://business.czarto.com/

This version: Sep 30, 2020
The latest version of this script available here:
https://github.com/Czarto/ShopifyScripts/blob/master/settings/checkout/adwords-remarketing.liquid
{% endcomment %}

{% comment %}Set to false if GTAG is already loaded on the page. Leave to true if unsure.{%endcomment%}
{% assign load_gtag = true %}

{% if first_time_accessed %}
{% comment %} Enter your account specific values 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 %}


{%if load_gtag %}
<!-- Global site tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-{{ google_conversion_id }}"></script>
{% endif %}
<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>
    // Google Ads Remarketing
    gtag('event', 'purchase', {
	  'send_to': 'AW-{{ google_conversion_id }}',
	  'value': '{{ total_price | divided_by: 100.0 }}',
	  'items': [{% for item in order.line_items %}{'id':'shopify_{{ shopify_store_country }}_{{ item.product.id }}_{{ item.variant.id }}','google_business_vertical': 'retail'}{% unless forloop.last %}, {% endunless %}{% endfor %}]
	});
</script>

{% endif %}

Download the lastest version from Github

STEP 4
Verification

Once you’ve installed all your code, it’s time to run through your main pages (collection, product, cart, and purchase pages) with Google Tag Assistant installed to make sure there are no errors.

Next Steps
Configure your Remarketing Audiences

Now that your store is collecting dynamic remarketing data, the next step is to properly organize and segment your visitors into Purchasers, Cart Abandoners and Product Viewers. This is covered in the next post about Google Ads Remarketing Audiences.

Additional Reading…

46 replies on “Google Ads Dynamic Remarketing for Shopify”

Hi Alex, thanks for clearing up the confusion re remarketing vs Shopify’s shopping plugin. Also knowing there are 2 GTAG events firing and that is expected (rather than undesirable) is great to know.
I’d ask your thoughts on multi currency stores as your script doesn’t have provision for handling that. Being Aussie we accept multi currency so it can make a big difference to our stats. I imagine you have similar challenges with CAD/USD. Have you considered something like this: ?

‘value’: {{ checkout.total_price | money_without_currency | remove: ‘,’ }},
‘currency’: ‘{{ order.currency }}’,

Like

Hi Mark — I think this is a valid point. However, for the sites I work with, they are all single currency (with multiple Shopify instances to handle additional currencies). So I don’t really have a way to test this sort of change (but I’ll add it to my todo list and get to it at some point — or if you’re a developer, feel free to submit the code change in GitHub).

Like

Hello,

could you please help me by changing this code according to the one you use? The new tracking doesn’t work for me. The one below was working fine for me. With yours Im getting prodid errors.

gtag(‘event’, ‘page_view’, {
‘send_to’: ‘AW-xxxxxxxxxxx’,
‘ecomm_pagetype’: ‘{{ template }}’,
‘ecomm_prodid’: ‘shopify_US_{{ product.id }}_{{ product.variants.first.id }}’,
‘ecomm_totalvalue’: ‘{{ product.price_min | money_without_currency }}’,
});

Like

Hi Γιάννης Αθανασίου,

Option 1: You can use the old version of the code here:
https://github.com/Czarto/ShopifyScripts/blob/5cd77bf05c408e73fc6cb84fb41e3a2d808b4e56/snippets/adwords-remarketing.liquid

Option 2: Troubleshoot why your product Id’s are not matching. What is your store’s country? I noticed in the code you posted you have your product Id’s hardcoded to “US” product ids. Maybe the new code isn’t detecting your country properly? (In which case you can try hard-coding the country code into your product ids).

Hope this helps
Alex

Like

Hi!

Does this really track conversions? Dont I have to add the “conversion label” to the tag in order for that to happen?

The old tag you had uploaded before you updated to this one, had the conversion label included.

Like

Hi Sandra,

You are correct:

This new script DOES NOT track Google Ads conversions anymore.
It DOES however still track Remarketing purchase events.

I removed the Google Ads conversion tracking because
(1) This post is about remarketing, and not conversion tracking, and so I didn’t want to inject extra side effects
(2) I’ve transitioned to using Shopify’s Google Shopping channel to track Google Ads conversions. With some tweaks, it works well enough, and means less code to maintain on my side. A writeup of my recommended changes to the Google Shopping channel here: https://business.czarto.com/2020/09/29/shopify-google-ads-conversions/

Alex

Like

Hi, thank you for this script.

Are we able to use this script alongside the Google Channel conversion tags? Is there anything extra we need to do to make them work or avoid conflicts?

There’s a line here (assign load_gtag), should this be set to false if we’re using the Google Channel integration?

Like

Yes, you can use the script alongside the Google Channel conversion tags (they both record slightly different things)
Nothing else is needed to avoid conflicts, you can install them as is.

For the “load_gtag” variable, leave it to true to be safe. I’ve experimented with NOT loading it to save on load times, but it’s inconsistent in it’s behaviour — you would need to test this on your site using the Google Chrome Tag extension.

Hope this helps.

Best,
Alex

Like

Hi Alex, thanks for this article!
Im new to Shopify, but i have already been doing dynamic remarketing with Woocommerce.
My question are:
1- how should i upload products from Shopify to Google Ads? Do you recommend any feed app? Or is there any built in solution from Shopify?
2- On the “Checkout Scripts” there are a few lines corresponding to “Conversion”. Why do we need it? I mean, if we have already enabled enhanced ecommerce through Shopify’s platform, we are supposed to be tracking purchase conversions, right? So arent we duplicating things if we are tracking purchases through enhanced ecommerce and also with your lines of codes (the ones included on the checkout scripts)?
Thank you very much!

Like

Hi DJWilko,

1. I use the Google Shopping app by Shopify to upload feeds. You should be able to find it in the app store.
2. Enhanced Ecommerce tracks sales in your Google Analytics. The tracking script in this article tracks conversions directly in Google Ads. *IF* you are importing conversion data from Google Analytics into Google Ads, then you should be ok. I personally prefer sending the sales directly to Google Ads (although I haven’t revisited that decision in a while, so I’m not sure if it’s ideal or not).

Best,
Alex

Like

Thanks Alex, for your fast reply!
1- I didnt realize the official app also handles the feed. Do you mean this one, right? https://apps.shopify.com/google?locale=es
2- A- Yes, i generally import it from Analytics, so in my case is just removing those lines related with conversion?
2- B- If importing conversion from Analytics, i wont neither use the conversion label. I just need to remove the conversion label lines too?
3- As you are an experienced advertiser, how do you submit the products to Facebook catalog? As far as i saw, the Facebook official app doesnt add the products to the catalog. Do you use a specific app for that? Or is just an issue in having locally?
Thanks!

Like

Hi Alex, I have installed Google Ads conversion tag based on this guideline before: https://help.shopify.com/en/manual/promoting-marketing/analyze-marketing/tracking-adwords-conversions. Now I would like to add the remarketing tag only. If I understand correctly, if I copy all the code above it will cause duplicate conversion tracking. Do you mind sharing the steps to add remarketing tag only on top of already existing conversion tag? Thank you!

Like

Hi Hangga — Sorry for the late reply.

I assume you are referring to the Checkout script.
To only keep the remarketing portion and discard the conversion portion, simply remove lines 33 to 39 (thoses with the // Conversions comment above them).

Hope this helps.
Good luck!
Alex

Like

Hello Alex
I have some problem with ecomm_totalvalue . My price are in EUR so it’s not correct to use remove: ‘,’
Instead of this how can I get a result as for example 40,89 instead of 4089
Thank you

Like

Hi Azzurra — Sorry for the late reply.

Until I build something more dynamic into my script, the quick solution is to remove all occurrences of “| remove: ‘,'” from the script. (There should be a total of 4 across both scripts). This should leave the comma in place.

Like

Hey,
thanks for the awesome tutorial.
We have uploaded the feed by SKU as id. Can you tell me how to adjust the prodid code to match with the merchant center id?

Like

Hi
Fantastic article. We implemented but we found that shopify is sending this

event page_view
dynx_itemid shopify_4204527616082_30341636587602
dynx_pagetype offerdetail

with the wrong ID (shopify_4204527616082_30341636587602) instead of the correct ID shopify_US_4204527616082_30341636587602

How can we fix that?
Thanks

Like

Hi Johnny,

This appears to be an issue with the shopify_store_country variable (lines 4-9). It isn’t being set for some reason. It needs to be set to the 2 letter country code representing your currency (US for USD, CA for CDN, etc…)

Hope this helps?

Alex

Like

Hi Alex
Thank you for your comments. We found that with your code, some events are sent with the right id while others are not. Example below is from the same product page on Shopify

event page_view
ecomm_pagetype product
ecomm_prodid shopify_US_4204538003538_30341667979346
ecomm_totalvalue 193.00

event page_view
dynx_itemid shopify_4204538003538_30341667979346
dynx_pagetype offerdetail

How can we fix that in your code?
Thanks

Like

Hello Alex, Thanks for the code. I have implemented the exact code to my Shopify store but I am having 2 issues.
First one – Ad campaign showing the wrong conversions data. For the example – I had 6 conversions today but in total conversion it showing 300. whereas the total click for the day is 200.
And also there are no issues with conviction Value except it is a bit slow to register those values.
Second one – I am getting an error in audience source – Issue: 89% of ecomm_prodid values received don’t match your feed.
In the merchant centre, my product id is like shopify_US_3024029580000_35612608414180.
I have three countries feed in my merchant centre. Do you think this is the reason I am getting this error?

It would be great if you could help me in this regards.
Thanks you

Like

Hi Vijay,

1) In the Google Ads interface, go to TOOLS > MEASUREMENT > CONVERSIONS. This should bring up all your conversion events. There should be a column called “Include in Conversions”. Make sure that ONLY your purchase or revenue generating event is set to “YES”, and that all others are set to “NO”. What is probably happening is that stuff like pageviews or add-to-carts or time-on-site is being recorded as a conversion.

2) This is probably one of the following:
a) You didn’t upload your entire product catalog to google merchant, and so there are products on your website that are not in the google merchant feed.
b) The merchant center product id doesn’t match the remarketing product id (although this is probably NOT the issue for you). But double check to see if the product id generated buy the remarketing code matches that which you have in merchant center (take a look at the country code in product id on your remarketing and make sure it matches some of your products in the feed)
c) You maybe have the remarketing code installed on high traffic pages where there are no products shown (FAQ pages for example). If it’s a page type that I didn’t account for, sometimes the remarketing code will output a product id of “0” which won’t match your merchant center.

Hope this helps…

Alex

Like

Hi Alex, thanks for this detailed and thorough instructions. I have followed your steps and they are all clear to me (except the product variant part in the comments of a Dutch user). However, Google Tag Assistent now shows 3 Tags on normal pages but only analytics tag on checkout. With my code which I had there before, I had 4 tags, including gtag for conversion and remarketing (however they didnt really work well because pruduct.id for remarketing was missing and my smart shopping campaign never started).

Can you help me out? I dont know what to do! I checked the Checkout code severals times now…

Like

Hi Manuel,

When you say “checkout”, do you mean the order complete / thank you page? Or do you mean the order checkout process after the shopping cart?

The issue *might* be the first line in my checkout script: “if first_time_accessed”

This causes the code to only run once per user — so that multiple conversions don’t get recorded — it’s possible you are not seeing the tags because you have are refreshing the same page? Try putting through a new order and checking the tags the very first time the thank you page appears…

Alex

Liked by 1 person

I’m trying to set it up for a custom app in a store which redirects the user to another page immediately after the Thank you page is loaded. And in this process, this code isn’t triggered at times. I tried to use “event_callback” property to wait until both the codes are triggered completely and then redirect the user, but it fails when an adblocker is used. How do I proceed with this? Will the beacon method work with your code?

Like

Hi HImanshu,

Unfortunately the redirect scenario is not something that I have tested. I don’t think there’s an easy workaround to that other than having a “Your are about to be redirected to another page… Click here to continue” and have the redirect wait 3 seconds or so.

In terms of the ad blockers, that’s unfortunately a reality of the internet in this day and age. More and more traffic is likely to get missed due to Ad Blockers…

Best,
Alex

Like

Hi Alex!
I don’t really understand HTML code and I have 4 questions:
1. I need to add the Google converting id only one time at the beginning of the code or every time I see “google_conversion_id”?
2. If we use EUR currency, we need to change something in the code?
3. how can I know of the code work?
4. where can I check how many time every parameter fire? like on facebook that you can see in the pixel how many time people went to add to cart page or view_content page or any other parameter?

Thanks a lot!
Asaf

Like

Hi Ethnasia — I’ve added a set at the bottom of the article to explain how to handle additional currencies. It’s just a matter of replacing “assign shopify_store_country = ‘US'” with your store’s two letter country code. (Currency code isn’t actually being used in the code, it is just a way to determine default store country).

Like

Hi Asaf,

1. You only need to add it once. Replace “123456789” with your actual conversion Id.
2. I’ve added a section explaining how to handle EUR. Simply change the country code from “US” to your own country’s two letter code.
3&4. Install the Google Tag Assistant applet into Google Chrome — it should tell you if you have errors or not. Otherwise the only way is to wait to see if your lists in Google Ads begin growing.

Like

Hi, i get the “Some products are not valid” in Google remarketing tag on the tag assistant. im not sure why, but info: i have 10 products in my google feed for ads. i have over 200 products total. i am checking the tag assistant on one of the products i have in the feed. not sure what the issue is.

another thing: i have dozens of variants for these products but i only have the main variant in my feed and advertised.

Like

Hi there, thanks for this! I keep getting “Some products are not valid”, but Google Tag manager correctly shows the ecomm_prodid and other parameters?

ecomm_prodid shopify_NL_3069029580900_25312618414180
ecomm_pagetype product
ecomm_totalvalue 7900

Like

Hi Sebastiaan,

Check to make sure that shopify_NL_3069029580900_25312618414180 is indeed in your Merchant center feed and uploaded to Merchant center? Did you upload your entire product feed to Merchant center, or are there some products that you chose not to upload?

Best,
Alex

Like

Hi Sebastiaan,

You either need to:
1) Change the way your products are being uploaded to Merchant center to use the Shopify style product id (shopify_NL_productid_variantid), or
2) Change my remarketing code to only use the VariantId as the google product id (I think it would be something like: {{ product.selected_or_first_available_variant.id }}

Alex

Like

Thanks for the great write up! I currently have Google Ads Tag implemented via Google Tag Manager and working fine, but I haven’t been able to get Google Analytics Remarketing Tag to work with Shopify for months. I constantly get a “91% of your Google Analytics tag activity is missing product ID” message. Would you happen to know how we can set that up correctly with Shopify?

Like

Hi Brett — Sorry for the 1 year delay in replying.

The issue is likely product_id matching between Shopify and Google Analytics. You would need to look at the format of the product_id being output by your GTM tag vs what GA is expecting.

Alex

Like

It took a couple of days and now ecomm_prodid or other parameters appear!

I have one more question)

What is this function for?
function getUserId() {
if(typeof __st !== ‘undefined’ && __st[“cid”]) {
return __st[“cid”];
} else {
return;
}
}

Thanks!

Liked by 1 person

Sorry for the late reply.

This code attempts to grab the Shopify UserId of the current user on the site, and then passes it along to Google Ads to allow for more accurate user tracking across different devices, etc… Not all Google Ads accounts have access to this feature.

Like

Leave a comment