Google Ads 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 a step further by showing your visitors an ad with the specific product they had previously viewed on your site.

This guide will show you how to implement Google Ads dynamic remarketing with Google Tag Manager. To better understand the process, review the dynamic remarketing guide on the Google Ads help center before you attempt this tag implementation.

Overview

To tag your site for remarketing, you need to:

  • Deploy a Google Ads remarketing tag on every page of your site.
  • Pass dynamic values to the remarketing tag on key steps of your site. These values can be things like the product ID of an item a user added to their cart, the origin and destination of a flight a user searched for, the promotion ID of an offer a user had clicked on, etc.)

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 different business categories, such as education, jobs, travel, etc. See the list of custom parameters on the Google Ads Help Center, and select one that is appropriate for your organization.

There are two approaches to configure a Google Ads dynamic remarketing tag implementation in Tag Manager:

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

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

Populate custom parameter values

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 data from your page, you will need to implement a Tag Manager variable. Data may be pulled in several ways, such as from 1st party cookies, the data layer, or custom JavaScript.

Insert values in the remarketing tag

Once you've configured the tag to receive the target data as variables, use those variables to insert data into Tag Manager's Google Ads remarketing tag template.

Specify triggers to fire the remarketing tag

The next step is to define triggers that tell Tag Manager when to fire each instance of the remarketing tag. You can define 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 last step is to test the tags on your site with 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:

One tag per funnel step

One tag per funnel step implementation

This section describes how to implement Google Ads dynamic remarketing tags in Tag Manager with one instance of the remarketing tag for each step of your purchase funnel.

The main steps for this process are:

  1. Configure your website to pass values to Tag Manager via the data layer or custom JavaScript.
  2. Create data layer variables in Tag Manager.
  3. Create triggers.
  4. Configure the remarketing tag with custom parameters.
Set up the data layer code on your site

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. Work with a developer to configure the data layer code on your website. If you plan to gather the dynamic values via custom JavaScript variables through Tag Manager, skip this step.

The dataLayer() object is used to pass custom data from your site to Tag Manager. This code should be placed above your container code so that the data is available when Tag Manager executes. 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:

<script>
dataLayer = [];
dataLayer.push({
  'ecomm_totalvalue': 699.12,
  'ecomm_prodid' : ['prodid1', 'prodid2', 'prodid3']
});
</script>

The key names here are arbitrary and do not need to conform to any requirements (e.g. they don't need to match the custom parameter naming conventions for the Google Ads 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 to pass 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 to view the data passed from the site to Tag Manager.

Some funnel steps may happen asynchronously (ie: without a full page reload). For instance, this may occur when a product is added to the cart and the page doesn't change; a success message or alert may appear instead. It is important to be able to capture dynamic cart events: Without it, you might miss a lot of shopping cart abandoners and make your remarketing efforts less accurate.

The dataLayer.push() method 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, you can use this function to update the data layer:

<script>
dataLayer.push({
  'event': 'ajax_cart_add',
  'ecomm_totalvalue': 78.45,
  'ecomm_prodid' : 'prodid4'
});
</script>

Configure variables

Configure a Tag Manager variable for each piece of dynamic data that we want to pass to the remarketing tag. In this example, we'll have a variable for ecomm_prodid and a variable for ecomm_totalvalue.

There are several ways to capture 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.

Update your site to pass values to Tag Manager via the data layer: This is the more robust method for remarketing tag configuration. This method will pass dynamic values directly to your remarketing tag from the data layer, but it requires that a developer make code changes on your website. Once the data is available in the data layer, create data layer variables in Tag Manager to pass these values to your tags.

Developers can learn more about data layer implementations at the Tag Manager developer site.

Use custom JavaScript variables: You can alternatively use custom JavaScript code to populate the dynamic parameter values from Tag Manager with custom 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 changes 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 remarketing 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 this 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 need to configure.

If you have not implemented the data layer...

Without the data layer, you will need to extract the dynamic value needed from the source code. This can be accomplished with a Tag Manager JavaScript Variable. Identify the variable from your existing JavaScript code, and create a JavaScript variable in Tag Manager that uses the name of the variable.

If you do not use the data layer and rely on custom JavaScript variables to grab dynamic parameter values, it is very likely that you will need to use a different strategy to populate the same custom parameter depending on the step of the funnel.

For instance, the way you populate the product ID on a product page may be different than the way you populate the product ID on the cart page or on the purchase confirmation page, because the source code or JavaScript variables that you can piggyback on will be different for each step. Therefore, you might 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 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 create a pageview trigger

  1. Click Triggers and then New.
  2. Click Trigger Configuration and select Page View.
  3. Set the trigger to fire on Some Page Views.
  4. In the section 'Fire this trigger when an Event occurs and all of these conditions are true', enter Page URL and then contains and then <path>, where <path> is a predictable part of the URL for the pages where you want this tag to fire (e.g. /products/).

To create a trigger that fires a tag on a group of pages (e.g. the product pages), use operators like "contains" or "matches regular expression" so it matches the desired page URL.

Non-URL triggers

In situations where the URL can't be used to differentiate page types, you may be able to use other variables as filters for the pageview event. For example, an ID attribute may be present:

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

To create a trigger that will fire when this attribute is found:

  1. Click Triggers and then New.
  2. Click Trigger Configuration and select Element Visibility.
  3. Set Selection Method to ID.
  4. In the Element ID field, enter cart_title.
  5. Set this tag to fire once per page.
  6. Set Minimum Percent Visible to 1%.
  7. Set the trigger to fire on All Visibility Events.

Asynchronous events

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

If you have a data layer implementation, 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.

When an item is added to the cart, your website code should use dataLayer.push() to add an event to the data layer:

dataLayer.push({
  'event': 'ajax_cart_add',
  'ecomm_totalvalue': 78.45,
  'ecomm_prodid' : 'prodid4'
});

Next, create the trigger in Tag Manager:

  1. Click Triggers and then New.
  2. Click Trigger Configuration and select Other: Custom Event.
  3. Set Event Name to ajax_cart_add.
TIP: 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 button. Learn more about events.

Configure each tag instance

You now have all the pieces ready to be assembled. You have configured variables to receive dynamic data and have set up triggers to tell Tag Manager when to fire remarketing tags. The final step is to create one instance of the remarketing tag for each step of the funnel.

Here's an example remarketing tag configuration:

  1. Click Tags and then New.
  2. Click Tag Configuration and select Google Ads Remarketing.
  3. Set the Conversion ID (and optional Conversion Label) to the value provided by Google Ads. Learn more
    TIP: Use a Constant String variable for your Google Ads Conversion ID. This will make it easier to create and manage additional Google Ads tags.
  4. Set Custom Parameters to Manually Specify.
  5. Use +Add Custom Parameter to add four key value rows. Populate those rows with the following:
    • ecomm_prodid: {{product ID for cart page}}
    • ecomm_pagetype: cart
    • ecomm_totalvalue: {{cart value}}
    • ecomm_pcat: {{product category for cart page}}

Note that a Tag Manager variable is not used for the key ecomm_pagetype. This is because in this example you will create one instance of the tag for each page type. Repeat this tag setup for every other page type that is required.

Once you've set up a tag for each specific page type, set up a standard remarketing tag to fire on all pages. To do this, create a new Google Ads remarketing tag, set the firing trigger to all pages, and add all the triggers you had created for the other tags as blocking triggers:

  1. Click Tags and then New.
  2. Click Tag Configuration and select Google Ads Remarketing.
  3. Set the Conversion ID (and optional Conversion Label) to the value provided by Google Ads. Learn more.
  4. Click Triggering and select a trigger that will fire on all pages.
  5. Click Add Exception and enter an exception for each trigger already covered by the custom parameters entered above.
Implementation using a single remarketing tag

Implementation using a single remarketing tag

The one remarketing tag per funnel step method 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 that method is complexity: You have to create a new instance of the remarketing tag for each step of the funnel, as well as one variable for each parameter and pagetype.

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 in order to be able to fire tag asynchronously. The primary steps for this method are:

  1. Deploy a custom JavaScript tag that fires on every page. This tag 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.
  2. The script will pass the data from step 1 to the data layer, as well as trigger an event called fireRemarketingTag.
  3. Configure a single Google Ads 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 knowledge of JavaScript and careful testing. If correctly implemented, this is 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 this example:

<script>
(function(){
 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
   */
   dataLayer.push({
    '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
   */
   dataLayer.push({
    '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
   */
   dataLayer.push({
    'event': 'fireRemarketingTag',
    'google_tag_params': {
      'ecomm_prodid': prodid,
      'ecomm_pagetype': 'purchase',
      'ecomm_totalvalue': totalvalue
    }
   });
  }
  else {
   dataLayer.push({
    'event': 'fireRemarketingTag',
    'google_tag_params': { }
   });
  }
 }
 catch (err) {}
}) ();
</script>

In the new custom HTML tag, click Triggering and create or add a trigger with the following properties:

  • Trigger type: Page View: DOM Ready
  • This trigger fires on: All DOM Ready Events
To create a new trigger from a tag template, click Triggering and then click addAdd.

The above example uses an anonymous, self-invoked JavaScript function which limits access of variables to the custom HTML tag itself, outside of the global space. 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.

This approach allows you to interact with 3rd party libraries. 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.

Test your code thoroughly 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 that the underlying code interfaces properly with Tag Manager.

When the custom HTML tag has executed, it will send the custom fireRemarketingTag event and the google_tag_params key with the required parameters to the data layer.

Step 2: Create a variable for google_tag_params

Create a variable in Tag Manager that will pick up the value of google_tag_params from the data layer:

  • Variable type: Data Layer Variable
  • Data Layer Variable Name: google_tag_params

Step 3: Create trigger to fire the remarketing tag

Create a trigger that will be used to fire the remarketing tag with these settings:

  • Trigger type: Custom Event
  • Event name: fireRemarketingTag
  • This trigger fires on: Some Custom Eventsurl and then matches RegEx and then .*

Step 4: Configure Google Ads remarketing tag

Create a new Google Ads remarketing tag with these settings:

  • Tag type: Google Ads Remarketing
  • Conversion ID: Enter your conversion ID from your Google Ads account.
  • Custom Parameters: Use Data Layer: {{google_tag_params}}

Implement a conversion tracking tag

Implement the Google Ads Conversion Tracking tag in addition to the remarketing tag to take advantage of real-time automated bidding algorithms such as Target CPA and Target ROAS.

Test and deploy

With every Tag Manager configuration, always preview and test your changes to ensure your container functions as expected. It's also a good idea to test with the JavaScript console open so you can see if your custom JavaScript code causes any errors. Test various scenarios to verify that the tag configuration behaves correctly: Add different types of products to the cart, view the cart with multiple products, etc.

When you use 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 website code changes at some point in the future and renders your custom remarketing code configuration invalid), it will be "caught" by the JavaScript interpreter instead of raising an exception. When you test your code, remove the try/catch construct so you can observe any errors that appear in the console. When you have fixed any errors and have verified that your code works correctly, add the try/catch block back again.

After you have tested your changes, publish your container to activate your Google Ads dynamic remarketing configuration.

Was this article helpful?
How can we improve it?