在 Google Analytics 中跟踪 POST 内容的表单成功完成情况
我们有一个客户无法将表单从 POST 切换为 GET,目前我们正在通过与“提交”按钮相关的事件来跟踪表单提交。
但是,这会跟踪“已完成”的表单,即单击“提交”但可能会返回带有错误的表单。
通常,我要么对表单进行 AJAX 化并阻止提交表单,直到 JS 验证完成,要么使用唯一的“表单完成”URL 并跟踪作为目标(以及 DOM 加载 JS 触发事件跟踪的事件),但在这种情况下这不是一个选择。
在这种情况下,如何将事件与“表单成功”内容联系起来?我知道我可以将事件与图像加载相关联,但我需要动态生成图像名称以防止缓存影响分析。
我可以将事件与 POST 中的文本牢固地联系起来吗?
We have a client unable to switch a form from POST to GET, at the moment we're tracking form submissions via an event tied to the 'Submit' button.
However, this tracks as a 'completed' form, someone who clicks submit but who might get the form returned with errors.
Normally I'd either AJAXify the form and prevent submission of the form until JS validation is complete, or alternatively use an unique 'Form Complete' URL and track as a goal (and an event with on DOM load JS triggering the event tracking), but that's not an option in this case.
How can I tie an event to the 'form success' content in this scenario? I know I can tie an event to an image load, but I'd need to dynamically generate the image name to prevent caching affecting the analytics.
Can I tie an event to text that's in POST robustly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在服务器端验证表单后,您可以简单地输出 JavaScript 以及下一个响应,告诉 Google Analytics 跟踪提交事件。
编辑:我刚刚注意到你说这不是一个选项。
Once you validate the form on the server-side, you can simply output JavaScript along with the next response that tells Google Analytics to track the submission event.
Edit: I just noticed that you said this isn't an option.
您能否输出一个隐藏字段,其中包含一个表示表单已成功提交的值,然后使用 jQuery 监视该字段以返回成功值?然后javascript重定向到另一个页面?
因此,在文档准备就绪时,请执行以下操作:
jQuery
或者,只需让 jQuery 监视页面内容中的某些成功指示符(例如“谢谢”或其他短语),然后进行重定向。
Could you output a hidden field that contains a value meaning that the form was successfully submitted, and then use jQuery watch for that field to come back with a success value? Then javascript a redirect to another page?
So on document ready do this:
jQuery
Alternatively, just have jQuery watch for some success indicator (like "thank you" or another phrase) in the page content and then redirect.
您还可以根据 JavaScript 事件有条件地调用 Google Analytics 跟踪器代码。 查看这篇文章
包含此 JavaScript仅当表单提交成功时才在您的页面上,或者使用我的其他 awnser 中的示例使用 jQuery 调用它:
页面不会重定向,但 Analytics 会记录它,就像用户实际访问该页面一样。
You can also conditionally invoke the Google Analytics tracker code based on javascript events. See this article
Include this javascript on your page only when the form submit is successful or call it with jQuery using the example in my other awnser:
the page will not get redirected but Analytics will record it as if the user actually visited that page.