简体   繁体   English

JqueryUI Range Slider上的Google Analytics(分析)事件跟踪

[英]Google Analytics Event Tracking on JqueryUI Range Slider

So I have a simple JQuery UI range slider with two handles, as shown in this JSFiddle. 因此,我有一个带有两个句柄的简单JQuery UI范围滑块, 如此JSFiddle所示

HTML 的HTML

<p class="results-val">
    <span class="min-val">0 </span>to
    <span class="max-val"> 30</span> days
</p>
<div id="slider"></div>

JS JS

$(function(){
    $( "#slider" ).slider({
        range: true,
        min: -60,
        max: 60,
        step: 5,
        values: [ 0, 30 ],
        slide: function(event, ui) {
            $(".min-val").text(ui.values[0] + " ");
            $(".max-val").text(" " + ui.values[1]);
        }
    });
});

In practice, this slider acts as a filter for our Dashboard application, scoping data shown regarding the user's results based on the range of day values. 实际上,此滑块用作Dashboard应用程序的过滤器,根据日值范围对与用户结果相关的数据进行范围界定。

Via Google Analytics, we want to track different permutations of handle positions. 通过Google Analytics(分析),我们希望跟踪手柄位置的不同排列。 For clarity, when I say permutations, this is what I mean: 为了清楚起见,当我说置换时,这是我的意思:

  • "0 to 30 days" is one permutation. “ 0到30天”是一种排列。

  • "-5 to 15 days" is another permutation. “ -5至15天”是另一个排列。

  • "-40 to 0 days" is another permutation. “ -40至0天”是另一个排列。

And so there are tons of permutations. 因此,存在大量的排列。

My idea for this is to have two events, one for each slider handle, with the handle's current step position as the value being passed: 我的想法是有两个事件,每个滑块手柄一个,用手柄的当前步位置作为传递值:

Category: Filtering,
Action: Adjustment,
Label: leftHandle,
Value: stepPos

Category: Filtering,
Action: Adjustment,
Label: rightHandle,
Value: stepPos

However, there's a problem here. 但是,这里有一个问题。 While this approach will indeed report an Average Value for each handle individually, we want to see both values together. 尽管此方法确实会报告每个句柄的平均值但我们希望同时看到这两个值 As stated above, it's important for us to know the most popular "permutations", with a single permutation consisting of both a left handle position value and a right handle position value. 如上所述,对于我们来说,了解最流行的“排列”非常重要,因为单个排列包括左手柄位置值和右手柄位置值。

If anyone has suggestions on how to set this logic, that would be wonderful. 如果有人对如何设置此逻辑有任何建议,那就太好了。 Thank you. 谢谢。

You can stuff both values into a comma separated string 您可以将两个值填充到逗号分隔的字符串中

You can debounce the slider event to only record values that the user keeps for more than a second or two. 您可以对滑块事件进行反跳操作,以仅记录用户保留一两个或两个以上的值。

var globalLeft, globalRight;

$(function(){

    $( "#slider" ).slider({
        range: true,
        min: -60,
        max: 60,
        step: 5,
        values: [ 0, 30 ],
        slide: function(event, ui) {
            $(".min-val").text(ui.values[0] + " ");
            $(".max-val").text(" " + ui.values[1]);

            globalLeft  = ui.values[0];
            globalRight = ui.values[1];

            $.debounce(1300, doPingGa)
        }
    });
});
function doPingGa() {
    ga('send', 'event', 'Filtering', 'RangeAdjust', globalLeft+','+globalRight);
}

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

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