Setting up Dynamic Remarketing using Google Tag Manager

Setting up Dynamic Remarketing using Google Tag Manager

Remarketing is a powerful feature which allows you to sell to people who have already visited your site and are interested in your products.

Using adwords dynamic remarketing you can take this a step further and advertise visitors the actual product they were interested in. Allowing you to customize your message based on the product they viewed or added to cart or even purchased (think complimentary products to upsell!!).

To do this sort of remarketing we need to collect a bit more structured data. This requires placing special tags on each of your pages. It requires you to link Google Merchant Centre Account with Adwords. Details. The below post details how technical implementation can be done using google tag manager.

Step 1: Add Tags to all your site pages

For Dynamic Tagging we need tag each page on the site with tags The tag will be built by building a js object It needs to be added as early on the page as possible preferably right after opening body.

 var google_tag_params = {
  'ecomm_pagetype': 'purchase',       //set the pagetype value
  'ecomm_pcat': ['electronics', 'books'],   // product category
  'ecomm_prodid': ['123A', 'H456'],      // sku
  'ecomm_pname': ['Nexus','Router'],    // product name 
  'ecomm_pvalue': [99, 19.99],      // product value
  'ecomm_totalvalue': '118.99'      // total value

The ecomm_pagetype key is required and needs to be set for each page.

The value for pagetype can be home, searchresults, category, product, cart, purchase, other

All other fields can be set as needed and if not available can be left as blank quotes ''


On the homepage

just set pagetype and leave other keys blank.

'ecomm_pagetype': 'home'


On Category page set

'ecomm_pagetype': 'category',
'ecomm_pcat': ['electronics'] // category name, separate by commas if multiple cats


On Product page set

'ecomm_pagetype': 'product', //set the value
'ecomm_pcat': ['electronics'], // product category
'ecomm_prodid': ['123A'], // sku
'ecomm_pname': ['Nexus'], // product name


Cart Page

Pass values for all items in the cart

'ecomm_pagetype': 'cart',
'ecomm_prodid': ['123A', 'H456'], // id (sku)
'ecomm_pname': ['Nexus','Book'], // product name
'ecomm_pcat': ['electronics', 'books'], // category
'ecomm_pvalue': [599, 19.99], // individual product values
'ecomm_totalvalue': '118.99' // total cart value



On order confirmation page add

'ecomm_pagetype': 'purchase', //set the value
'ecomm_pcat': ['electronics', 'books'], // product category
'ecomm_prodid': ['123A', 'H456'], // sku
'ecomm_pname': ['Nexus','Router'], // product name
'ecomm_pvalue': [99, 19.99], // product value
'ecomm_totalvalue': '118.99' // total value


All other pages set

'ecomm_pagetype': 'other'


Below the tags we would add dataLayer which sends the data to Google Tag Manager. End result would look something like this for a product page

<!-- Dynamic remarketing tag  should always be above dataLayer.push --> 
<script>// <![CDATA[
var google_tag_params = {   
'ecomm_pagetype': 'product',  //set the value   
'ecomm_pcat': ['electronics'],  // product category   
'ecomm_prodid': ['123A'],   // sku    
'ecomm_pname': ['Nexus']    // product name  
// ]]></script>

Standard code for container on everypage

dataLayer = [];
YOUR GTM container code

Send data to gtm via dataLayer.push

dataLayer.push ({   
 'google_tag_params': window.google_tag_params 

Step 2: Google Tag Manager setup

Next step is to setup remarketing tag in gtm and specify rules and macros to trigger them.


Create a new tag in your gtm container. In the next step select Adwords Remarketing as the tag type.

Go to your adwords account and create a new remarketing tag.  Here is how to create a remarketing tag.

From the tag get your Conversion ID and Conversion Label.

conversion id & conversion label

conversion id & conversion label


Next we need to tell the tag where to get the product information we have specified on the page. To do this we'll create a macro. In custom parameter section select Use Data Layer Variable.

In Data Layer Variable select new macro. On the popup select Macro Type: Data Layer Variable. Name the macro google_tag_params and use Data Layer Variable Name google_tag_params

Datalayer variable name

Datalayer variable name

End result will look something like this:

adwords dynamic remarketing tag

adwords dynamic remarketing tag


Now we need a rule to tell gtm when to trigger the tag. Click Add Rule to Fire Tag. On popup select Create new rule.

Since we have added the tags to every page Specify a rule that fires the tag on all pages of your domain. Create a rule with   {{event}} contains remarketingTriggered And save the rule.


Now just save the tag , create a new version of container and publish it and you'll be done.  Get cracking with creating new tailored ads for your customers and see your sales go up :).

This should help you get started. Let us know how it goes  in the comments.

Hussain Mehmood

Hey I am Hussain Principal Analytics Consultant @ MarketLytics focusing on measurement strategy and analytics implementation. I started marketlytics in 2010 to turn my passion for understanding user behaviour into my day job. I use & extend google analytics, tag manager and kissmetrics everyday to deliver performance measurement & data driven insights.