[英]Add event listener to trigger Google adwords tracking script once a form has been completed
Is there a way of creating a javascript event listener in a form, so that when a user completes that form, a trigger (event-listener) is created. 有没有一种在表单中创建javascript事件侦听器的方法,以便当用户完成该表单时,会创建触发器(事件侦听器)。
This trigger(event-listener) is then picked up by a separate HTML page which I have built and solely runs the google adwords tracking script. 然后,由我建立并单独运行google adwords跟踪脚本的单独的HTML页拾取此触发器(事件监听器)。
So that I am able to track exactly where the user has come from in order to complete my form. 这样我就可以准确地跟踪用户来自何处,以完成我的表格。
You can capture the current utm params from the URL, and use these in your <form>
in a hidden <input>
: 您可以从URL捕获当前的utm参数,并在<form>
中的隐藏<input>
:
Javascript: Javascript:
// Get the utm-params from the URL
// You can add some logic yourself to get only the utm-param(s) you need.
let utmParams = location.search;
// Set utmParams as the input value
document.getElementById("utm-values").value = utmParams;
HTML: HTML:
<input id="utm-values" type="hidden" value="" />
On submit
, these values will now be carried over to your new page. submit
,这些值现在将被带到您的新页面。
If you really need an event listener, than create your own submit button and script. 如果确实需要事件侦听器,则可以创建自己的提交按钮和脚本。
HTML: HTML:
<form id="myForm">
...
<button id="mySubmit">Submit</button>
</form>
Javascript: Javascript:
// Reference the form element
let form = document.getElementById("myForm");
// Submit the form through javascript
// Here you can add your own code, before the actual submitting
document.getElementById("mySubmit").addEventListener("click", function () {
form.submit();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.