[英]Tracking Submitted Form Values with Google Tag Manager and Google Analytics
I am using Google Tag Manager to handle Google Analytics. 我正在使用Google跟踪代码管理器来处理Google Analytics(分析)。 There is a form on my website that has a submit button which I've successfully set up a click listener for through Google Tag Manager. 我的网站上有一个带有提交按钮的表单,我已经通过Google跟踪代码管理器成功设置了一个点击侦听器。
With this click listener I would like to track what input values where present in the form at the time the click listener fires, then be able to sort events in Google Analytics based on these values. 借助此点击侦听器,我想跟踪点击侦听器触发时表单中存在的输入值,然后能够根据这些值对Google Analytics(分析)中的事件进行排序。 I've looked into Google Analytics Dimensions and Metrics but these don't seem to be able to store form values the way I would like them to. 我研究了Google Analytics(分析)维度和指标,但是这些似乎无法以我希望的方式存储表单值。
Does anyone know the best way to go about this? 有谁知道最好的方法吗? I think I might be having trouble understanding what Dimensions and Metrics are really supposed to be used for... Is there some other Google Analytics tool that would accomplish more easily? 我想我可能很难理解什么维度和指标应真正用于......是否还有其他一些Google Analytics(分析)工具可以更轻松地完成?
Take a look at this discussion on Google Tag Manager Community. 查看有关Google跟踪代码管理器社区的讨论 。
Here is the just of it: 这是正义的:
Assuming you're using auto events: 假设您正在使用自动事件:
function() { // Assuming that {{element}} is the form you want. // This should be the case if you're using Auto Events. var form = {{element}}; // Assuming there's only one <select> in the form. var select = form.getElementsByTagName('select')[0]; var results = []; for (var i=0; i<select.options.length; i++) { // Assuming you want the value attributes of the selected. // You could also use .text here instead of .value. if (select.options[i].selected) results.push(select.options[i].value); } // Assuming you want an array of the selected values. // If you want a CSV string, return results.join() instead. return results; }
All this code was written by Brian Kuhn via the Google Plus post I reference above. 所有这些代码都是Brian Kuhn通过我在上面引用的Google Plus帖子编写的。 Not trying to take credit. 不试图获得荣誉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.