简体   繁体   English

如何在没有单独的感谢页面的情况下设置联系表单的Google Analytics(分析)目标跟踪?

[英]How to set up Google Analytics goal tracking of a contact form with no separate thank you page?

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? 如何设置Google Analytics(分析)以跟踪提交了联系表格但没有单独的感谢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. 我见过在博客和GA帮助论坛上发布的代码,但到目前为止,我还没有真正想到要如何设置目标以插入代码段。

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? 还有其他建议吗,以前有人曾经这样做吗?

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. 因此,从您在yahelc答案的评论中张贴的URL看来,您有一个表单提交并通过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. 另外,您的页面上GA代码是异步版本,但是您遇到的问题中的代码是传统代码,因此您需要使用异步语法。

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. 因此,您实际上并不希望将GA代码附加到onsubmit上,因为这会产生误报。无论访问者是否成功填写了表单,只要访客单击“提交”按钮,它都会触发。

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: 因此,看起来好像处理表单验证的javascript在/custom.js中,并且在custom.js viewsource的第163行中包含以下内容:

success: function(response){

                           jQuery(".ajax_form").before("<div class='ajaxresponse' style='display: none;'></div>");

                           jQuery(".ajaxresponse").html(response).slideDown(400);

                           jQuery(".ajax_form #send").fadeIn(400);

                           jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").val("");

                               }

                            });

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. 验证并提交表单后,这似乎是显示“谢谢”消息的位置,因此您应该将GA“成功”代码放在此函数中的某个位置。

The code you will want to insert should look something like this (based on the code in your question): 您将要插入的代码应如下所示(基于您问题中的代码):

_gaq.push(['_trackEvent', 'Goals', 'CLick-Button']);
_gaq.push(['_trackPageview','/Goa1-Button']);

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. 您可以将其他可选参数传递给_trackEvent以获得进一步的粒度。 Refer to GA's event tracker guide for more details. 有关更多详细信息,请参阅GA的事件跟踪器指南

As for the goal tracking, as yahelc mentioned, this is setup within the interface. 至于目标跟踪,正如yahelc所述,这是在界面中设置的。 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. 上面的代码将发送一个虚拟页面视图,页面名称为“ / Goa1-Button”,您将在设置目标时使用此值。 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). 如果您希望稍后再添加URL参数,则可以使其完全匹配该值,也可以从该值开始,以此类推...(但也要注意,您当前无法基于事件创建目标...这很la脚,但是我听说GA正在努力最终实现这一目标)。

edit: Apparently you actually can set goals based on events, if you use the "New Version", as mentioned by yahelc in his answer comments. 编辑:显然,您实际上可以根据事件设置目标,如果您使用的是“新版本”,正如yahelc在他的回答评论中提到的那样。 Nice! 真好!

Goals are configured from within the Google Analytics interface, and do not apply retroactively. 目标是在Google Analytics(分析)界面中配置的,不会追溯地应用。

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 (ie 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? 但是,最重要的是:它是AJAX表单还是仅发布到同一URL的常规表单? Are you using async or traditional Google Analytics syntax? 您使用的是异步还是传统的Google Analytics(分析)语法?

EDIT: 编辑:

Based on the form you just posted, it looks like its an AJAX POST that returns an HTML body. 根据您刚发布的表单,它看起来像一个返回HTML正文的AJAX POST。

So, all you need to do is add your "goal" code into that markup, something like: 因此,您需要做的就是将“目标”代码添加到该标记中,例如:

<script>
_gaq.push(["_trackPageview", "/contact-us"]); //for a URL goal
_gaq.push(["_trackEvent", "Contact Us", "Submit"]); //for an event goal.
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM