简体   繁体   English

表单填写完毕后,添加事件监听器以触发Google adwords跟踪脚本

[英]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. 这样我就可以准确地跟踪用户来自何处,以完成我的表格。

Use a form with a hidden input field: 使用带有隐藏输入字段的表单:

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 ,这些值现在将被带到您的新页面。


Alternatively, you can use an eventListener: 另外,您可以使用eventListener:

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.

相关问题 仅当表单已更改时如何将事件侦听器添加到窗口 - How add event listener to window only if form has been changed Google Adwords转化跟踪活动 - 单页 - Google Adwords conversion Tracking event - single page 表单发送时的Google AdWords转化跟踪 - Google AdWords Conversion Tracking on a form send 在具有外部目标的表单上跟踪Google AdWords转化 - Tracking Google AdWords Conversion on a Form with an External Target 如何在点击按钮事件中添加Google AdWords转化跟踪代码? - How to add Google AdWords Conversion Tracking code in knockoutjs button click event? 事件没有新页之后的Google Adwords转化跟踪 - Google Adwords Conversion Tracking After Event No New Page 与表单的“提交”按钮配合使用的Google AdWords转化跟踪 - Conversion tracking for Google AdWords that works with a form's submit button 如何在drupal中将AdWords转化跟踪代码添加到特定表单 - how to add AdWords Conversion Tracking code to a specific form in drupal 将Google AdWords转化跟踪(javascript)代码添加到PrestaShop / Smarty页面中 - Add Google AdWords Conversion Tracking (javascript) code into a PrestaShop / Smarty page 无法使用自定义事件在脚本中触发事件侦听器 - Unable to trigger event listener in script with custom event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM