AdWords dynamic remarketing

Remarketing allows you to show ads to people who have previously visited your website or used your mobile app. Dynamic remarketing takes this one step further by showing your visitors an ad with the specific product they had previously viewed on your site.

In this article:

This guide will show you how to implement dynamic remarketing using AdWords. We highly recommend that you review the dynamic remarketing guide on the AdWords help center before implementing dynamic remarketing via Tag Manager.


To tag your site for remarketing, you will need to:

  • Place the AdWords remarketing tag on every page of your site
  • Pass dynamic values to the remarketing tag on key steps of your site (e.g. the product ID of an item a user added to their cart, the origin and destination of a flight a user searched for, the deal ID of an offer a user had browsed, etc…)

These steps can all be accomplished with Tag Manager, saving you the trouble of having to hardcode tags and custom parameter values on your site.

Dynamic remarketing can be implemented for any type of online organization. The list of dynamic values that should be captured will depend on your website’s business objectives. There are custom parameters defined for many different business categories: education, jobs, real estate, travel, and more. See the list of custom parameters on the AdWords Help Center, and choose the one that is most appropriate for your organization.

In certain cases you might also want to pass additional parameters (e.g. loggedinuser=true, frequentbuyer=false), but the approach would be exactly the same as the one used to pass the standard remarketing parameters.

There are two main approaches you can use with Tag Manager to implement those tags. You can either:

Whichever method you choose, the implementation steps are generally the same:

  1. Populate custom parameter values dynamically
  2. Insert dynamic values in the remarketing tag
  3. Specify triggers to fire the remarketing tag
  4. Test and deploy the tags

Populate custom parameter values dynamically

The first step in your implementation is to capture data from your website in a way that can be processed by Tag Manager. To capture dynamic data from your page, you will need to implement a Tag Manager variable. Dynamic data may be pulled in several ways, such as from 1st party cookies, the data layer, or custom JavaScript.

Insert dynamic values in the remarketing tag

Once you've configured either one variable per type of data needed by the tag, you'll reference those variables to insert dynamic data into the built-in AdWords remarketing tag template which contains fields for configuring each instance of the tag.

For example, you might use a product ID or cart value using the one instance of the remarketing tag for each step of the funnel method. Or you may choose to use a single variable to hold all your dynamic data at once, using the single remarketing tag with custom JavaScript method.

Specify triggers to fire the remarketing tag

The last step of the tagging process is to tell Tag Manager when to fire each instance of the remarketing tag. This is done by specifying triggers. When setting up your tag, you can create triggers based on built-in variables that include pageviews, link click, button click, form submit, etc. You can also create triggers based on a custom event that register in Tag Manager via the Data Layer.

Test and deploy the tags

The last step in the implementation process is to test the tags on your site using Tag Manager's Preview mode. Once all the test cases have been completed and you are able to confirm that the tags are firing correctly, with the expected dynamic values, you can deploy the tags by publishing the container.

For detailed instructions on how to implement remarketing tags with Tag Manager, choose the remarketing tag implementation method that you intend to use:

Implementation using one tag per funnel step

Implementing one tag per funnel step

This section describes how to implement AdWords dynamic remarketing tags in Tag Manager by creating one instance of the remarketing tag for each step of your purchasing funnel.

How to set up the data layer code on your site

How to set up the data layer code on your site

This step is required if you choose the implementation method in which you will explicitly pass dynamic data to Tag Manager via the data layer. If you plan on grabbing the dynamic values via custom JavaScript variables through Tag Manager, skip this step.

The dataLayer object is a JavaScript array automatically created by the Tag Manager container code. It is used to pass custom data from your site to Tag Manager. First, create the dataLayer array (this needs to be done only once per page). To pass data to the data layer, use dataLayer.push({…});. This code should be placed before your Tag Manager container code itself in order for the data to be available when Tag Manager starts firing tags. Below is a sample code snippet to create the data layer and then pass the user's total cart value and the list of products contained in the cart:

dataLayer = [];
  'ecomm_totalvalue': 699.12,
  'ecomm_prodid' : ['prodid1', 'prodid2', 'prodid3']

The key names are completely arbitrary here and do not need to conform to any requirements (e.g. they don't need to match the custom parameter naming conventions for the AW remarketing tag) but you do need to make sure that you use the same key name every time you pass to Tag Manager the same type of information.

Use a JavaScript array when passing multiple values for a given key (for instance product IDs on a shopping cart page) and not a single comma-separated string.

Google Chrome users can use Tag Assistant to verify that the data layer was correctly implemented and view the data passed by the site to Tag Manager.

Alternatively, you can view the content of the data layer by opening your web browser's JavaScript console and entering "dataLayer" at the prompt:

Screenshot of the dataLayer object inspected with Google Chrome Console.

Some funnel steps might happen asynchronously (ie: without a full page reload). This is the case for instance when you add a product to the cart and the page doesn't change but simply an overlay or success message appears. It is important to be able to capture those "Ajax cart" events, because without it, your tracking would miss a lot of shopping cart abandoners and make your targeting less accurate.

The dataLayer.push() function allows you to set variables and fire tags after Tag Manager has loaded. For example, if a user adds an item to a shopping cart and the site doesn't go to a full cart page but instead displays a "dynamic" cart element via Ajax, you can use this function to update the data layer:

  'event': 'ajax_cart_add',
  'ecomm_totalvalue': 78.45,
  'ecomm_prodid' : 'prodid4'

Configure the variables

We need to configure a variable for each piece of dynamic data that we want to pass to the remarketing tag. In our example, we'll have a variable for ecomm_prodid and a variable for ecomm_totalvalue.

You can choose an arbitrary name for your variables. The name chosen here is just a user friendly, human-readable name that will be used within Tag Manager to reference the variable. It is a good idea to use explicit, unambiguous names that tell you exactly what the variable is supposed to contain (e.g. "ecomm_prodid" or "product ID").

Populating custom parameter values dynamically

There are several ways of capturing dynamic data with Tag Manager. For example, you can pass values explicitly to Tag Manager from your website using the data layer, or you can use Tag Manager to extract it from your site if possible using custom JavaScript variables.

Updating your site to pass values to Tag Manager via the data layer: This is the safest and cleanest way of passing dynamic values, but it requires code changes on your website. For this reason, this method can sometimes be impractical and can cause long delays in tagging implementation. This approach should be favored if you have easy access to technical resources and can make quick updates to your site.

Use custom JavaScript variables: You can alternatively use custom JavaScript code to populate the dynamic parameter values from Tag Manager using custom JavaScript variables and/or custom HTML tags. This approach, while less robust than the former, is sometimes the most practical way of deploying the remarketing tags since it doesn't require you to make any code change directly on your site. You can write custom JavaScript code that will pull the required dynamic values from the existing pages source code and pass it to the tag. In general, the data needed by the tag is already present somewhere in the document and can be retrieved via JavaScript code that is injected into the page through Tag Manager. The downside of method is that it relies on your site's source code as observed at the time of implementation, and future changes to Tag Manager may require you to revise your custom JavaScript code.

If you have implemented the data layer on your site...

Choose Data Layer Variable as the variable type, and enter the name of the data layer key from where Tag Manager can find the expected data for the variable that you are configuring.

If you have not implemented the data layer to pass dynamic data to Tag Manager...

In this case you'll need extract the dynamic value needed from the source code, such as by using a Tag Manager JavaScript Variable, or by writing custom JavaScript code.

Let's use a concrete example and suppose you want to configure a variable to dynamically retrieve the product ID that should be passed to the remarketing tag on a product page, and you are not passing this product ID via the data layer. The first thing you want to do is try to locate the value you need from the existing site source code. The expected value is the product ID set in Google Merchant Center for the sample product page you are looking at.

To extract the product ID from this JavaScript variable, create a JavaScript variable in Tag Manager and enter the name of the product ID variable.

Sometimes you will find the desired variable, but not in the exact format that you need. In those cases, you will need to create a custom JavaScript variable to extract the desired value from your site's source code. When a custom JavaScript variable is called, Tag Manager can be configured to execute a custom function that you provide, using the output of the function as the variable value.

If you are not using the data layer and rely on custom JavaScript variables to grab dynamic parameter values, keep in mind that you will need to use a different strategy to populate the same custom parameter depending on the step of the funnel you are considering.

For instance, the way you populate the product ID on a product page will be different than the way you populate the product ID on the cart page or on the purchase confirmation page, because the underlying source code or JavaScript variables that you can piggyback on will be different for each step. Therefore, you will not be able to create a single "product ID" variable that will work in every circumstance. Instead, you will need to create one variable to extract the product ID for each scenario where you need this information.

Configure triggers

The next step is to set up triggers in Tag Manager for each instance of the remarketing tag. Each trigger is built by specifying a type of event, and one or more filters to specify when a tag should fire.

Pageview-based triggers

In most cases, the trigger you’ll need to create will be based on the view of a particular page, or on a subset of pages. For example: On an ecommerce website, we'll usually want to create one trigger to fire the tag on all product pages, one trigger to fire the tag on the cart page, and one trigger to fire the tag on the purchase confirmation page.

To achieve this, select pageview as the event and enter the URL of the page (e.g.: the cart page) where you’d like your tag to fire as the trigger filter.

To create a trigger that fires a tag on any page within a subset of pages (eg: the product pages), you'll need to use operators like "contains" or "matches regular expression" when creating the trigger so it matches any product page URL.

Please read the documentation on triggers for more information.

Non-URL triggers

On rare occasions when the URL can't be used to differentiate page types, you can use other variables as filters for the pageview event. For example, let's imagine that you have the following HTML on your shopping cart:

<div id="cart_title">Shopping Cart</div>

Create a variable called "cart_text" of type "DOM Element" and specify the id "cart_title".

Then, create a trigger based on the pageview event and set the filter condition to cart_text equals "Shopping Cart".

Note that the HTML element containing the text you want to use to determine the page type must have an ID. You may also need to use additional care when applying this methodology to multilingual websites, as the actual text may change depending on the language.

Asynchronous events

To ensure the best performance of your dynamic remarketing campaigns, it’s important to fire tags as soon as the user completes important step in the purchasing funnels, such as adding a product to the cart. When adding a product to the cart doesn’t lead to a new pageview, you can trigger based on a click event or a custom event.

If you are using the Data Layer, use a custom event to let Tag Manager know that a product was added to the cart and pass the relevant product information at the same time, using the dataLayer.push method as follows:

  'event': 'ajax_cart_add',
  'ecomm_totalvalue': 78.45,
  'ecomm_prodid' : 'prodid4'

Then, when setting up the trigger, select custom event as the event type, and add as the event condition event equals 'ajax_cart_add'.

If you are not using the Data Layer, you will need to set up a click based trigger to fire a tag when the user clicks on a “add to cart” button. Learn more about events.

Configuring each tag instance

We now have all the pieces ready to be assembled. We have configure our variables to receive dynamic data and we have set up our triggers to tell Tag Manager when to fire our remarketing tags.

All that's left to do is to create one instance of the remarketing tag for each step of the funnel.

Here's an example of how you might set up a remarketing tag instance using the built-in AdWords remarketing tag template:

  • Tag Name: AdWords Remarketing - Add to Cart
  • Tag Type: AdWords Remarketing
  • Conversion ID: (use your own value)
  • Manually Specify Custom Parameters:
    • ecomm_prodid: {{product ID for cart page}}
    • ecomm_pagetype: cart
    • ecomm_totalvalue: {{cart value}}
    • ecomm_pcat: {{product category for cart page}}

With our implementation method, we have put each dynamic value in its own variable, so in the "Custom Parameter" section, select "Manually Specify" to associate each variable to the desired custom parameter key. When you type the custom parameter key, you need to make sure that you enter the parameter name using the required naming convention for our remarketing implementation use case.

Note that we're not using a variable for the key ecomm_pagetype, since we're creating one instance of the tag per value of pagetype, so instead, we're hardcoding the value as a text string for each tag instance.

Once you've set up one tag instance per pagetype, you'll then also need to set up one tag to fire on all other pages.

To do this, create one more instance of the remarketing tag, and set the firing trigger to all pages, and add all the triggers you had created for the other tags as blocking triggers, as shown:

Create AdWords tag that fires on all pages, with product, cart, and purchase pages blocking
Implementation using a single remarketing tag

Implementation using a single remarketing tag

The method of implementing one remarketing tag per funnel step is considered the most safe and robust option because it minimizes the use of custom JavaScript code and instead relies on built in Tag Manager features (such as triggers. However, the main drawback associated with it is that it entails creating one instance of the remarketing tag per step of the funnel, as well as one variable per dynamic parameter per pagetype. The setup can be somewhat complex and time-consuming.

It's possible to deploy the tag using a single variable, a single remarketing tag and a custom JavaScript tag. This requires less configuration of triggers, tags and variables in Tag Manager. However, the tradeoff is more custom JavaScript code, and you need to write custom event listeners manually in order to be able to fire tag asynchronously via auto-event tracking.

With this approach, we will first execute on every page a custom JavaScript tag that will check which type of page is being viewed, and based on this, execute some additional code to extract all the required dynamic parameter values at once and assemble them in a single object whose content is exactly the content that google_tag_params should have. Then the script will pass this data to the data layer as well as trigger an event fireRemarketingTag.

Finally, you can configure a single AdWords remarketing tag to fire with a custom event trigger based on the event fireRemarketingTag and read the custom parameters directly from the data layer.

This approach requires good knowledge of JavaScript and very careful testing. If correctly implemented, it can be a fast, efficient, and flexible way to tag a site.

Step 1: Create custom HTML tag

First, create a custom HTML tag. The new tag should contain custom JavaScript code that should be structured around the following example:

 try {
  if ( /* Insert JS expression to test for product page here */ ) {
   var prodid, totalvalue;
    Insert custom JS code to extract value of
    prodid and totalvalue from current document
    'event': 'fireRemarketingTag',
    'google_tag_params': {
      'ecomm_prodid': prodid,
      'ecomm_pagetype': 'product',
      'ecomm_totalvalue': totalvalue
  else if ( /* Insert JS expression to test for cart page */ ) {
   var prodid, totalvalue;
    Insert custom JS code to extract value of
    prodid and totalvalue from current document
    'event': 'fireRemarketingTag',
    'google_tag_params': {
      'ecomm_prodid': prodid,
      'ecomm_pagetype': 'cart',
      'ecomm_totalvalue': totalvalue
  else if ( /* Insert JS expression to test for purchase page */ ) {
   var prodid, totalvalue;
    Insert custom JS code to extract value of
    prodid and totalvalue from current document
    'event': 'fireRemarketingTag',
    'google_tag_params': {
      'ecomm_prodid': prodid,
      'ecomm_pagetype': 'purchase',
      'ecomm_totalvalue': totalvalue
  else {
    'event': 'fireRemarketingTag',
    'google_tag_params': { }
 catch (err) {}
}) ();

When saving the tag,  you will be prompted to specify a trigger. Create and apply a new trigger to fire on all pages when the DOM is ready:

Edit Trigger event page view, url matches regex, trigger type dom ready

The custom HTML Tag uses an anonymous, self-invoking function which allows us to limit the access to the various variables we might use in our custom code to the custom HTML tag itself, without polluting the global namespace.

It also uses a try/catch construct to ensure that the custom HTML tag will not raise an exception in case the code fails to execute properly.

The nice thing about this custom HTML approach is that we are free to also interact with 3rd party libraries that the site might be loading. For instance, if your site uses jQuery, you can add code to the custom HTML tag to add event listeners that fire the remarketing tag when asynchronous events occur.

It's advised to do extensive testing to verify that parameters are extracted properly on all pages, and to assure that the code works on every major browser version. For example, pages in certain product categories might have a different layout and markup structure than others (e.g. apparel vs. electronics) so it is important to ensure tha the underlying code is interfacing consistently with Tag Manager.

When the custom HTML tag has finished executing, it will raise a custom event in Tag Manager (event equals "fireRemarketingTag") and pass to the data layer key google_tag_params an object  containing all the required dynamic parameters ready to use for the remarketing tag.

dataLayer in Chrome console showing object properties

Step 2: Create a variable for google_tag_params

Then, create a single variable to pick up the value of google_tag_params from the data layer with the following configuration:

  • Variable type: Data Layer Variable
  • Data Layer Variable Name: google_tag_params
Create data layer variable google_tag_params

Step 3: Create trigger to fire the remarketing tag

Next, create a trigger that will be used to fire the remarketing tag with the following settings:

  • Trigger type: Custom Event
  • Event name: fireRemarketingTag
  • This trigger fires on: Some Custom Events
    • url > matches RegEx > .*
Add new custom event trigger where event equals fireRemarketingTag on every page

Step 4: Configure AdWords remarketing tag

Finally, create a single AdWords remarketing tag with the following settings:

  • Tag type: AdWords Remareting
  • Conversion ID: Your conversion ID from your AdWords account.
  • Custom Parameters:
    • Use Data Layer: {{google_tag_params}}
Create adwords dynamic remarketing tag

Implementing a conversion tracking tag

Tag Manager features a built-in template for setting up a conversion tracking tag. See AdWords Conversion Tracking for more information. It’s highly recommended that you implement the Adwords conversion tracking tag in addition to the remarketing tag so that you can take advantage of powerful, real-time, automated bidding algorithms such as Target CPA or Target ROAS.

Testing and deploying

Throughout the implementation process of setting up AdWords dynamic remarketing, you should regularly test that your tags and custom code are working as expected.

To do this, click on the arrow next to the publish button in the upper right side of the screen and select Debug.

Click the debug button

This will set a cookie just on your browser so that when you browse your site, you navigate as if the container content was already deployed.

The debug mode also displays a debug panel allowing you to see which tags have been fired by Tag Manager and which trigger fired each of them.

Debug panel showing what tags have been fired

If the site is passing data to Tag Manager via the data layer, you should verify that the data that they are passing is correct by exploring the content of the dataLayer object in your browser's JavaScript console. The data layer is a JavaScript array composed of various bits of data stored as nested objects.

Code inspector showing data layer objects

It's also a good idea to test with the JavaScript console open so you can see if your custom JavaScript code is causing any errors.

Make sure to test various scenarios so you can verify the tag behaves correctly (adding different types of products to the cart, view a cart with multiple products etc.)

When using custom JavaScript variables or custom HTML tags, it is a best practice to write your code inside a try/catch block. If your code triggers an error (which might happen if your site changes at some point in the future rendering your custom code invalid), it will be "caught" by the JavaScript interpreter instead of raising an exception. When you are testing your code however, it's best to remove the try/catch construct so you can observe in the console what errors your code might trigger. When you have fixed any errors and have verified that your code works correctly, add the try/catch block back again to future proof it before deploying it.

When you have finished testing your tags, you can deploy them to the site by clicking Publish. This should complete your setup of AdWords dynamic remarketing!

Was this article helpful?
How can we improve it?