我想在Contact form 7 Plugin中集成Google转换代码。我已经设置了一切。 但是在表单提交时会收到错误。
未捕获的ReferenceError:未定义ga
at eval (eval at <anonymous> (scripts.js?ver=4.8:256), <anonymous>:1:1)
at String.<anonymous> (scripts.js?ver=4.8:256)
at Function.each (jquery.min.js:2)
at ajaxSuccess (scripts.js?ver=4.8:256)
at Object.<anonymous> (scripts.js?ver=4.8:324)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at A (jquery.min.js:4)
at XMLHttpRequest.<anonymous> (jquery.min.js:4)
联系表格7其他设置如下
答案 0 :(得分:2)
使用on_sent_ok: "typeof goog_report_conversion === 'function' && goog_report_conversion();"
并将Google Adword转换代码放在表单底部。
答案 1 :(得分:0)
on_sent_ok
和on_submit
已被弃用,并计划在2017年底之前废除。
您可以使用DOM
- 事件代替这些设置。
您可以使用此功能
<script type="text/javascript">
document.addEventListener('wpcf7mailsent', function( event ) {
var img = document.createElement("img");
var goalId = "868xxxxxx"; // Your Google Conversion ID
var randomNum = new Date().getMilliseconds();
var value = 0;
var label = "WoZxxxxxxxxxx"; // Your Google Conversion Label
var url = encodeURI(location.href);
var trackUrl = "http://www.googleadservices.com/pagead/conversion/"+goalId+"/?random="+randomNum+"&value="+value+"&label="+label+"&guid=ON&script=0&url="+url;
img.src = trackUrl;
document.body.appendChild(img);
}, false );
</script>