[英]Track Form Submissions with Google Analytics 4 to register conversions
我需要使用 Google Analytics 跟踪表单的提交。
在我的网站上,我已经有了 Google Analytics (GA4) o 跟踪页面浏览量:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-XXXX');
</script>
包含表单的页面的 url 是/contact
但可能是:
/contact?topic=inquiry&utm_source=google&utm_campaign=xyzzy&utm_id=12
表格的简化版本是:
<form x-data="send_message()" method="post">
<label>Email</label>
<input type="text" name="email">
<button class="action" type="submit">Send</button>
</form>
提交表单时, submit
方法运行:
export default function send_message() {
submit() {
fetch("/messages", {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(body)
})
.then((response) => {
if (response.ok) {
// Show success message
} else {
// Show error message
}
})
}
};
如何跟踪表单提交并使用UTM
或Topic
参数以便衡量转化?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.