Reputation: 201
I have 12 snippets of the same below, and they all need to be on the same page. I have amended them so they are goog_report_conversion_a, goog_report_conversion_b and so on. This causes the tags to be unverified however - is this the correct way of adding multiple snippets to one page?
<script type="text/javascript">
/* <![CDATA[ */
goog_snippet_vars_a = function() {
var w = window;
w.google_conversion_id = XXXXXXXXX;
w.google_conversion_label = "XXX1";
w.google_remarketing_only = false;
}
// DO NOT CHANGE THE CODE BELOW.
goog_report_conversion_a = function(url) {
goog_snippet_vars_a();
window.google_conversion_format = "3";
window.google_is_call = true;
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 type="text/javascript"
src="//www.googleadservices.com/pagead/conversion_async.js">
</script>
//Example click events below
<a onClick="goog_report_conversion_a()" href="/">Click Event</a>
<a onClick="goog_report_conversion_b()" href="/">Click Event</a>
Upvotes: 2
Views: 2802
Reputation: 1171
Yes you can do it that way even though Google can't verify it (because of the alterations in the code).
However there is a lot of duplication in your code because you will have to copy all those huge chunks one time for each button (12 times in total in your case).
I would suggest using a wrapper function taking the google_conversion_id
and google_conversion_label
as parameters.
<script type="text/javascript">
/* <![CDATA[ */
goog_conv_custom = function(conversion_id, conversion_label, url) {
var w = window;
w.google_conversion_id = conversion_id;
w.google_conversion_label = conversion_label;
w.google_remarketing_only = false;
goog_report_conversion(url);
}
// DO NOT CHANGE THE CODE BELOW.
goog_report_conversion = function(url) {
window.google_conversion_format = "3";
window.google_is_call = true;
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="//www.googleadservices.com/pagead/conversion_async.js">
</script>
//Example click events below
<a onClick="goog_conv_custom('conversion_id_a', 'conversion_label_a')" href="/">Click Event</a>
<a onClick="goog_conv_custom('conversion_id_b', 'conversion_label_b')" href="/">Click Event</a>
Upvotes: 4