简体   繁体   English

Google Analytics(分析)设置了自定义变量,可在提交联系表单后更改值Drupal 7

[英]Google analytics set custom variable that change value after contact form submission Drupal 7

My purpuse is to get the categories' statistics of contact requests sent by users by submiting the site contact form. 我的目的是通过提交站点联系表来获取用户发送的联系请求的类别统计信息。 I'm working with the Drupal-7 contributive module "google analytics" and I think about setting a custom variable called "contact form category" that change value according to to the choosen contact form category of one visitor 我正在使用Drupal-7贡献模块“谷歌分析”,我考虑设置一个名为“联系表单类别”的自定义变量,该变量根据一个访客的选择的联系表单类别来更改值

I guess I should begin with the following code 我想我应该从以下代码开始

$('#contact-site-form').submit(function() {
    _gaq.push(['_trackEvent', 'Contact Form', 'Form submission', 'New submission']);
});

Please, can you help me to find the solution :( 拜托,您能帮我找到解决方法吗:(

I see you're using google analytics classic by the usage of _gaq, I strongly advise you to upgrade to universal analytics. 我看到您通过_gaq使用了Google Analytics(分析)经典版,强烈建议您升级到通用分析。

In universal analytics, Custom variables are deprecated. 在通用分析中,不赞成使用自定义变量。 You should use custom dimensions or metrics instead. 您应该改用自定义维度或指标。 They're practically the same, but google analytics will have better support for them than custom variables in the future. 它们实际上是相同的,但是与将来的自定义变量相比,谷歌分析将对它们提供更好的支持。

Here's a guide about how to set up a new dimension: https://support.google.com/analytics/answer/2709829?hl=en 这是有关如何设置新维度的指南: https : //support.google.com/analytics/answer/2709829?hl=zh_CN

Specifically addressing your problem, you need to define a new custom dimension which will be called or example 'ContactFormCategory', and set its scope to be 'hit' (since this dimension should be associated with your following event only) and GA will assign an index to that dimension. 要专门解决您的问题,您需要定义一个新的自定义维度(称为“ ContactFormCategory”或示例),并将其范围设置为“ hit”(因为该维度仅应与您的以下事件相关联),GA会分配一个该维度的索引。 Let's assume that index equals 1. 假设索引等于1。

Then the code you'll put will be: 然后,您要输入的代码将是:

$('#contact-site-form').submit(function() {
    ga.('set', { 'dimension1': 'your_category_value' });
    ga.push(['_trackEvent', 'Contact Form', 'Form submission', 'New submission']);
});

If for some reason you can't upgrade to universal analytics and you're stuck with classic analytics, you can only use custom variables. 如果由于某种原因您不能升级到通用分析,而又坚持使用经典分析,则只能使用自定义变量。 You won't need to define anything in the analytics UI like in dimensions\\metrics, only to set the appropriate data. 您无需在分析UI中定义任何维度(例如,维度\\指标),只需设置适当的数据即可。 You can use this guide to do it: 您可以使用本指南进行操作:

https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables

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

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