How-To

How to Setup Google Dynamic Remarketing on Shopify via GTM

Implement your dynamic product remarketing script to automate retargeting campaigns and win back non-converters.

How to Setup Google Dynamic Remarketing on Shopify via GTM

According to a recent study by Monetate, it takes 3.2 sessions (on average) before a new user completes a purchase.

This means you need marketing strategies to bring non-converters back!

Dynamic product remarketing is a key tactic to help with this. And what better way to entice users to come back than show them products they previously viewed on your site?

Prerequisites from Google in order to take advantage of dynamic remarketing for retail:

  • Submit your product feed data through Google Merchant Center
  • Link your AdWords and Merchant Center account together
  • Enable Remarketing and Advertising Reporting features in Google Analytics
  • Create a Dynamic Remarketing campaign in AdWords

This ensures your latest product feed is used within your campaigns.

There are three ways to setup Google AdWords dynamic remarketing for Shopify:

  1. AdWords gtag snippets via GTM
  2. Our new Shopify app automates all of the GTM + AdWords setup!
  3. Google Analytics custom dimension sync

You can also hard code the gtag events in your theme, but hopefully you’ve succumb to the power of GTM and manage all of your tags there 🙂 .

If you don’t have Google Tag Manager enabled yet for your store, check out my guide on how to implement GTM on Shopify.

New GTM + DataLayer App

Download our GTM Suite app for Shopify now.

Option # 1: AdWords gtag Snippet via GTM

Step 1: Create custom variables in Google Tag Manager

We are going to leverage the existing data layer that all Shopify stores have out of the box.

Yes, Shopify has a data layer. It’s not GTM’s data layer, but it contains some of data you need. See my overview on data layer variables within Shopify here.

Go to Google Tag Manager > Select your account > Select your container > Variables > User-Defined Variables > New

Variable # 1: ecomm_pagetype_shopify

Copy this variable name into the Global Variable Name shown in the screenshot:

window.ShopifyAnalytics.meta.page.pageType

ecomm_pagetype for shopify and dynamic remarketing

Important – these need to exactly match!

Variable # 2: ecomm_pagetype

Variables > User-Defined Variables > New

As you know, category pages in Shopify are called “collections” and thus the pagetype in the data layer JS is “collections”. So we’re going to use GTM’s lookup table variable to change this to the Google required value of category.

We’re using the variable created above and telling GTM that when “collection” is returned as the ecomm_pagetype_shopify variable then swap it out to be “category” instead when publishing into our remarketing tag.

shopify dynamic remarketing ecomm_pagetype

DON’T FORGET TO SET THE DEFAULT VALUE SETTING!

Variable # 3: ecomm_prodid

Variables > User-Defined Variables > New

Copy this variable name into the Global Variable Name shown in the screenshot:

window.ShopifyAnalytics.meta.product.variants.0.sku

Important tip: This example above shows me pulling the SKU on the page which matches up to the item id that I have configured in my Merchant Center product feed. These need to be the same value otherwise you’ll get an error in AdWords that this doesn’t match. Here is where to view your product IDs in the merchant center to see if your product SKUs equal your Item IDs.

merchant center item IDs

If these don’t match then you may need to adjust the mapping of your feed to set your SKU as the ID or look at other ways to grab the variable on your product pages to match the IDs (I can’t cover this due to so many potential possibilities!).

Variable # 4: ecomm_totalvalue

Variables > User-Defined Variables > New

Copy this variable name into the Global Variable Name shown in the screenshot:

window.ShopifyAnalytics.meta.product.variants.0.price

Variable # 5: ecomm_category

In this example, we’re going to use a DOM Element variable to grab the category name that a user visits:

ecomm_category variable

Step 2: Create dynamic remarketing tag in GTM for product and cart pages

In this step, you need to copy your remarketing tag that you get from your AdWords account, including the event snippet that contains the retail variables.

First, create two new triggers that fire on product and cart pages. Here’s how these should look:

Product pageview trigger:

product pageview trigger

Cart pageview trigger:

cart trigger

Once you have those created, go to Google Tag Manager > Tags > New Tag > Custom HTML Tag

(This example shows the setup with the new gtag.js that Google rolled out in October 2017.)

Go ahead and copy your full snippet into the field as shown below.

product and cart dynamic remarketing tag

If you followed my previous steps when creating the custom variables then these are your variables that you’ll need to update:

{{ecomm_prodid}}
{{ecomm_pagetype}}
{{ecomm_totalvalue}}

It’s important that this snippet goes below your global site tag as shown in the screenshot below:

product and cart dynamic remarketing tag events

And then as you can see in the screenshot you’ll assign your product and cart pageview triggers.

Step 3: Create dynamic remarketing tag in GTM for category pages

This follows the same process as the last step so hopefully it’s quick and painless for you!

Create your category pageview trigger:

category page trigger

Create your custom tag in GTM > Tags > New Tag > Custom HTML Tag:

category dynamic remarketing tag

You’ll notice that in the event snippet we only have:

  • {{ecomm_pagetype}}
  • {{ecomm_category}}

As Google states in their instructions, the ecomm_prodid and ecomm_totalvalue variables are only needed on product and cart pages.

Then assign your category pageview trigger and you’re all set!

Step 4: Create dynamic remarketing tag in GTM for remaining pages

Our last step is to create a third tag that we’re going to fire on all other pages except product, cart, and category pages.

Here’s what this new tag looks like:

dynamic remarketing misc pages

When setting your triggers, you’ll want to select the All Pages firing trigger and then set the three exceptions for cart, category, and product pageviews as shown in the screenshot above.

Step 5: Review and deploy your tag!

Once you’ve completed the steps above, it’s time to verify the tag and variables work as expected!

Enable Preview Mode within Google Tag Manager and navigate to home, category, product, cart, and other pages to validate the proper tags are firing.

Here’s an example of our category page. Click into the tag to review your HTML and you should see your variables populated with your product page data. See the {{ecomm_pagetype}} equal category?

Lookup table variables to the rescue in GTM 🙂

validate remarketing tag

Option # 2: Google Tag Manager Suite App for Shopify

For the same reasons we built our Elevar app to automate repetitive daily analysis, we decided to build an app for Shopify to help make the process of getting GTM installed…

…and Google AdWords conversion tracking…

…and Dynamic Remarketing for AdWords…

…and the dataLayer for key eCommerce marketing variables…

…and checkout funnels for Enhanced eCommerce…

…and access to our pre-built GTM containers that can be imported in one-click…

up and running on any store!

==> INSTALL APP NOW <==

Option # 3: Google Analytics Sync

This last option allows you to create custom dimensions in Google Analytics that you can then sync in your AdWords audience setup.

Step 1: Create custom dimensions in Google Analytics

In Google Analytics > Property > Custom Definitions > Custom Dimensions

Create these four custom dimensions:

  1. ecomm_prodid
  2. ecomm_pagetype
  3. ecomm_totalvalue
  4. ecomm_category

Which you can do by clicking “New Custom Dimension” and configuring as “Hit” scoped dimensions like this:

google analytics remarketing custom dimensions

And once you’ve completed all four then you’ll end up with something like this with index 2-5:

dynamic marketing custom dimensions in GA

Step 2: Populate Custom Dimension Values in GTM

If you follow a similar process in step 1 to capture the ecomm values via GTM then you can assign them through a Google Analytics tag in GTM.

Keep in mind there are many ways to do this – this screenshot below shows a pageview tag with the custom dimensions set but you can also do via custom events, etc.

gtm custom dimensions

Step 3: Setup in AdWords

This is a few quick steps. Inside of Adwords > Tools > Audiences > Sources > Google Analytics you can configure retail custom parameter events by selecting the custom dimensions you setup in the previous step:

adwords google analytics retail source

Then select dimensions:

adwords google analytics retail attributes

That’s it! Happy retargeting.

Check out other popular Shopify articles below (and you can download our Shopify GTM app here)

Shopify Marketing Tips

Want more helpful eCommerce and Analytics tips? Sign up for our emails!

We respect your inbox.


Brad Redding

Brad, co-founder of Elevar, has lived in eCommerce for over 12 years. He's helped design, build, and optimize over 100 websites in his career. From new retail startups to well-known brands like Le Creuset, Signature Hardware, Rebecca Minkoff, Char-Broil and more, he specializes in data analytics and conversion optimization to help achieve business goals.

    1. Not necessarily – you just need to match the ecomm_prodid that you are pushing from your website to match your Google Merchant Center product ID.

  1. Hi There, thanks so much for this tutorial. This is a hefty question. I want to track “Add_to_Cart” events so I can re-market to users that have added products to cart in Adwords. If my Shopify site uses Ajaxcart any clue how to pull in the ecomm_prodid and ecomm_totalvalue into GTM?

    1. Hi Luis – that is a good question!

      That should be doable, you’ll just need to set custom event parameters on your addToCart conversion to something like this:

      gtag(‘event’, ‘addToCart’, {‘send_to’: ‘AW-xxxxxxx’,
      ‘ecomm_prodid’: ‘{{ecomm_prodid}}’,
      ‘ecomm_totalvalue’: ‘{{Product Price Divided by 100}}’,
      ‘ecomm_pagetype’: ‘{{ecomm_pagetype}}’

      And then set the trigger to fire on add to cart action.

      [I removed some of the script intentionally so beware copying/pasting]

      1. Thank you for your reply Brad, I follow your logic but from I can see when inspect the code on our product detail page I do not see anything in the shopify.analytics datalayer that identifies the correct ecomm_prodid that was added to cart via the ajaxcart.

        I see the variants on the product detail page in the datalayer. Based on your tutorial it looks like you passing window.ShopifyAnalytics.meta.product.variants.0.sku from the shopify.analytics datalayer.

        1. Hi Luis,

          Try these steps (assuming you have the ecomm_prodid variable setup from the tutorial above):

          1. Put GTM into preview mode
          2. Go to product page and click add to cart
          3. Click the gtm.click event in the debug console that fired on your add to cart
          4. View the variables data and specifically the ecomm_prodid

          You should see this with your ID so if you attach an event to this click you’ll have your ecomm_prodid sent with your add to cart!

  2. How would your add the correct formatting in GTM if your “Item ID” in Google Merchant is listed like so – shopify_US_9985833793_36962930177 ??

    Thanks for any help! Great article by the way.

  3. HI Brad
    Excellent Guide and got it setup. I am little confuse if use this do we still need to add the retargeting & conversion codes to our theme body and shopify checkout setting?
    I am asking this because I have it on my site added as per some users discussing on shopify forums.

    1. Hi Ken – thanks for the note! If you already have the remarketing code snippets within your theme then you do not need to add this via GTM as well. Let me know if that helps!

  4. I’m very confused about creating Remarketing Dynamic Ads on Adwords, I followed guides from Google but still struggling with Dynamic Feed. I have Main Feed in Google Merchant Center already, running for Shopping Ads, but in the Product List, I’m seeing some Red symbol that said “Disapproved or Invalid: Dynamic Remarketing”, its not applied to all products, but some.
    Could you please explain more how to create Remarketing Dynamic Ads with Feeds? Would really appreciate for the answer. Thank you.

  5. Hi Brad,

    fantastic guide, thank you so much! It seems to have worked with me but despite following it religiously I’m still running into trouble as website visitors aren’t being added to my audience lists. I have done some digging and there seems to be the following problems:

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

    – We didn’t find the custom parameter “ecomm_prodid”
    Your tag doesn’t include the custom parameter “ecomm_prodid”.
    Check that your tag is implemented correctly. The “ecomm_prodid” value is necessary to enable dynamic remarketing, and should be added to your tag. Learn about the dynamic remarketing tag. Check that you’re using the correct custom parameters using the Tag Assistant Chrome extension.

    –> I suspect the reason for that is that I just recently changed the SKU of all of my products in my Shopify store, which is essentially the Item ID in my Google Merchant Centre. This hasn’t synched up yet in Merchant Centre, from where the data is retrieved.

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

    –> I don’t know what the problem behind this error is.

    2. We haven’t detected custom parameters for Retail (Google Analytics)
    The tag is active but we couldn’t find any custom parameters.
    Check that the remarketing tag is implemented correctly. Custom parameters are necessary to enable dynamic remarketing. Learn about the dynamic remarketing tag.

    – Your tag doesn’t include the custom parameter “ecomm_prodid”.
    Check that your tag is implemented correctly. The “ecomm_prodid” value is necessary to enable dynamic remarketing, and should be added to your tag. Learn about the dynamic remarketing tag. Check that you’re using the correct custom parameters using the Tag Assistant Chrome extension.

    –> I think it’s the same issue as above.

    Otherwise the following is running correctly:

    – Google Analytics tag is active
    – Adwords tag is active
    – Custom parameters are active (“ecomm_pagetype”, “ecomm_category”, “ecomm_totalvalue”, “ecomm_proid”, “event”)

    1. Thanks Jeremy!

      Check your ecomm_prodid custom dimension in GA and tags in GTM. It looks like you are missing a “d”. So instead of passing ecomm_prodid, you are passing ecomm_proid.

      And you are correct that this ID from your Tag will need to match the ID in your Merchant Center shopping feed as well.

      Hope that helps!

  6. Brad, you are a legend man. That seems to have been the problem. I made a mistake in both GA and GTM. There was a ‘d’ missing in the custom dimension in GA and another one in the Product & Cart Tag! Exactly as you said.

    I think the Merchant Centre Feed should up to date within the next 2h. Fingers crossed it will work then.

    Thank you so much for your help and kindness, I really appreciate it. You’ve won a subscriber!

  7. I am so sorry to be a pain but it still doesn’t seem to work! 🙁 I corrected the mistakes in GA and GTM, and the Merchant Centre Feed is now up to date. So there shouldn’t be any excuses anymore as to why it doesn’t work, but I just can’t seem to get it up and running. These are the the issues that Adwords is notifying me of:

    1. There are problems with some of your custom arameters 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. Learn more
    View tag implementation instructions

    – Custom parameter “ecomm_prodid” and Merchant Center feed values don’t match
    Values for “ecomm_prodid” should match item identifiers in your Merchant Center feed.
    The value of the “ecomm_prodid” parameter being passed to the remarketing tag is incorrect. Your tag’s “ecomm_prodid” value needs to match either the “id”, “item_group_id” or “display_ads_id” of the product in the connected Google Merchant Center account. Learn more
    View tag implementation instructions

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

    2. We haven’t detected custom parameters for Retail (Google Analytics)
    The tag is active but we couldn’t find any custom parameters.
    Check that the remarketing tag is implemented correctly. Custom parameters are necessary to enable dynamic remarketing. Learn about the dynamic remarketing tag.
    View tag implementation instructions

    – We didn’t find the custom parameter “ecomm_prodid”
    Your tag doesn’t include the custom parameter “ecomm_prodid”.
    Check that your tag is implemented correctly. The “ecomm_prodid” value is necessary to enable dynamic remarketing, and should be added to your tag. 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

    I’m at my wits’ end. Should I just start from scratch?

  8. Hi Jeremy! No problem, I’m happy to help!

    I would wait ~ 24 hours and check again. I usually see a bit of delay in Merchant Center before audience reporting updates accurately.

    I’ll send you an email to check in tomorrow!

  9. Brad, great guide. Thanks for compiling.

    I’ve followed the steps below and validated the activity using Tag Assistant. Everything seems to be working but when I review “Audience Sources” in Adwords, I see the following error message:
    “Your AdWords tag hasn’t been active in the last 24 hours, Your tag hasn’t been adding website visitors to your audience lists”
    That said, the Adwords tag is still recording hits and I’m getting hits for the parameters that I set up.

    Any insight into what could be going on here?

    Also, what audience should I be targeting to when I create a dynamic remarketing campaign? The adwords optimized list?

    1. Hi Scott! Thanks for the note.

      If you just implemented the same day then sometimes it takes 24 hours for the AdWords audience source to catch up.

      Regarding the audience question – this can really be anything you want (you can use more than one audience for a dynamic remarketing campaign).

      I hope that helps!

  10. Hi!
    Great tutorial! I’ve followed it in detail but I’m seeing two problems:
    – I’m not getting most of the data on the cart and checkout pages. In particular, the three values come out as “undefined”
    – Also, I’m getting ecomm_totalvalue in hundreds (2200 instead of 22.00). Now I can easily solve this with a custom javascript variable to divide by 100, but I’m wondering whether that’s expected behaviour.
    Do you have any feedback?
    Note that I haven’t published the changes, I’m still in preview mode on GTM.
    Thanks!

    1. Thanks for the note, Marco!

      Cart and checkout variables are difficult to grab natively from Shopify through the DOM since the stores vary so much. We actually have a GTM app w/dataLayer variables in a private app (we are testing before publishing in app store). This will help solve for the consistency of grabbing ecomm total variables across stores.

      Regarding the values coming out in hundreds, you are correct. I use a custom JS tag set to the following:

      function() {
      return parseFloat({{ecomm_totalvalue - checkout}})/(100);
      }

      *Note your variable name may be different than this example*

      I’ll update the article to include this import differentiator!

  11. Hi Brad,

    This has been VERY helpful; thank you so much!

    I have been struggling however to implement the last comment to get the: ecomm_totalvalue in hundreds (2200 instead of 22.00). Are you going to update the instructions above?

    Also, I’m having an issue with the tracking on the /cart page: the tag bucket works well on all product pages, but for the /cart page it brings back: ecomm_prodid, ecomm_pagetype, ecomm_totalvalue all as ‘undefined’?

    This tag works fine on the product pages just not the cart page?

    Lastly, how would you set up on the /checkout page for ecomm_pagetype: ‘purchase’?

    I have another question but separate it below as sure affecting others.

    Thanks again!

  12. Hi Brad,

    Sure this is a general issue and hopefully a workaround for Shopify.

    The setup above returns the product page tracking with the ecomm_prodid = SKU

    The Shopify product feed to Merchant Center, by default, maps the product ID = shopify……… (a Shopify generated ID and maps the mpn = SKU.

    To resolve this would you either:
    1) update your ecomm_prodid variable to:
    ‘ecomm_prodid’:'{{‘shopify_GB_{{ item.product_id }}_{{ item.variant_id }}’,
    2) OR create a new Google merchant centre feed using the SKU as the ID, not the Shopify created ID?

    (PS. GB above would be US for USA I assume)

    Many thanks!

    1. Hi Sean – thanks for the note and my apologies on the delay in responding. I would not modify your merchant center feed if you have that set already (we can change around your onsite data quickly). Is your merchant center ID the “shopify_…” or do you have it set as product SKU?

  13. thanks for the answer; the app sounds amazing!
    In your example, how did you set up the “checkout” variable? I’m not sure I understand the logic of the subtraction since it’s not referenced in this article.

  14. Hey Brad, really love this article. I’m facing a similar problem as Sean where the ID on my GTM is in the format shopify_{variant_id}_{product_id}. What should I edit on the ecomm_prodid in order to reflect this? Should I change the “window.ShopifyAnalytics.meta.product.variants.0.sku” to something else?

    1. Thanks Ashton! There are a few comments asking about this so I will put something together and share with you a snippet you can add to your GTM and/or theme!

  15. Hello Brad, thanks a lot for writing this article! I face a similar problem to Sean who talked about the GMC being tagged as ‘shopify_{{ item.product_id }}_{{ item.variant_id }}’. How do I go about changing the ecomm_prodin on GTM in order to reflect this?

    1. Thank you! There are a few comments asking about this so I will put something together and share with you a snippet you can add to your GTM and/or theme!

  16. Hi Brad,
    awesome writeup and it helped us a lot! But we are in the same boat as Ashton and Sean on the prodid. Our feed is uploaded as ‘shopify_US_{{ item.product_id }}_{{ item.variant_id }}’ and I was wondering how I can pass this format of prodid to Google Ads. If you got to create the snippet you mentioned could you share? Really would appreciate.

  17. Thanks so much for this!!!!!! I finally got everything working! except for the ecomm_prodid issue everyone is having, lol. i have found some code that seems to set the correct value if you run it from theme.liquid, but when i try and make a constant value variable in GTM and place it in my tag GTM shows an error when i preview, unknown variable. here is the code im trying to work with shopify_US_{{product.id}}_{{product.variants.first.id}} (like everyone else) thanks so much again this whole site is awesome and very helpful!

  18. Hi!

    Thanks so much for this super helpful guide! I have a question for you if you have time to check it out. I do not have product SKUs on my shopify for our products. I use an app called Google shopping feed that generated my product ID for the merchant center. Will your tutorial still work?

    I am at the part where you wrote:
    “Important tip: This example above shows me pulling the SKU on the page which matches up to the item id that I have configured in my Merchant Center product feed. These need to be the same value otherwise you’ll get an error in AdWords that this doesn’t match. Here is where to view your product IDs in the merchant center to see if your product SKUs equal your Item IDs.”

    And i m worried that bc I do not have SKUs set up it wont work… any ideas/recommendations?

    Thanks!

  19. Also ran into this same problem. My ecomm_totalvalue was 12999 instead of 129.99.

    Here is what I did:
    1- use exact approach described in article
    2- rename {{ecomm_totalvalue}} -> {{ecomm_totalvalue_datalayer}}
    3- add new variable called {{ecomm_totalvalue}} and use custom javascript script that Brad shared.
    4- Update your tag to include to the correct variable {{ecomm_totalvalue}}

  20. If your feed uses the shopify_ format you can use this Custom Javascript variable for ecomm_prodid:

    function () {
    return ‘shopify_AU_’+window.ShopifyAnalytics.meta.product.id+’_’+window.ShopifyAnalytics.meta.selectedVariantId;
    }

    Replace AU with your own country code.

    1. Hi Kyle – unfortunately we’re limited to what we can grab from the DOM on the native cart page (i.e. cart object isn’t available). Any variables (dataLayer or JS) would have to be initiated from the cart liquid file.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Articles

Talk with Us

Please complete the form to request a demo, discuss our solutions, or to just say hi!



Some of our clients