joaopeixoto
posted this
01 October 2023
First, create a conversion action (Learn more about how to Set up conversion tracking for your website.) if tracking clicks for a desktop site or Track clicks on a phone number on your mobile website, (if tracking clicks for a mobile site). When you reach the part about setting up the tag, make sure that you select the Click option, instead of Page load. The event snippet will look like this:
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;
}
This I done where you said.
but there are more steps....
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 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.
Download now!
or
Call now!
Add the code to a button: This code shows you how to add click tracking functionality to a button using the 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.
Submit
or
Call now!
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 alt width height>
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.
First, create a conversion action (Learn more about how to Set up conversion tracking for your website.) if tracking clicks for a desktop site or Track clicks on a phone number on your mobile website, (if tracking clicks for a mobile site). When you reach the part about setting up the tag, make sure that you select the Click option, instead of Page load. The event snippet will look like this:
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;
}
This I done where you said.
but there are more steps....
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 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.
Download now!
or
Call now!
Add the code to a button: This code shows you how to add click tracking functionality to a button using the 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.
Submit
or
Call now!
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 alt width height>
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.