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.
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.
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>
:
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:
<input id="utm-values" type="hidden" value="" />
On submit
, these values will now be carried over to your new page.
If you really need an event listener, than create your own submit button and script.
HTML:
<form id="myForm">
...
<button id="mySubmit">Submit</button>
</form>
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();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.