I enjoy working with Google Analytics and the ways that I am able to slice information about our visitors. We use Customer Variables to track information about who and how are users interact with our site. Staying true to the goal of Analytics, we are always looking for ways to improve and optimize our website.
我喜欢使用Google Analytics以及我能够分割有关访问者信息的方式。我们使用客户变量来跟踪用户与我们网站的互动对象和信息。坚持分析的目标,我们一直在寻找改善和优化我们网站的方法。
Currently we are in a phase of development where we can make choices about how we want to store and present product information. One of the questions that came up was whether or not to show product information in all caps or not. Working with our users for the last few years, it seems that much of our traffic comes from visitors who do have caps lock on. So it got us thinking, could we track our caps lock users with a customer variable to that we can make a more informed determination about how to present the information?
目前,我们正处于开发阶段,我们可以选择如何存储和展示产品信息。提出的一个问题是是否以全部大写形式显示产品信息。在过去的几年里,我们与用户合作,似乎我们的大部分流量都来自有大写锁定的访问者。所以它让我们思考,我们是否可以通过客户变量跟踪我们的大写锁定用户,以便我们可以更明智地确定如何呈现信息?
Check out this sample I slapped together: http://jsfiddle.net/shanabus/Za4kL/
看看这个样本我一起打耳光:http://jsfiddle.net/shanabus/Za4kL/
Our site basically represents a standard e-commerce site. There are a few different text boxes and that allow you to search for part numbers and throughout the order process there are a few places where users can type text. Would you bind the caps lock test to all text boxes or just the common ones? Is there a performance hit if I bind the keypress listener to all text boxes on the site or is it negligible? Is there a better way to implement this?
我们的网站基本上代表一个标准的电子商务网站。有几个不同的文本框,允许您搜索部件号,在整个订单处理过程中,有一些用户可以键入文本的地方。你会将大写锁定测试绑定到所有文本框或只是常见的文本框吗?如果我将keypress监听器绑定到站点上的所有文本框或者它可以忽略不计,是否会影响性能?有没有更好的方法来实现这个?
I imagine instead of showing/hiding a div I would instead set the custom var:
我想象的不是显示/隐藏div而是设置自定义var:
_gaq.push('_setCustomVar', 5, 'capslock', 'true', 3);
Thanks for any thoughts and consideration on this seemingly trivial topic.
感谢您对这个看似微不足道的话题的任何想法和考虑。
1 个解决方案
#1
4
I'd bind the event globally, and use the following code:
我将全局绑定事件,并使用以下代码:
var CAPS_ON = null;
$(window).keypress(function(ev) {
var charCode = ev.which; //jQuery normalizes ev.charCode to ev.which
// Lowercase chars
if (charCode >= 97 && charCode <= 122) {
CAPS_ON = ev.shiftKey; // Caps are off if SHIFT is not pressed
} else if (charCode >= 65 && charCode <= 90) {
CAPS_ON = !ev.shiftKey;
}
});
This creates a variable CAPS_ON
, which can be used throughout the page.
这将创建一个变量CAPS_ON,可以在整个页面中使用。
Further explanation on the code:
关于代码的进一步说明:
- The event has to be bound to the
keypress
event, because it's the only key event which discerns lowercase/uppercase characters. - 该事件必须绑定到按键事件,因为它是识别小写/大写字符的唯一关键事件。
- The
shiftKey
property has to be checked, because it inverts the CAPS LOCK feature. - 必须检查shiftKey属性,因为它反转了CAPS LOCK功能。
#1
4
I'd bind the event globally, and use the following code:
我将全局绑定事件,并使用以下代码:
var CAPS_ON = null;
$(window).keypress(function(ev) {
var charCode = ev.which; //jQuery normalizes ev.charCode to ev.which
// Lowercase chars
if (charCode >= 97 && charCode <= 122) {
CAPS_ON = ev.shiftKey; // Caps are off if SHIFT is not pressed
} else if (charCode >= 65 && charCode <= 90) {
CAPS_ON = !ev.shiftKey;
}
});
This creates a variable CAPS_ON
, which can be used throughout the page.
这将创建一个变量CAPS_ON,可以在整个页面中使用。
Further explanation on the code:
关于代码的进一步说明:
- The event has to be bound to the
keypress
event, because it's the only key event which discerns lowercase/uppercase characters. - 该事件必须绑定到按键事件,因为它是识别小写/大写字符的唯一关键事件。
- The
shiftKey
property has to be checked, because it inverts the CAPS LOCK feature. - 必须检查shiftKey属性,因为它反转了CAPS LOCK功能。