You can use conversion tracking to track when someone clicks a button or link on your website. For example, you can track when someone clicks a “Buy now” button, or when someone clicks a phone number on your mobile website.
This article explains how to add and edit a conversion tracking tag to track customer clicks on your website. To track a conversion on a page load instead, follow these instructions.
Before you begin
Before you can add a conversion tracking tag to your website, you’ll need to:
- Make sure this kind of conversion tracking is right for you.
- Have the ability to edit your website. Either you or your web developer will need to be able to add the tag to your website code.
Instructions
Choose the version of the conversion tracking tag you're using. You can get sitewide tag snippets from Google Ads only. We recommend you migrate to this new version. Tags from the previous version of Google Ads will still function.
Set up conversion tracking using the Google tag
- Track clicks on your website by creating a conversion action.
- For desktop sites, Set up conversion tracking for your website.
- For mobile sites, Track phone number clicks on a mobile website.
When setting up the tag, choose the Click option instead of Page load. The event snippet will look like this:
<script> function gtag_report_conversion(url) { var callback = function () { if (typeof(url) != 'undefined') { window.location = url; } }; gtag('event', 'conversion', { 'send_to': 'TAG_ID/CONVERSION_LABEL', 'value': 1.0, 'currency': 'USD', 'event_callback': callback }); return false; } </script>
Note: You may disable the collection of remarketing data for users who do not wish to view personalized ads. Learn more About the Google tag.
- On your website, open the HTML for the page with the button or link that you want to track. Insert the event snippet between the
head
tags (<head></head>
) of your page, right after the Google tag. - You'll now need to add an onclick attribute directly to the code for the button or link you want to track. The particular code you use will depend on how the link or button is displayed on your site: as a text link, a button, or a button image.
- Add the code to a text link: This code shows you how to add click tracking functionality to a link using the
<a>
tag. In the code below, replace “http://example.com/your-link” with the destination URL of your link or “800-123-4567” with the phone number on your website, and replace “Download now!” or "Call now!" with your link text. The code that should be added to the link tag is highlighted in yellow.<a onclick="return gtag_report_conversion('http://example.com/your-link');" href="http://example.com/your-link">Download now!</a>
or
<a onclick="return gtag_report_conversion('tel:800-123-4567');" href="tel:800-123-4567">Call now!</a>
- Add the code to a button: This code shows you how to add click tracking functionality to a button using the <button> tag. In the code below, replace “http://example.com/your-link” with the destination URL of your link or “800-123-4567” with the phone number on your website.
<button onclick="return gtag_report_conversion('http://example.com/your-link')">Submit</button>
or
<button onclick="return gtag_report_conversion('tel:800-123-4567')">Call now!</button>
- Add the code to a button image: In the code below, replace “download_button.gif” with your button image, replace the width and height with your button’s parameters, and replace “http://example.com/your-link” with the URL for your link or “800-123-4567” with the phone number on your website.
<img src="download_button.gif" alt="Download Whitepaper" width="32" height="32" onclick="return gtag_report_conversion('http://example.com/your-link')" />
or
<img src="call_button.gif" alt="Call now!"
width="32" height="32"
onclick="return gtag_report_conversion('tel:800-123-4567')" />
For conversion tracking to work, you'll need to add both the event snippet and the appropriate onclick code from one of the examples above to the page that has the link or button. This tells Google Ads to record a conversion only when a customer clicks on the link or button.
Important
Your website must call the gtag_report_conversion function when someone clicks on the link, button, or button image and pass your website or telephone link (examples: ‘http://example.com/your-link’, ‘tel:800-123-4567’) as the parameter value.
Check your Google tag
If you want to make sure your conversion tracking tag is installed and tracking conversions correctly, or you think there may be a problem with the tag:
- Review the instructions for checking your conversion tracking tag.
- Download Google Tag Assistant for Google Chrome to troubleshoot issues with your conversion tracking tag.
Set up conversion tracking using JavaScript
Follow these steps to track conversions based on clicks on your website or mobile website.
- Once you’ve set up your conversion action, your conversion tag should look something like this:
<!-- Google Code for Add to Cart Conversion Page In your html page, add the snippet and call
goog_report_conversion
when someone clicks on the chosen link or button. --><script type="text/javascript"> /* <![CDATA[ */ goog_snippet_vars = function() { var w = window; w.google_conversion_id = 12345678; w.google_conversion_label = "abcDeFGHIJklmN0PQ"; w.google_conversion_value = 13.00; w.google_conversion_currency = "USD"; w.google_remarketing_only = false; }
// DO NOT CHANGE THE CODE BELOW.goog_report_conversion = function(url) { goog_snippet_vars(); window.google_conversion_format = "3"; var opt = new Object(); opt.onload_callback = function() { if (typeof(url) != 'undefined') { window.location = url; } } var conv_handler = window['google_trackConversion']; if (typeof(conv_handler) == 'function') { conv_handler(opt); } } /* ]]> */ </script> <script type="text/javascript" src="//googleadservices.com/pagead/conversion_async.js"> </script>
Note: You may disable the collection of your data for users who do not wish to view personalized ads. Learn how to disable the collection of personalized data for specific users - On your website, open the HTML for the page with the button or link that you want to track.
- Between the body tags (
<body></body>
) of the page, paste the conversion tracking tag. - You'll now need to add an on click command directly to the code for the button or link you want to track. The particular code you use will depend on how the link or button is displayed on your site: as a text link, image, or button:
- Add the code to a text link: In the code below, replace “http://example.com/your-link” with the URL for your website or telephone link, and replace “Download now!” with your link text.
<a onclick="goog_report_conversion ('http://example.com/your-link')" href="http://example.com/your-link">Download now!</a>
Or:<a onclick="goog_report_conversion ('tel:800-123-4567')" href="#">Call now!</a>
- Add the code to a button: In the code below, replace “http://example.com/your-link” with the URL for your website or telephone link, and replace “Download now!” with your button text.
<button onclick="goog_report_conversion('http://example.com/your-link')" href="http://example.com/your-link">Download now!</button>
Or:<button onclick="goog_report_conversion('tel:800-123-4567')">Call 800-123-4567</button>
- Add the code to an image: In the code below, replace “download_button.gif” with your button image, replace the width and height with your button’s parameters, and replace “http://example.com/your-link” with the URL for your link.
<img src="download_button.gif" alt="Download Whitepaper" width="32" height="32" onClick="goog_report_conversion ('http://example.com/your-link')"/>
Or:<img src="my_phone_button.gif" alt="Call: 800-123-4567" width="32" height="32" onClick="goog_report_conversion('tel:800-123-4567')"/>
- Add the code to a text link: In the code below, replace “http://example.com/your-link” with the URL for your website or telephone link, and replace “Download now!” with your link text.
For the tracking to work, you'll need to include both the conversion tracking tag and the appropriate onclick
code from one of the examples above. This tells Google Ads to record a conversion only when a customer clicks on a chosen link or button.
Check your conversion tag
If you want to make sure your conversion tracking tag is installed and tracking conversions correctly, or you think there may be a problem with the tag:
- Review the instructions for checking your conversion tracking tag.
- Download Google Tag Assistant for Google Chrome to troubleshoot issues with your conversion tracking tag.