单击热图和鼠标坐标! - JavaScript
我正在尝试为我的一个网站构建一个简单的热图,但它似乎比我想象的要棘手得多!
1) 该网站有不同的主题,1 个是左对齐,另一个是中心对齐。
2) 屏幕尺寸会随着用户的不同而变化。
我需要跟踪网站上的点击,但不幸的是 event.PageX 和 event.PageY 是在考虑整个屏幕的情况下计算的。
示例
在第一个示例中,坐标为 [300, 500] 的单击可能位于大猩猩周围的某个位置(可能是他的鼻孔! =) )。
在另一个示例中,单击坐标为 [300. 500] 可能会位于主要内容区域之外的某个位置!
底线: 我该如何解决这个问题,以便我可以构建准确的 DIY 点击热图?
知道这一点真的很有趣!谢谢你们! =)
I'm trying to build a simple heatmap for one of my sites, but it seems a lot trickier that I thought!
1) There are different themes for the site, 1 is aligned to the left, another one is aligned to the centre.
2) Screen sizes change throughout the users.
I need to track clicks on the site, but unfortunately event.PageX and event.PageY are calculated taking in consideration the whole screen.
Examples
In the first example a click with coordinates [300, 500] will probably be located somewhere around the gorilla (maybe his nostrils! =) ).
In this other example a click with coordinates [300. 500] will probably be located somewhere outside the main content area!
Bottomline:
How can I address this problem, so that I can build an accurate DIY click heatmap?
This would be really interesting to know! Thanks guys! =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1)只需传递当前主题和坐标即可。
2) 获取主要内容区域的鼠标相对位置。这样您就可以避免不同浏览器宽度/高度的不同位置的问题。
关于鼠标位置的 jQuery 文档 中有一个特殊部分(如果您要使用它):这:
话虽这么说,也许有点矫枉过正; Google Analytics 也具有热图功能。
1) Just pass the current theme along with the coordinates.
2) Get the relative mouse position of your main content area. This way you avoid the problem of different positions for different browser widths/heights.
There is a special part in the jQuery docs for Mouse Position (if you were to use it) about this:
That being said, perhaps overkill; Google Analytics has a heatmap feature too.
您可以根据底层对象(即大猩猩)存储每次点击的相对坐标,而不是存储每次点击的绝对坐标。
然后,在显示热图时,您会以您的分辨率显示相对于每个对象的点击次数。
为此,您只需获取每次点击的“目标”对象(这是事件参数的“目标”属性)并从点击坐标中减去它的坐标。
Rather than storing the absolute co-ords for each click you could store the reltive co-ord for each click based on the underlying object, i.e the gorilla.
Then when displaying the heatmap you display clicks relative to each object at your resolution.
To do this you would simply have to grab the 'target' object of each click (this is the 'target' property of the event arguments) and subtract it's co-ords from the click co-ords.
这是我的代码。它仅记录页面包装内的点击(而不是背景内容)。所以你只能得到相对位置。
Here is my code. It logs clicks only inside page wrapper (not background n stuff). So you get relative positions only.