Multiple Google Adwords conversion labels on same page
Solution 1
What worked for us was just including the entire block of code (including the <script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js"></script>
tag itself) twice. Because the script tag contains code which is executed immediately, including it twice will cause it to execute twice - each time using the variables declared immediately before it.
Solution 2
The Javascript function.
var goog_report = function(id, label, value){
if(typeof(value)==='undefined') value = 0;
var base_url = 'www.googleadservices.com/pagead/conversion/';
var img = new Image(1,1);
img.src = base_url + id +'/?label='+label+'&value='+ value +'&script=0';
};
Set your Google variables.
var goog_id = 1234;
var goog_label = 'xyz';
var goog_value = 10.99;
Example 1: Call within HTML.
<script>
goog_report(goog_id, goog_label, goog_value);
</script>
Example 2: Call within an event handler.
<script>
var handleSomeEvent = function(evt) {
goog_report(good_id, goog_label, goog_value);
};
</script>
Example 3: Call after jQuery Ajax success call.
<script>
$.ajax({
type: "POST",
url: "/charge/",
data: $('form').serialize(),
success: function(data) {
goog_report_purchase(goog_id, goog_label, data.charge_amount);
}
});
</script>
Example 4: Hard-coded OnClick event on Anchor Element
<a href="javascript:;" onclick="goog_report(1234, 'xyz', 10.99)">Boom! Conversion.</a>
Solution 3
Note that as of October 2017, you can (and should) use Google's new gtag.js, which is a new web tagging library that replaces the older AdWords website conversion tracking and remarketing tags.
gtag.js allows you to send tracking data to multiple AdWords accounts by adding a call to the ‘config’ command for every account you’ll be using, specifying each account’s conversion ID:
<!-- Global Site Tag (gtag.js) - Google AdWords: GOOGLE_CONVERSION_ID_1 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-GOOGLE_CONVERSION_ID_1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'AW-GOOGLE_CONVERSION_ID_1');
gtag('config', 'AW-GOOGLE_CONVERSION_ID_2');
</script>
This is the pattern that modern solutions should follow.
Hoppe
C#, TypeScript, Azure, JavaScript, Angular, TypeScript, SQL Server
Updated on June 15, 2022Comments
-
Hoppe almost 2 years
Can I have more than one google adwords conversion label on a single web page? It looks like the javascript variables would just overwrite each other.
What if I remove the javascript variables and just keep the noscript link?
conversion 1
var google_conversion_id = 123; var google_conversion_language = "en"; var google_conversion_format = "3"; var google_conversion_color = "666666"; var google_conversion_label = "abc"; var google_conversion_value = 0;
conversion 2:
var google_conversion_id = 456; var google_conversion_language = "en"; var google_conversion_format = "3"; var google_conversion_color = "000000"; var google_conversion_label = "def"; var google_conversion_value = 0;
followed by script tag:
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js"></script>
and sample noscript tags:
<div style="display:inline;"><img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/..."/> </div>
-
Nik Sumeiko about 10 yearsyou can omit
http:
protocol invar base_url
, so it doesn't cancel SSL for https pages.