Add the dynamic remarketing tag to your site

About dynamic remarketing

Dynamic remarketing lets you reach your past site visitors with ads that show the specific products people viewed on your site. Once you've set up your dynamic remarketing campaign, you'll need to add the dynamic remarketing tag, including custom parameters, to your site so your lists can start working.

Your remarketing tag shouldn't be associated with any personally identifiable or sensitive information. Sensitive categories of sites can't use remarketing. If you're setting up a remarketing campaign and placing the remarketing tag on your site, you need to follow the Policy for advertising based on interests and location.

Click the links below to learn how to implement, validate, and customize the dynamic remarketing tag:

Place the tag on your site with custom parameters

You need to add the dynamic remarketing tag (snippet of code) on every page of your site. The tag will collect the product id and the type of page people visited (product page, shopping cart page, purchase page, general site visit).

Below is an example of how the dynamic remarketing tag might look. This isn't the exact snippet of code you should add to your site. Learn where to find your remarketing tag.

<script type="text/javascript">
var google_tag_params = {
ecomm_prodid: 'REPLACE_WITH_VALUE',
ecomm_pagetype: 'REPLACE_WITH_VALUE',
ecomm_totalvalue: 'REPLACE_WITH_VALUE'
};
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = XXXXXXXXXX;
var google_conversion_label = "YYYYYYYYYY";
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/XXXXXXXXXX/?value=0&amp;label=YYYYYYYYYY&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

The section in green font (that ends with the </script> tag below ecomm_totalvalue: 'REPLACE_WITH_VALUE') includes the custom parameters, and the section in blue font (that ends with the </noscript> tag) includes the remarketing tag.

  • The tag must be implemented on all pages (added just before </body> tag) of your website.
  • Custom parameters are the only way to dynamically send values to your AdWords account (for example, product ID, page type, total value) based on information on the page.

Important notes:

  • The code should use JSON format: JavaScript Object Notation, a format for transmitting structured data over a network connection.
  • You should use at least ecomm_prodid, ecomm_pagetype, and ecomm_totalvalue as your custom parameter keys for the lists to start working correctly.
  • On pages that have multiple Product IDs (for example, the shopping cart page), you can group them using brackets. Example: ecomm_prodid: ['123', '456']
  • You can either use single or double quotes in the custom parameters. Both will work, but you have to be consistent. If you choose to use single quotes, use them for all values.
  • Don't forget to include a comma to separate the parameters. If you don't include commas, the tag won't work properly. See common errors in the dynamic remarketing tag setup and find out about how Google Tag Assistant can help you check for these common errors. (Note: This help article is available in English only.)

Custom parameters

Basic parameters

Key (don't change) Example values Definition
ecomm_prodid 1234 Product Id - Must match the Product Id from the Google Merchant Center feed. This allows the dynamic ad to show people the exact product they viewed.
ecomm_pagetype home,
searchresults,
category,
product,
cart,
purchase,
other
Page Type - Indicates which page people visited. You need to use one of the values listed in the middle column. Don't change these values and keep them in English, even if your site is in a different language. A value must be present on each page. These values might be used for the lists that AdWords created for you and for automated bid optimization.
"Product" refers to viewing a product page, and "other" should be used for pages not covered by the other values.
Important: every page needs to have a page type value.
ecomm_totalvalue 49.99 Total Value - Specify the value of the product. On a cart or purchase page, you need to specify the total value (summing up the value of all products). This value might be used in automated bidding optimization and may be used to categorize your lists into groups according to the value of products.

Note

If the value for ecomm_prodid doesn't match the product id from the Google Merchant Center feed, we can't show that product in the ad to the visitor. We'll then select the next best product to show, based on other signals.

Examples of custom parameters

Here's an example for a retail website with all the basic custom parameters implemented. Keep in mind that this is just the custom parameters section, and you also need to include the rest of the remarketing tag below the custom parameters.

Site section Custom parameter tag sample Notes
Home <script type="text/javascript">
var google_tag_params = {
ecomm_prodid: '',
ecomm_pagetype: 'home',
ecomm_totalvalue: ''
};
</script>
On the homepage, you have information about the page type.
Category page <script type="text/javascript">
var google_tag_params = {
ecomm_prodid: '',
ecomm_pagetype: 'category',
ecomm_totalvalue: ''
};
</script>
On the category page, you have information about the page type.
You can also add an advanced custom parameter to send AdWords the category type (example: ecomm_category).
Product page <script type="text/javascript">
var google_tag_params = {
ecomm_prodid: '123',
ecomm_pagetype: 'product',
ecomm_totalvalue: '99.00'
};
</script>
On the product page, you can dynamically fill in information about the product being viewed.

Important: Use the same product ID from your Google Merchant Center feed.

Cart page <script type="text/javascript">
var google_tag_params = {
ecomm_prodid: ['123', '456'],
ecomm_pagetype: 'cart',
ecomm_totalvalue: '120.00'
};
</script>

On the cart page you should send all the products you have in the cart.
When you have multiple values in a parameter, use a JavaScript array (brackets).
Important: In the "ecomm_totalvalue" parameter, you need to send the sum of the value in the cart.

Purchase page <script type="text/javascript">
var google_tag_params = {
ecomm_prodid: ['123', '456'],
ecomm_pagetype: 'purchase',
ecomm_totalvalue: '120.00'
};
</script>
Purchase Confirmation page should also have all products that the user bought.

Important: In the "ecomm_totalvalue" parameter, you need to send the sum of the value in the cart.
All other pages <script type="text/javascript">
var google_tag_params = {
ecomm_prodid: '',
ecomm_pagetype: 'siteview',
ecomm_totalvalue: ''
};
</script>
On all other pages, use siteview for ecomm_pagetype.

Note

We recommend using the values in this article for optimal setup. There needs to be a value for ecomm_pagetype on all pages. We recommend minimally using "product, cart, purchase, other," because these will form lists that AdWords already creates for you when you set up your dynamic remarketing campaign. Additional values can be used to define other pages specific to your site.

Tip

If you already have a regular remarketing tag and a Google Merchant Center account, you could make a few changes to your existing tag to start using dynamic remarketing. These changes will let you send additional information to AdWords through your tag.

Validate that the tag is working correctly and learn about common errors

There are two ways that you should validate your tag:

  • Google Tag Assistant: During tag implementation, you can use Google Tag Assistant to validate on each page that your tag is working properly. (Note: This help article is available in English only.) Google Tag Assistant will catch most syntax errors, and can also validate if the product ID you're using matches the ID in your Google Merchant Center account. Download Tag Assistant from the Chrome web store.
  • The "Remarketing tag" section in AdWords: After you've added the tag across your site, you can visit the "Audiences" section of the Shared Library in your AdWords account to validate your remarketing tag. In the "Remarketing tag" box at the top of the page, you'll find information about your tag, such as implementation problems or any opportunities to further optimize your setup.

For example, you might discover that some of the product IDs you send through the tag don’t have a matching entry in the Google Merchant Center; this would mean that you're losing a valuable opportunity to serve an effective dynamic ad. Tag validation will give you guidance on how to address this and other tag issues.

You can use Google Tag Manager to implement the dynamic remarketing tag. Learn more about Google Tag Manager.

Common errors when setting up custom parameters

Below are some of the common mistakes people make when they implement custom parameters. If you use Tag Assistant, you'll be able to identify most of these common mistakes.

  1. String values are not quoted. For example:
    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: 2234,
    ecomm_pagetype: purchase,
    ecomm_totalvalue: 120.99
    };
    </script>

    Should be changed to:

    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: 2234,
    ecomm_pagetype: "purchase",
    ecomm_totalvalue: 120.99
    };
    </script>

    Single quotes also work, as long as they are used consistently. Numbers don't need quotes.

  2. Custom parameters are not separated by a comma (","). For example:
    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: 234
    ecomm_pagetype: "purchase"
    ecomm_totalvalue: 120.99
    };
    </script>

    Should be changed to:
    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: 234,
    ecomm_pagetype: "purchase",
    ecomm_totalvalue: 120.99
    };
    </script>

    The last custom parameter doesn't need to have "," after it. But it's OK if it does.

  3. Parameter contains space or non-ASCII characters. We only support [a-z][0-9] and '_'. For example:
    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: 234,
    ecomm pagetype: "purchase",
    ecomm_totalvalue: 120.99
    };
    </script>

    Should be changed to:

    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: 234,
    ecomm_pagetype: "purchase",
    ecomm_totalvalue: 120.99
    };
    </script>
  4. Multiple values in a parameter without brackets. For example:
    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: "123,"234",
    ecomm_pagetype: "cart",
    ecomm_totalvalue: 100,50
    };
    </script>

    Should be changed to:

    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: ["123","234"],
    ecomm_pagetype: "cart",
    ecomm_totalvalue: [100,50]
    };
    </script>
  5. Parameter with no value. For example:
    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: ,
    ecomm_pagetype: "other",
    ecomm_totalvalue:
    };
    </script>

    Should be changed to:
    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: "",
    ecomm_pagetype: "other",
    ecomm_totalvalue: ""
    };
    </script>

    or simply:

    <script type="text/javascript">
    var google_tag_params = {
    ecomm_pagetype: "other"
    };
    </script>
  6. Incorrect naming convention for custom parameters. For example:
    <script type="text/javascript">
    var google_tag_params = {
    pid: 2234,
    pagetype: "purchase",
    totalvalue: 120.99
    };
    </script>

    Should be changed to:

    <script type="text/javascript">
    var google_tag_params = {
    ecomm_prodid: 2234,
    ecomm_pagetype: "purchase",
    ecomm_totalvalue: 120.99
    };
    </script>

Customize the tag to reach the right visitors and to optimize your bids

Advanced tagging for better performance

You can send additional parameters through the tag. With these parameters, you can categorize your site visitors in more sophisticated ways to further tailor your bids and ads. Advanced parameters may also be used by automated bidding to optimize performance and by the dynamic ad recommendation engine to select products for your ads.

We encourage you to send as many parameters through the tag as you have available.

Advanced parameters

(Additional custom parameters you can specify)

Key Example values Definition
ecomm_rec_prodid 5678, 1122, 6760 Recommended product IDs - Specify one or multiple products in priority order (the first being the highest priority) that are recommended with the main product. These must match the "product id" from the Google Merchant Center feed.
ecomm_category electronics Product Category - Specify the category someone visited. This may be used to build remarketing lists and tailor ads or bids. For example, you may bid differently for product categories based on their value or margin.
ecomm_pvalue 29.99 Product Value - Specify the value for the product. The product value will also be available to you in AdWords so you can define remarketing lists based on the Merchant Center feed attribute for product value. Occasionally, a feed may be missing some product items, and sending the product value through the tag will ensure you can always use this value.
ecomm_quantity 3 Product Quantity - Specify the quantity of a product a visitor selected, in the case of shopping cart or purchase event. In the case of multiple products, you may use a JavaScript array, for example [‘3’,’2’,’2’], which would mean that the visitor selected or purchased three of the first product, and so forth.
a 22 Visitor's Age - Specify the age of the visitor
g f, m Visitor's Gender - Specify the gender of the visitor. Use ‘f’ for female and ‘m’ for male.
hasaccount y, n Visitor has an account - Specify whether or not the visitor has an account. This may be used to customize lists, tailor bids and ads, and for automated bidding optimization. Use "y" for yes and "n" for no.
cqs 1, 2, 3 Customer Quality Score - Specify the visitor value ranging from 1 to 3 (where 1 is the most valuable). The range is flexible and values higher than 3 can be used (with 1 still being the most valuable). Keeping the range small will enable automated optimization to be most effective.
rp y, n Visitor Repeat Purchaser
ly 1, 2, 3 Visitor Loyalty Score - Specify the visitor loyalty score ranging from 1 to 3 (where 1 is the most valuable). The range is flexible and values higher than 3 can be used (with 1 still being the most valuable). Keeping the range small can enable automated optimization to be most effective.
hs 1, 2, 3 Visitor High Spender Score - Specify the user high spender score ranging from 1 to 3 (where 1 is the most valuable). The range is flexible and values higher than 3 can be used (with 1 still being the most valuable). Keeping the range small can enable automated optimization to be most effective.
Ajax, Flash and other non-HTML implementations

The remarketing tag usually gets activated when a page loads. However, on many sites, important events, such as adding a product to a shopping cart, don't lead to a new page and are done using Ajax. Being able to identify that a visitor added a product to the shopping cart is important because it shows a strong intent of purchase. Follow these steps to activate the tag when an event occurs:

  1. Follow the instructions listed on the section below labeled "How to implement the non JavaScript tag (image tag)" to create an tag with parameters.
  2. Replace all instances of "&amp;" in the tag with "&."
  3. Define a simple JavaScript function to create the tag upon some event. The following code snippet is an example:
    <html>
    <head>
    <script type="text/javascript">
    function activateRemarketingTag(prodid, pagetype) {
    var img = document.createElement("img");
    img.onload = function() { return; };
    img.src = "//googleads.g.doubleclick.net/pagead/viewthroughconversion/XXXXXXXXXX/?value=0&label=YYYYYYYYYY&guid=ON&script=0&data=ecomm_prodid%3D" + prodid + "%3Becomm_pagetype%3D" + pagetype + "&random=" + new Date().getTime();
    }
    </script>
    </head>
    <body>
    <button onClick="activateRemarketingTag(1234567, 'cart');">Click Me!</button>
    </body>
    </html>
How to implement the non-JavaScript tag (image tag) - Only use if the above implementation doesn't work

We recommend using the JavaScript tag because it leads to fewer implementation errors and addresses several HTML goals. For example, some web browsers cache images so that a subsequent page visit loads faster. This allows images to display directly from your computer’s cache, instead of having to revisit the website’s web server. Because the remarketing tag uses the <IMG> HTML tag, it's treated like an image and will get cached in these instances. As result, it won't be properly activated on multiple page visits. The JavaScript code snippet addresses this.

You can use these instructions if you want to use the non-JavaScript part of the tag (also known as the image tag) or if you want to have a shorter version of the tag. The image tag doesn't require the JavaScript library (conversion.js) and the and the loading of the image happens in parallel with the page loading.

You need to customize the non-JavaScript portion of the remarketing tag so it can still send values. The data needs to be manually encoded.

Here’s how to set up the remarketing tag: Take the tag you've just created in the section labeled "Place the tag on your site with custom parameters." The tag should look like this example:

<script type="text/javascript">
var google_tag_params = {
ecomm_prodid: 'REPLACE_WITH_VALUE',
ecomm_pagetype: 'REPLACE_WITH_VALUE',
ecomm_totalvalue: 'REPLACE_WITH_VALUE'
};
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = XXXXXXXXXX;
var google_conversion_label = "YYYYYYYYYY";
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/XXXXXXXXXX/?value=0&amp;label=YYYYYYYYYY&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

The highlighted text is the non-JavaScript tag. Follow these steps to send your custom parameters through the remarketing tag:

  1. Prepare the custom parameters (also called key/values) you'd like to send to AdWords. The key/values should be sent in the following format:

    key1=val1;key2=val2;key2=val3...

    For example, if you want to send ecomm_prodid=100 and ecomm_pagetype=purchase as customer parameters, they should be arranged like this:

    ecomm_prodid=100;ecomm_pagetype=purchase

    If a given key has multiple values, say multiple product ids on a shopping cart page, use commas to separate the values:

    ecomm_prodid=101,102;ecomm_pagetype=purchase

  2. URL-encode the string created above, and append it to the pixel's URL as a parameter called "data."
  3. In the example above, change the characters '=' ';' and ',' to their URL-encoded equivalent %3D %3B and %2C. After the change, the final img src looks like this:

    //googleads.g.doubleclick.net/pagead/viewthroughconversion/XXXXXXXXXX/?value=0&amp;label=YYYYYYYYYY&amp;guid=ON&amp;script=0&amp;data=ecomm_prodid%3D101%2C102%3Becomm_pagetype%3Dpurchase

    If you're using JavaScript, you can use the encodeURIComponent() function:
    var prodid = ['123A','456B'];
    var tag_parameters = 'ecomm_prodid=' + prodid.join(',') +
    ';ecomm_pagetype=purchase';
    var pixelURL = "//googleads.g.doubleclick.net/pagead/viewthroughconversion/XXXXXXXXXX/?value=0&label=YYYYYYYYYY&guid=ON&script=0&data=" + encodeURIComponent(tag_parameters);

    var img = document.createElement("img");
    img.onload = function() { return; };
    img.src = pixelURL;

  4. Below is the final img tag, which you can put on your site. It gives you the same functionality as the JavaScript version of the tag.

    <div style="display:inline;">
    <img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/XXXXXXXXXX/?value=0&amp;label=YYYYYYYYYY&amp;guid=ON&amp;script=0&amp;data=ecomm_prodid%3D101%2C102%3Becomm_pagetype%3Dpurchase"/>
    </div>

    A note on ampersands (&): ampersands must be encoded as "&amp;" inside of HTML code (in the <img> src attribute), but not inside of JavaScript code. Many tags and containers that allow the piggybacking of pixels (like DoubleClick Floodlight) expect the URLs to not be HTML-encoded. This leads to frequent errors of double-encoding ampersands which leads to improper tracking. Make sure you use proper URL depending on the context. If you're unsure, use the Google Tag Assistant chrome extension to verify your implementation.