简体   繁体   English

跟踪Google Analytics(分析)目标中的表单输入

[英]Track form input in Google Analytics goal

I have an account registration form where a user can select their account type. 我有一个帐户注册表格,用户可以在其中选择其帐户类型。 I have a goal set up in google analytics that has a signup funnel starting with the signup form and ending with the thank you page. 我在Google Analytics(分析)中设置了一个目标,该目标具有一个注册渠道,该渠道以注册表单开始,以“谢谢”页面结束。 I would also like to be able to track the number of account types in the goal or another goal altogether. 我还希望能够跟踪目标或其他目标中的帐户类型数量。

In the code below I have some radio buttons to choose the account type and then there is obviously a submit button after various other form fields. 在下面的代码中,我有一些单选按钮可以选择帐户类型,然后在其他各种表单字段之后显然还有一个提交按钮。

My site is Magento/PHP. 我的网站是Magento / PHP。

<label><input type="radio" name="account_type" value="personal">Personal</label>
<label><input type="radio" name="account_type" value="business">Business</label>
[...]
<button role="button" title="Apply" type="submit">Apply</button>

I would be grateful for any advice. 如有任何建议,我将不胜感激。 Thank you. 谢谢。

On your "thank you" page, in addition to the regular on-page code, you can also set a custom variable with the information. 在“谢谢”页面上,除了常规的页面代码外,您还可以使用信息设置自定义变量 Alternatively, you can pop it when the visitor makes their selection (during click event) or on form submit (js callback function on submit button) but ideally since you will want to only pop it upon a successful form submission, the best way is to track it on the thank you page. 另外,您可以在访问者进行选择(在单击事件期间)或在表单提交(提交按钮上的js回调函数)上进行访问时弹出它,但理想情况下,由于您只想在成功提交表单后弹出它,因此最好的方法是在“谢谢”页面上对其进行跟踪。

Example "thank you" page code: 示例“谢谢”页面代码:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '[your account id here]']);
  _gaq.push(['_setCustomVar',1,'Account Type','[radio button value here]',2]);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

Edit: 编辑:

The above method is to set a custom variable with the desired info. 上面的方法是使用所需信息设置自定义变量。 This will introduce new dimensions and metrics to use in your reports. 这将引入新的维度和指标以在您的报告中使用。 IMO the above is the best way to go about tracking this sort of thing. IMO以上是跟踪此类事件的最佳方法。

However, in the comments below, greg mentioned that you might be asking how to track this as part of your goal. 但是,greg在下面的评论中提到您可能会问如何将其作为目标的一部分进行跟踪。 One thing you can do is invoke a _trackPageview on it, using a custom URL. 您可以做的一件事是使用自定义URL在其上调用_trackPageview。 For example (and this is just an example, to demonstrate the principle...ideally you will probably want to call this somewhere else, like in a wrapper function that grabs the form value...) 例如(这只是一个示例,以演示该原理……理想情况下,您可能想在其他地方调用它,例如在获取表单值的包装函数中……)

<button onclick="_gaq.push(['_trackPageview','/forms/accountType/[radio button value here]']);" role="button" title="Apply" type="submit">Apply</button>

If you track it like this, then you will be able to include this virtual page name as a step in your current goal funnel. 如果以这种方式跟踪它,那么您就可以在当前目标渠道中将此虚拟页面名称包括在内。 HOWEVER, NOTE that this method will increase your page views and screw with your other metrics; 但是,请注意,此方法将增加您的页面浏览量,并与其他指标保持一致; you will have to remember to exclude these page views from all your other reports! 您将必须记住从所有其他报告中排除这些页面浏览量!

Another alternative is to track it as an event , and you can make a separate goal based off the event. 另一种选择是将其作为事件进行跟踪 ,您可以根据事件制定单独的目标。 Example: 例:

_gaq.push(['_trackEvent', 'Forms', 'Account Type', '[radio button value here]']);

You can put it in an onclick like the 2nd code example above, or you can put it on the "thank you" page, like in the 1st code example above (I suggest putting it on the thank you page). 您可以像上面的第二个代码示例一样将其放在onclick中,也可以像上面的第一个代码示例一样将其放在“谢谢”页面上(我建议将其放在“谢谢”页面上)。

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

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