Search
Clear search
Close search
Google apps
Main menu

Conversion tracking guide

Conversion tracking involves setting a cookie in a user's browser when they click or view an ad. If the user clicks your ad and reaches one of your conversion pages, their browser sends the cookie to a Google server, and a small conversion tracking image is displayed on your site. When such a match is made, Google records a successful conversion for you.

This information is presented within the "Campaigns," "Conversions," or "Reports" sections in your DoubleClick Ad Exchange account.

Conversions are only tracked for customers that are able to download images and that have cookies enabled for their web browsers. Although this is the default setting for most browsers, users who don't accept the conversion tracking cookies won't be included in your conversion statistics.

Because Ad Exchange buyers can set up campaigns for multiple advertisers in a single account, a conversion that results from one ad view or click might not always be attributed to the proper campaign. Talk to your account team before using conversion tracking.
Overview

Implementing conversion tracking is simple: place a few lines of code, referred to in this guide as a code snippet, on to your website. As a prerequisite, you or someone in your organization must place the conversion tracking code snippet. You'll also need to have access to your website's code and the Ad Exchange account that corresponds to the site.

This guide takes you through the code snippet insertion instructions. We recommend that you completely review these setup instructions prior to starting the installation. Additionally, this guide offers specific snippet insertion instructions for static and dynamically generated sites.

Once you've successfully installed your code snippet, you can access your conversion tracking reports from the "Campaigns" page, "Conversions" page, and "Reports" page. Note that conversion tracking stats show up in your reports an hour or more after the actual conversion takes place.

Conversion tracking allows great flexibility in setting up your tracking preferences. You can start tracking aggregate data immediately with the initial code snippet we provide; or you can take advantage of our tracking options to get more detailed conversion statistics.

If you don't have the knowledge to successfully implement our conversion tracking procedures, refer your webmaster or web developer to this guide, as the modification of the code snippet can result in malfunction of the snippet (including data loss or inaccurate data collection). Remember that site owners are solely responsible for the performance and maintenance of their website code.

Get the code snippet

When the code snippet is placed on the conversion page of your website, statistics on users who click an Ad Exchange ad and complete a conversion (purchase, sign-up, page view, or lead) can be collected and viewed in your reports. This data is tracked via the cookie placed on a user's computer.

To get the Google code snippet, visit the Tools and Analysis tab, and select Conversions from the drop-down. Place the code snippet on the conversion page(s) of your site to track conversions.

Purchase Conversion Default: Sample code snippet only - DO NOT USE

<!-- Google Code for Purchase Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = 1234567890;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "666666";
var google_conversion_label = "Purchase";
//-->
</script>
<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0
src="http://www.googleadservices.com/pagead/conversion/1234567890/?value=1&label=Purchas
e&script=0">
</noscript>

Advanced Option
Purchase Conversion, $5.00 value: Sample code snippet only - DO NOT USE
<!-- Google Code for Purchase Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = 1234567890;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "666666";
var google_conversion_label = "Purchase";
//-->
if (5.0) {
var google_conversion_value = 5.0;
}
</script>
<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0
src="http://www.googleadservices.com/pagead/conversion/1234567890/?value=5.0&label=Purch
ase&script=0">
</noscript>

Requirements

The requirements for installing conversion tracking on your website are:

  • Ad Exchange ads must be approved and running
  • Placement of the Google code snippet on the conversion page

For conversion tracking to properly track conversions from clicks on your ad, a user’s browser must permit the setting of cookies and be able to download images.

Insert the code snippet on to your website

To properly track a conversion, you should place the code snippet on your conversion page(s), as in Figure 1 below.

Figure 1: Copy-and-paste the code snippet

Placing the code snippet into your website code has no effect on your site unless a conversion takes place. If you opted to place the Site Stats text on your conversion page, you should see the text block appear. While it's possible to opt out of this feature, you should consider telling users that you are using the conversion tracking feature (e.g. through your privacy policy) in order to maintain their trust and privacy.

The code snippet should be placed between the <body> tags, closer to the </body> tag so that the image appears further down the page. You should NOT place the code in the header or footer of your page. This could overstate your conversion statistics and defeat the purpose of tracking.

Examples - Do NOT Use
Simple HTML document - no conversion tracking code
<html>
<head>
<title>Sample HTML File</title>
</head>
<body>
This is the body of your web page.
</body>
</html>

Simple HTML document with conversion tracking code
<html>
<head>
<title>Sample HTML File</title>
</head>
<body> This is the body of your web page.
<!-- Google Code for Purchase Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = 1234567890;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "666666";
var google_conversion_label = "Purchase";
//-->
if (1) {
var google_conversion_value = 1
}
</script>
<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0
src="http://www.googleadservices.com/pagead/conversion/1234567890/?value=1.0&label=Pur
chase&script=0">
</noscript>
</body>
</html>
Scenarios for inserting the code snippet

Your websites can use more than one technology to create and manage web pages.

Conversion tracking performs equally well on either a static or dynamically generated conversion page, provided the snippet is displayed in a page the user sees after a conversion.

Dynamically generated pages

The Google code snippet should be inserted into a static portion of the page. This may be done using an include statement if your web server offers server-side includes or by simply inserting the code snippet within the <body> section of the page.

This section provides examples for the following web programming languages:

  • Active Server Pages (ASP)
  • Sun® Java Server Pages (JSP)
  • PHP: Hypertext Preprocessor (PHP)

I. Conversion tracking & Active Server Pages (ASP)

Follow these instructions to insert the conversion tracking code to a website created using dynamically generated Active Server Pages (ASP).

To add conversion tracking code to ASP pages using your ASP editor:

<%= totalValue %>

Choose the Purchase/Sale conversion type while going through the conversion tracking setup. Insert the full string (<%= totalValue %>) into the Revenue for your action field and click OK when you see a prompt about using an unrecognized value. Copy and save the resulting code snippet.

  1. Open your conversion confirmation page ASP file. If multiple pages are generated from the same file, find the section in the ASP file that generates your conversion page.
  2. If your site has a variable conversion value, determine the ASP expression which calculates that value. For example:
  3. Insert the conversion tracking code onto the conversion confirmation page. Make sure that the code appears within a static HTML section, not contained within an ASP code section (delineated by <%= and %> markers).

    Insert the conversion tracking code directly into the body of the conversion confirmation page. Search for the </body> tag and place the code immediately above it. If the </body> tag is not located within the static portion of the HTML page, make sure the code snippet is added so it appears within the body section of the page.

    Example:
    <body>
    ...
    <!-- Google Code for Purchase Conversion Page -->
    <script language="JavaScript" type="text/javascript">
    <!--
    var google_conversion_id = 1234567890;
    var google_conversion_language = "en_US";
    var google_conversion_format = "1";
    var google_conversion_color = "666666";
    var google_conversion_label = "Purchase";
    //-->
    if (<%= totalValue %>) {
    var google_conversion_value = <%= totalValue %>;
    }
    </script>
    <script language="JavaScript"
    src="http://www.googleadservices.com/pagead/conversion.js">
    </script>
    <noscript>
    <img height=1 width=1 border=0
    src="http://www.googleadservices.com/pagead/conversion/1234567890/?value=<%=
    totalValue %>&label=Purchase&script=0">
    </noscript>
    </body>

    If your web server supports Server Side Includes (SSI) you can use an #include statement to insert the conversion tracking code onto your site. After you generate your conversion code snippet, save it to a file on your webserver - we recommend using the filename googleconversion.asp.

    Search for the </body> tag and place the #include statement with the location of the file directly above it. If the </body> tag is not located within the static portion of the HTML page, add the code snippet so it appears within the body section of the page.

    Example:

    <head>
    <title>Thank You for Shopping</title>
    </head>

    <body>
    ...
    <!-- #include file=".../googleconversion.html" -->
    </body>

    Don't place the #include statement in the footer or header of the file, as is sometimes common. Doing so causes Google to record a conversion every time a user visits any page on your site.

    The #include statement is evaluated before the rest of the of the ASP pages, so you are able to use an ASP expression as the dynamic value of the conversion.

  4. Save your conversion confirmation file and upload to your webserver if necessary. If you would like to test the placement of your conversion tracking code, go to your conversion page by completing a conversion on your site. View the source of the page (in Google Chrome, for example, select View/Developer/View Source). You should see the conversion tracking code between the <body> and </body> tags on your page. Note that the ASP expression will be replaced by the actual conversion value when you view the source.

II. Conversion tracking & Java Server Pages (JSP)

Follow these instructions to insert the conversion tracking code into a website created using dynamically generated Java Server Pages (JSP).

To add conversion tracking code to JSP pages using your JSP editor:

Insert the conversion tracking code directly into the body of the conversion confirmation page. Search for the </body> tag and place the code immediately above it. If the </body> tag is not located within the static portion of the HTML page, be sure you add the code snippet so within the body section of the page.

Example:

<!-- Google Code for Purchase Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = 1234567890;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "666666";
var google_conversion_label = "Purchase";
//-->
if (<%= totalValue %>) {
var google_conversion_value = <%= totalValue %>;
}
</script>
<script language="JavaScript"
src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0
src="http://www.googleadservices.com/pagead/conversion/1234567890/?value=<%=
totalValue %>&label=Purchase&script=0">
</noscript>
</body>

You can also insert the conversion tracking code onto your site using a server-side jsp:include statement. After you generate your conversion code snippet, save it to a file on your webserver - we recommend using the filename googleconversion.html. Search for the </body> tag and place the jsp:include statement with the location of the file directly above it. If the </body> tag is not located within the static portion of the HTML page, make sure that you add the code snippet so that it appears within the <body> section of the page.

Example:

<html>
<head>
<title>Thank You for Shopping</title>
</head>
<body>
...
<jsp:include src=".../googleconversion.html"/>
</body>
</html>

 
Don't place the jsp:include statement in the footer or header of the file, as is sometimes common. This causes Google to record a conversion every time a user visits any page on your site.

The jsp:include statement will be evaluated before the rest of the of the JSP pages so you are able to use a JSP expression as the dynamic value of the conversion.

If your web server supports Server Side Includes (SSI) you can use an #include statement to insert the conversion tracking code onto your site. After you generate your conversion code snippet, save it to a file on your webserver - we recommend using the filename googleconversion.html. Search for the </body> tag and place the #include statement with the location of the file directly above it. If the </body> tag is not located within the static portion of the HTML page, make sure that you add the code snippet so that it appears within the <body> section of the page.

Example:

<head>
<title>Thank You for Shopping</title>
</head>
<body>
...
#include file=".../googleconversion.html"
</body>

 
Don't place the #include statement in the footer or header of the file, as is sometimes common. This will cause Google to record a conversion every time a user visits any page on your site.
  1. Open your conversion confirmation page JSP file. If multiple pages are generated from the same file, find the section in the JSP file which generates your conversion page.
  2. If your site has a variable conversion value, determine the JSP expression which calculates that value. For example: <%= totalValue %>, ${totalValue}
  3. Choose the Purchase/Sale conversion type while going through the conversion tracking setup. Insert the full string (<%= totalValue %>) into the Revenue for your action field, and click Save Changes & Get Code to generate the final tracking code. Click OK when you're prompted about using an unrecognized value. Copy and save the resulting code snippet .
  4. Insert the conversion tracking code snippet onto the conversion confirmation page. Make sure that the code appears within a static HTML section, not contained within an JSP code section (delineated by <%@ and %> markers).
  5. The #include statement will be evaluated before the rest of the of the JSP pages so you are able to use a JSP expression as the dynamic value of the conversion.
  6. Save your conversion confirmation file and upload to your webserver if necessary. If you would like to test the placement of your conversion tracking code, go to your conversion page by completing a conversion on your site. View the source of the page. You should see the conversion tracking code between the <body> and </body> tags on your page. Note that the JSP expression will be replaced by the actual conversion value when you view the source.

III. Conversion tracking & Hypertext Preprocessor (PHP)

Follow these instructions to insert the conversion tracking code to a website created using dynamically-generated PHP: Hypertext Preprocessor (PHP) pages.

To add conversion tracking code to PHP pages using your web page editor:

  1. Open your conversion confirmation page PHP file. If multiple pages are generated from the same file, find the section in the PHP file which generates your conversion page.
  2. If your site has a variable conversion value, determine the PHP expression that displays that value. For example: <?php echo $totalValue ?>, <? echo totalValue ?>

    Choose the Purchase/Sale conversion type while going through the conversion tracking setup. Insert the full string (<? echo $totalValue ?>) into the Revenue for your action field and click Save Changes & Get Code to generate the final tracking code. Click OK when you're prompted about using an unrecognized value. Copy and save the resulting code snippet .

  3. Insert the conversion tracking code onto the conversion confirmation page. Make sure that the code appears within a static HTML section, not contained within an PHP code section (delineated by <? and ?> markers).
  4. Insert the conversion tracking code snippet directly into the body of the conversion confirmation page. Search for the </body> tag and place the code immediately above it. If the </body> tag is not located within the static portion of the HTML page, make sure that you add the code snippet so that it appears within the <body> section of the page.
    Example:

    <!-- Google Code for Purchase Conversion Page -->
    <script language="JavaScript" type="text/javascript">
    <!--
    var google_conversion_id = 1234567890;
    var google_conversion_language = "en_US";
    var google_conversion_format = "1";
    var google_conversion_color = "666666";
    var google_conversion_label = "Purchase";
    //-->
    if (<? echo $totalValue ?>) {
    var google_conversion_value = <? echo $totalValue ?>
    }
    </script>
    <script language="JavaScript"
    src="http://www.googleadservices.com/pagead/conversion.js">
    </script>
    <noscript>
    <img height=1 width=1 border=0
    src="http://www.googleadservices.com/pagead/conversion/1234567890/?value=<? echo
    $totalValue ?>&label=Purchase&script=0">
    </noscript>
    </body>

  5. Save your conversion confirmation file and upload to your web server if necessary. If you would like to test the placement of your conversion tracking code, go to your conversion page by completing a conversion on your site. View the source of the page (in Internet Explorer choose View > View Source). You should see the conversion tracking code between the <body> and </body> tags on your page. Note that the PHP expression will be replaced by the actual conversion value when you view the source.

Web pages containing frames
In cases where frames are used, we recommend inserting the code snippet only within the HTML of the frame containing the conversion page.

Secure and non-secure pages
The code snippet can be used safely on both secure (security level is https://) and non-secure pages (security level is http://). You'll be asked to select the security level of your pages when signing up, to ensure the code snippet uses the correct protocol (https:// or http://) on your conversion pages.

How to confirm the conversion tracking code snippet

You can verify if the code is working by waiting for a conversion to occur or completing a test conversion yourself. If you know that a conversion has occurred on your site from an Ad Exchange ad, check the conversion column in your reports to see that the conversion registered. Please note that updates to your account reports take up to 24 hours.

You can also run through the process yourself by searching on Google, clicking one of your ads, and completing a conversion on your site. However, keep in mind that this method costs you an ad click, so we recommend waiting for a conversion to occur on its own.

If you opted in to place the Site Stats text block on your conversion page, you should see the text appear. While it is possible to opt out of this feature, you may want to consider telling users that you are using the free conversion tracking feature (e.g. through your privacy policy) in order to maintain their trust and privacy.

HTML editors

Please follow the basic instructions and apply them to the editors you use.

Advanced tracking options

Tracking options

When using conversion tracking, you can categorize different actions by applying labels when you define an action.

Learn more about the different conversion tracking options.

Google Analytics and conversion tracking

Ad Exchange advertisers can link their accounts to Google Analytics. With your free Google Analytics account, you can collect and analyze data about how visitors engage with your content, so you can monitor and find ways to improve the performance of your campaigns. The Google Analytics tracking code will not interfere with the conversion tracking code if you use them at the same time on your site.

To begin learning about Google Analytics, visit our Google Analytics Help Center.

To sign up for Google Analytics, please visit the Google Analytics homepage at http://www.google.com/analytics/.

Was this article helpful?