I built a new site using Divi in WP. The previous HTML site had used an onclick event and also included the following script immediately following the opening tag. The digital marketing team informed me that after the move to WP, they no longer were receiving any data. I am trying to figure out where I have gone wrong as I am newer to WP. Any suggestions?
the onclick itself:
<a onclick="goog_report_conversion ('javascript:document.searchform.submit();')"
href="javascript:document.searchform.submit();" class="btn_reserve">Reserve Now!</a>
the JS:
<!-- Google Code for Reserve Now -->
<script type="text/javascript">
/* <![CDATA[ */
goog_snippet_vars = function() {
var w = window;
w.google_conversion_id = 973012345;
w.google_conversion_label = "iNr5DMy-uHsQbyT-zwM";
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="//www.googleadservices/pagead/conversion_async.js">
</script>
I built a new site using Divi in WP. The previous HTML site had used an onclick event and also included the following script immediately following the opening tag. The digital marketing team informed me that after the move to WP, they no longer were receiving any data. I am trying to figure out where I have gone wrong as I am newer to WP. Any suggestions?
the onclick itself:
<a onclick="goog_report_conversion ('javascript:document.searchform.submit();')"
href="javascript:document.searchform.submit();" class="btn_reserve">Reserve Now!</a>
the JS:
<!-- Google Code for Reserve Now -->
<script type="text/javascript">
/* <![CDATA[ */
goog_snippet_vars = function() {
var w = window;
w.google_conversion_id = 973012345;
w.google_conversion_label = "iNr5DMy-uHsQbyT-zwM";
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="//www.googleadservices.com/pagead/conversion_async.js">
</script>
I would try separating the html from the javascript. i.e. not using "onclick" in html but instead using addEventListener.
<a href="javascript:document.searchform.submit();" class="btn_reserve">Reserve Now!</a>
<script>
document.querySelector('.btn_reserve').addEventListener("click", function(e) {
// it seems like this line won't return a URL and will instead submit the form.
// I would double check it.
var url = document.searchform.submit();
goog_report_conversion(url);
});
</script>