我试图将值从表单上的2个隐藏输入字段发送到在Google Analytics(分析)内部创建的2个自定义维度,但是我不知道在提交表单时如何发送这些值。我也使用重力形式。
在Google Analytics(分析)中创建的维度为contactID和locationID:

我的代码如下所示:

<input name='input_4' id='input_6_4' type='hidden' class='gform_hidden' value='123456' />
<input name='input_25' id='input_6_25' type='hidden' class='gform_hidden' value='987654' />

jQuery(document).ready(function(){
  jQuery('#gform_6').submit(function(e) {
    var form = this;
    var contactID = $('#input_6_4').val();
    var locationID = $('#input_6_25').val();

    e.preventDefault(); // disable the default submit action

    ga('set', 'contactID', contactID);
    ga('set','locationID', locationID);

    $(':input', this).attr('disabled', true);

    setTimeout(function() {
        form.submit();
    }, 1000);
  });
});


感谢任何人的帮助。

最佳答案

您需要考虑两件事:

1)自定义维度和指标需要与现有匹配一起发送。这意味着仅设置自定义维度不会将值发送到Google Analytics(分析)。设置它们后,您需要向Google Analytics(分析)发送某种类型的匹配,例如事件,网页浏览等。您也可以在匹配时进行设置(如下例所示)。

2)通过使用维度或指标的索引值来设置自定义维度和指标。因此,在您的情况下,您可能已经命名了维度contactID,但实际上您需要找出该维度的索引并进行设置。您可以在创建尺寸的Web Interface中找到它,应该会看到一个索引列。因此,例如,如果contactID的索引值为2,则实际上需要设置Dimension2。开发人员站点上对此进行了介绍,因此您应该阅读Custom Dimensions & Metrics

放在一起:例如,如果contactID的维度索引为1,而locationID的维度索引为2,并且如果您决定在提交表单后发送事件以确保将这些值发送到Google Analytics(分析),

那么你将取代

ga('set','contactID',contactID);
ga('set','locationID',locationID);

与:

ga('send', 'event', 'category', 'action', {
    'dimension1': contactID,
    'dimension2': locationID
});


并将“类别”和“操作”替换为事件所需的任何值。

10-07 19:09
查看更多