Overview of AdWords Remarketing Tag

The AdWords Remarketing Tag is a small snippet of HTML and JavaScript to record which pages of your site a visitor has seen, as well as optional meta-information that you provide about that visit (such as product IDs or basket values). This information can then be used to improve your marketing campaign's targeting, for example to show specific ads to visitors who have viewed a product's page or exclude visitors who have viewed certain pages.

There is both a standard version of the AdWords Remarketing Tag and an asynchronous version designed for clients with AJAX-based or dynamic websites. The standard AdWords Remarketing Tag is designed for the vast majority of customers; some information in this guide does not apply to the asynchronous version of the tag (for example, when the tag fires), but the asynchronous tag page explains the differences.

Both versions of the AdWords Remarketing Tag work with the AdWords Conversion Tag. Although code snippets for the AdWords Remarketing Tag and the AdWords Conversion Tag look similar, they perform different tasks and it is normal to have both the AdWords Remarketing Tag and the AdWords Conversion Tag on your conversion pages.

The standard AdWords Remarketing Tag

You can retrieve the details of your AdWords Remarketing Tag from within AdWords by clicking the "Shared Library" link below the list of your campaigns, and then clicking on "Audiences". Once in your Audiences view, you can click on the "View tag details" button at the top right of the screen to retrieve your AdWords Remarketing Tag. The AdWords Remarketing Tag's code snippet can be found in the "Setup" section, and comes pre-filled with your account's google_conversion_id.

As noted above, the AdWords Remarketing Tag contains a reference to your AdWords account's google_conversion_id which is a unique identifier for your account. This main tag should be used by everyone planning to do remarketing in AdWords and on its own is sufficient to do basic "static remarketing" activity such as remarketing to users who have visited a page on your site.

Additionally the AdWords Remarketing Tag can also use an extra optional part that contains a google_tag_params variable that is used by the main tag to provide additional information about the event for advertisers who are doing "dynamic remarketing" such as showing visitors to your site an ad for the specific products they viewed. The google_tag_params section is only required when doing dynamic remarketing - it is not required if you only need to do static remarketing and so can safely be ignored and left undefined. More details about this extra optional use of the google_tag_params variable can be found in the Dynamic AdWords Remarketing Tag tab below.

Static AdWords Remarketing Tag

Your AdWords account has a remarketing tag that can be used for all of your remarketing activity. It has a single google_conversion_id value (123465789 in the example below - yours will be different and can be found in the tag's set up details in the AdWords interface explained above). Some existing older tags may also have a google_conversion_label - the conversion label is deprecated and is no longer required for new tags.

This is the default option and will be the option that most advertisers will use.

<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 123456789;
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/123456789/?value=0&amp;guid=ON&amp;script=0"/>
  </div>
</noscript>

Dynamic AdWords Remarketing Tag

Your AdWords account has a remarketing tag that can be used for all of your remarketing activity. It has a single google_conversion_id value (123465789 in the example below - yours will be different and can be found in the tag's set up details in the AdWords interface explained above). As is the case with the static AdWords Remarketing Tag, some existing older tags may also have a google_conversion_label - the conversion label is deprecated and is no longer required for new tags.

As you are doing dynamic remarketing then you should include the google_tag_params tag to provide additional dynamic parameters to the remarketing tag.

<script type="text/javascript">
var google_tag_params = {
  parameter1: 'abc123', 
  parameter2: 29.99
};
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 123456789;
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/123456789/?value=0&amp;guid=ON&amp;script=0"/>
  </div>
</noscript>
The content of the google_tag_params object can be populated by automatically through javascript, or alternatively via server-side languages as the page is dynamically generated.

When implementing this please pay particular attention to the validity of the javascript syntax to avoid generating any javascript errors. Some examples of common problems are:
  • Adding a trailing comma on the last member of the google_tag_params object.
  • Providing string values without quotes - all string literals are properly quoted with either ' or ".
  • Incorrect or missing array notation when providing multiple values.
More details about how to pass data correctly can be found in the parameter reference, and help on validating that the implementation is correct can be found on the verification & troubleshooting page.

Plain HTML & Javascript

Simple javascript DOM selectors could be used to automatically extract the relevant information from the page's DOM and insert it into the google_tag_params javascript object.

For example if you have your product's ID number in an element with the HTML ID of "productId" you could extract that in a way similar to the example below:

<script type="text/javascript">
var productId = document.querySelector('#productId').innerText;
var google_tag_params = {
  ecomm_prodid:productId 
};
</script>
If you take this approach please make sure you update the tag whenever the site's design changes.

PHP

You can use simple PHP echo statements to populate the content of the parameter values to dynamically populate them.

For example if your site builds each product page from a database and you wanted to include the ecomm_prodid parameter value in the {[tag}}, you could store the product's ID into the PHP variable $prodIdValue as you dynamically build the page using PHP, and then include that variable in the google_tag_params section of the tag using PHP's echo function.

<script type="text/javascript">
var google_tag_params = {
  ecomm_prodid: '<?php echo $prodIdValue ?>' 
};
</script>

JSP

You can use simple JSP scriptlet statements to populate the content of the parameter values to dynamically populate them.

For example if your site builds each product page from a database and you wanted to include the ecomm_prodid parameter value in the AdWords Remarketing Tag, you could store the product's ID into request's prodIdValue attribute as you dynamically build the page using servlets, and then include that variable in the google_tag_params section of the tag using simple scriplets.

<script type="text/javascript">
var google_tag_params = {
  ecomm_prodid: '<% request.getAttribute("prodIdValue") %>' 
};
</script>
Alternatively if you are using JSTL you can use JSTL Core's c:out tag instead.
<script type="text/javascript">
var google_tag_params = {
  ecomm_prodid: '<% c:out value="${prodIdValue}" %>' 
};
</script>
Then in your servlet's source file for the page you can retrieve the value from your database and set the value dynamically when the page loads,
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // ... The rest of your doGet code ...   
  request.setAttribute("prodIdValue", prodIdValue); // prodIdValue should have a value from your database by this point
}

ASP.NET

You can use simple ASP.NET Response.Write statements to populate the content of the parameter values to dynamically populate them.

For example if your website builds each product page from a database and you wanted to include the ecomm_prodid parameter value in the AdWords Remarketing Tag, you could store the product's ID into the ASP.NET variable variable ProdIdValue as you dynamically build the page using ASP.NET, and then include that variable in the google_tag_params section of the tag using ASP.NET's Response.Write function.

<script type="text/javascript">
var google_tag_params = {
  ecomm_prodid: '<% Response.Write(ProdIdValue) %>' 
};
</script>
Alternatively, if you would prefer to use code behind with your website you could use ASP.NET LiteralControl server controls to populate the AdWords Remarketing Tag (we recommend against using LabelControl as it will add a HTML tag when rendered which would cause javascript errors). For example you could add the following to your ASPX file.
<script type="text/javascript">
var google_tag_params = {
  ecomm_prodid: '<asp:Literal runat="server" id="ProdIdValueLiteral" />' 
};
</script>
Then in your code behind source file for the page you can retrieve the value from your database and set the value dynamically when the page loads, making use of the PassThrough property to ensure that the value is rendered as-is without any browser-based modifications, transforms, or encoding by the ASP.NET runtime.
protected void Page_Load(object sender, EventArgs e)
{
  // ... The rest of your Page_Load code ...
  ProdIdValueLiteral.PassThrough;
  ProdIdValueLiteral.Text = ProdIdValue;  // ProdIdValue should have a value from your database by this point
}

Placement & Behaviour

The AdWords Remarketing Tag should be present on all areas of your site where user-intent signals for remarketing can be recorded including all landing pages, product/category pages, basket pages and conversion pages. If you have any editorial content on your site such as a blog or "get the look" or magazine-style content then that is also a good area to use the AdWords Remarketing Tag as it represents a good sign of user engagement.

We recommend that the tag be placed before the closing body tag to avoid any page loading delays whilst the browser downloads and processes the conversion.js file from the googleadservices.com server. Please don't modify the script tag to use the async parameter as it can lead to unpredictable behaviour.

Once the conversion.js file has loaded it will be executed by the browser, and so fire the tag, automatically. No further code is required to trigger the tag into firing. If you include more than one remarketing tag on the page then the remarketing tag will fire more than once, but if you do this please take special care to ensure that you are not overwriting the globally-scoped variables used by the tag.

If any existing AdWords conversion tags are already on your site these should be left as-is; the AdWords Remarketing Tags do not replace or affect the normal operation of any AdWords conversion tags - please see the AdWords Conversion Tag section for additional details.

Variable Detail

The table below discusses the globally-scoped variables used by the standard AdWords Remarketing Tag. Note that the tag's javascript is expecting these specific variable names and so you should not alter the names. If you need to namespace these variables, or you need to use them more than once (such as two remarketing tags on the same page) then you may want to consider using the asynchronous tag of the AdWords Remarketing Tag.

VariableTypeDescription
google_conversion_idRequiredThis 9-digit number is a unique identifier and ties the tag to your AdWords account.
google_conversion_labelOptionalThe conversion label is deprecated but may be present in some older pre-existing tags.
google_customer_paramsOptionalThis variable contains a standard javascript object containing additional remarketing data used for dynamic remarketing. The object it references can be an empty object or an undefined variable. More details about this variable are discussed below this table.

If this variable is not provided, static remarketing rules can still be generated in AdWords by using URL-based rules.
google_remarketing_onlyRequiredThis variable should always have a value of true - it lets us know that this is a remarketing tag and not a standard conversion tag.

google_custom_params

When being used the optional google_custom_params variable should reference a javascript object with properties that represent custom parameters containing useful remarketing information, for example the value of a user's basket or the category of products a user is looking at. We recommend that this object is declared as google_tag_params but ultimately it doesn't matter what the object itself is called.

When the remarketing tag fires it will take the google_custom_params object and encode each custom parameter and value and include that encoded information in the request sent when the tag fires. The names can be anything you like and the values of the parameters can be strings, numbers, arrays or booleans. There is no strict limit on the number of parameters or the length of their name or values, provided that the length of the HTTP request does not exceed 2048 characters - details about checking if the request exceeds 2048 characters can be found in the verification section.

An example an of an imaginary online retail website's custom parameters that contain information about the current user's basket and loyalty information is show below:

<script type="text/javascript">
var google_tag_params = {
  basketProductIds: [125543, 423535, 145436], 
  totalBasketValue: 56.97,
  customerCategory: 'Silver',
  returnCustomer: true
};
</script>

When including numbers for purchase totals or product values, please do not include any currency symbols; additionally if your website operates with multiple currencies we suggest normalising all monetary values to a single currency to make things consistent and easy to work with, for example when generating rules that use the 'basket value' it is easier to use one currency, instead of multiple rules that use different currency values.

Each of the custom parameters which are used will appear within the AdWords interface for use when generating remarketing audiences where simple rules can be applied that operate on the values of the custom parameters. As well as custom parameters there are also a set of predefined parameters that can be used with advanced Google advertising products, for example dynamic product remarketing.

The AdWords Conversion Tag & the AdWords Remarketing Tag

Although both tags look similar, the AdWords Remarketing Tag complements the AdWords Conversion Tag and does not replace it - you still need to use a AdWords Conversion Tag to successfully record conversions on your site's conversion pages, and you should also include the AdWords Remarketing Tag on the conversion page as well to record the remarketing data as well as the conversion. You can read more about implementing the AdWords Conversion Tag at the AdWords Help site.

You can retrieve the details of your AdWords Conversion Tag from within AdWords by clicking the "Tools" tab and selecting "Conversions" from the menu. Once you are in your Conversions view you can select a conversion object (or create a new one), then select the "Code" tab and select the "I make changes to the code" option to reveal the AdWords Conversion Tag's code snippet which comes pre-filled with your account's google_conversion_id as well as any other options specified when the conversion was created.