如何在没有单独感谢页面的情况下设置联系表单的 Google Analytics 目标跟踪?
如何设置 Google Analytics(分析)来跟踪已提交联系表单且没有单独的致谢网址的网站访问者?
我已经看到了博客和 GA 帮助论坛上发布的代码,但到目前为止,我还没有想到如何实际设置目标以插入代码片段。
在论坛等上找到的代码:
onsubmit="pageTracker._trackPageview('/Goa1-Button'); pageTracker._trackEvent('Goals','CLick-Button');"
具体来说,我想知道以下内容:
- 我将使用什么目标类型?
- 如果我将活动命名为“联系表单完成”,它会放在哪里并适合上面的代码?
- 上面的代码正确吗?它对我有帮助吗?
还有其他建议吗?以前有人曾经这样做过吗?
How do I set Google Analytics up to track visitors to my website who have submitted a contact form, that doesn't have a separate thank-you url?
Ive seen the code posted around blogs and GA help forums but so far have yet to come across how would I actually set the goal up in order to insert the snippet of code.
Code found on forums and such:
onsubmit="pageTracker._trackPageview('/Goa1-Button'); pageTracker._trackEvent('Goals','CLick-Button');"
Specifically, I would like to know things such as:
- What goal type would I use?
- If i named the campaign Contact form completions, where would it go and fit in to the code above?
- Is the code above right and will it help me?
Any other advice, any one ever had to do this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,从您在 yahelc 答案的评论中发布的 URL 来看,您有一个通过 AJAX 提交并返回响应的表单。
另外,您的页面上 GA 代码是异步版本,但您问题中的代码是传统的,因此您需要使用异步语法。
在您的页面上,如果访问者未填写某些内容,则相关区域将以红色突出显示(旁注:如果我不填写,我不会看到“您需要填写此内容”或“这是正确的格式”消息表格正确......你应该考虑添加......)。
您需要确保的主要事情是,只有当访问者成功填写表单时,您才会弹出“成功”代码。因此,您实际上并不希望将 GA 代码附加到 onsubmit,因为这可能会产生误报。每当访问者单击提交按钮时,无论他们是否成功填写了表单,它都会触发。
所以看起来处理表单验证的 javascript 位于 /custom.js 中,并且在 custom.js viewsource 的第 163 行上有以下内容:
这看起来是在表单完成后显示“谢谢”消息的地方已验证并提交,因此您应该将 GA“成功”代码放置在此函数中的某个位置。
您要插入的代码应如下所示(基于您问题中的代码):
注意:对于事件跟踪,这会将事件类别设置为“目标”,将事件操作设置为“单击按钮”。您还可以将其他可选参数传递给 _trackEvent 以进一步了解粒度。如需了解更多详情,请参阅 GA 的事件跟踪器指南。
至于目标跟踪,正如 yahelc 提到的,这是在界面中设置的。上面的代码将发送一个页面名称为“/Goa1-Button”的虚拟页面视图,您将使用该值来设置您的目标。您可以通过多种方式设定目标。您可以使其与该值完全匹配,或者如果您预计稍后会添加 URL 参数等,则可以从该值开始(但还要注意,您目前无法根据事件创建目标...这很蹩脚,但我听说 GA 正在努力最终实现这一目标)。
编辑:显然,如果您使用“新版本”,您实际上可以根据事件设定目标,正如 yahelc 在他的回答评论中提到的那样。好的!
So it looks like from the URL you posted in a comment on yahelc's answer, that you have a form that submits and gives back a response via AJAX.
Also, your on-page GA code is the async version, but the code you have in your question is the traditional, so you need to use the async syntax.
On your page, if the visitor does not fill something out, the area in question gets highlighted in red (sidenote: I see no "you need to fill this out" or "this is the correct format" messages if I do not fill out the form correctly..you should look into adding that...).
The main thing you need to make sure is that you only pop the 'success' code if the visitor successfully fills out the form. So you don't really want to attach the GA code to the onsubmit because this can produce false positives..it will trigger whenever the visitor clicks the submit button, regardless of whether or not they successfully filled out the form.
So it looks like the javascript that handles form validation is in your /custom.js, and you have on line 163 of custom.js viewsource the following:
This looks to be where the "thank you" message is displayed, after the form has been validated and submitted, so you should put your GA "success" code somewhere in this function.
The code you will want to insert should look something like this (based on the code in your question):
NOTE: For the event tracking, this will set the event category to "Goals" and the event action to "CLick-Button". There are other optional arguments you can pass to the _trackEvent for further granularity. Refer to GA's event tracker guide for more details.
As for the goal tracking, as yahelc mentioned, this is setup within the interface. The code above will send a virtual page view with a page name of "/Goa1-Button" and you will use this value in setting up your goal. There are a lot of ways you can set it up the goal. You can make it exactly match that value or start with that value if you anticipate URL params being added to it later, etc...(but also note, you cannot currently create goals based on events...which is lame, but I hear GA is working on making that happen eventually).
edit: Apparently you actually can set goals based on events, if you use the "New Version", as mentioned by yahelc in his answer comments. Nice!
目标是在 Google Analytics 界面中配置的,并且不追溯应用。
您应该查看如何设置目标和渠道?
您可以指定特定页面、事件或网站停留时间作为您的目标。
至于如何配置跟踪表单提交的代码,需要更多信息(即代码示例)来帮助您。但是,最重要的是:它是 AJAX 表单,还是仅发布到同一 URL 的常规表单?您使用的是异步语法还是传统的 Google Analytics 语法?
编辑:
根据您刚刚发布的表单,它看起来像是一个返回 HTML 正文的 AJAX POST。
因此,您需要做的就是将“目标”代码添加到该标记中,例如:
Goals are configured from within the Google Analytics interface, and do not apply retroactively.
You should check out How do I set up goals and funnels?
You can specify a specific page, event or amount of time on site as your goal.
As far as how to configure the code that will track submission of your form, that requires more information (i.e. code samples) to help you with. But, most importantly: Is it an AJAX form, or a regular form that just posts to the same URL? Are you using async or traditional Google Analytics syntax?
EDIT:
Based on the form you just posted, it looks like its an AJAX POST that returns an HTML body.
So, all you need to do is add your "goal" code into that markup, something like: