Dynamic Remarketing Code Setup – Google Tag Manager & Analytics

Dynamic Remarketing Code Setup Methods

This is 2nd part for dynamic remarketing setup. For prior part,


Kindly Check Adwords Dynamic Remarketing: Complete Setup Guide For All Websites,


where I have explained

  • How To Link Adwords & Analytics accounts?
  • How to Preview Dynamic Remarketing Ads?
  • Some Myths about Dynamic Remarketing

There are various methods to implement dynamic remarketing. Here is the hierarchy of most of the methods used.

Dynamic Remarketing Hierarchy - Digishuffle


We will be looking at Google Tag Manager —> Analytics method to implement dynamic remarketing.


Dynamic Remarketing using Google Tag Manager & Analytics

Step 1:

  • There are 3 custom parameters, you can implement
    • Product ID [Required]
    • Page Type [Optional]
    • Total Value [Optional]
  • These parameters are used as a condition to create remarketing list in Adwords.
  • You are free to pass other values in optional attributes as per your needs.
  • In Analytics, go to Property > Custom Definition > Custom Dimensions.
  • Create 3 Hit level dimensions, (can name anything)
    • ecomm_prodid
    • ecomm_pagetype
    • ecomm_totalvalue

Dynamic Remarketing - Custom Dimension - Digishuffle

Step 2:

  • Go To Property > Audience Definition > Dynamic Attributes.
  • Create dynamic attribute linking.
  • Verify the business type, adwords linked account.
  • Assign the custom dimension created in Step#1 to respective attributes.
  • You can also assign only Product ID attribute & create remarketing list from Analytics.

Dynamic Attribute Linking - Digishuffle

Step 3:

DataLayer Placement

  • In Google Tag Manager, we will start with dataLayer placement method.
  • Use this method if you have access to the backend.
  • You can place the code on different pages such as
    • product_listing_pages
    • search_results_pages
    • product_pages
    • coupon_code_pages
    • & so on
  • Here is the code you can place on search results page. You should dynamically replace
    • ecomm_totalvalue = total value of products on the pages
    • ecomm_prodid = array of product ids on the page.


  • On Product Pages

  • and so on


One HTML Custom Code

  • Create Custom HTML Tag in GTM & paste below code.
  • Trigger on All Pages.
  • Fire Google Analytics event tag with different custom events.
  • You can place a single code on all pages but add the page conditions.


Custom JS 

  • You can also trigger Custom JS on events like Add To Cart, Remove from Cart, Coupon Code Clicked, etc


Step  4:

  • Create custom dataLayer variables in GTM. (ecomm_prodid, ecomm_pagetype, ecomm_totalvalue)
  • Pass it with the analytics event tag or pageview tag in custom dimensions.
  • Verify the Index is proper with the metrics defined in Step #2.

GTM - Dynamic Remarketing Variables - Digishuffle


Step 5:

  • Keep an eye on Adwords > Shared Library > Audiences. Check if the search & display audiences are getting filled.
  • You’ll see an error for 2-3 days until the data gets populated via analytics. So ignore it.
  • Also, an error might arise due to code not on all pages.
  • Check here if the error persists.

Dynamic Remarketing Error - Digishuffle



  • You can replicate the above process for any business type.
  • Product IDs should match the Dynamic Ads Feed Product Ids.
  • Dynamic remarketing will also work if you only pass primary_Ids. (for any business type)
  • You can also use other methods to send custom attributes to Google Analytics.


More Articles:

Adwords Advanced Automated Reports – Daily/Weekly/Monthly

Adwords CPA Scanner – Analyze & Reduce High CPAs in Seconds.

10 Incredible Ways to Analyze High Bounce Rate – Advanced Guide

Time On Visible and Hidden Pages – Google Analytics


Ritwik is Web Analyst & Growth Hacking Consultant. He loves to write technical & easy to understand blogs for Marketers & Entrepreneurs. Focused on Google Analytics, Tag Management, GScripts & more. Google Certified Professional. A Firm Believer in Teaching -> Learning -> Growing. :)