简体   繁体   English

跟踪 JavaScript 事件

[英]Track JavaScript event

I have GA on my website and i'm trying to track every click on the website.我的网站上有 GA,我正在尝试跟踪网站上的每次点击。 The following JavaScript must be used, it acts like an overlay on the page:必须使用以下 JavaScript,它的作用类似于页面上的叠加层:

<script type="text/javascript">
var tile = new HTMLLiveTile.TileController();
window.onmousedown = function() {
tile.openStoreProduct("var1", "var2", "var3");
}
</script>

What would be the HTML equivalent code to track this?跟踪这个的 HTML 等效代码是什么?

Right now i have:现在我有:

<a id="tile" onClick="ga('send', 'event', 'click1', 'click2', 'sample');"><img src="./images/image.png"> </a>

I'm very new to this, sorry if it's redundant.我对此很陌生,抱歉,如果它是多余的。 My assumption was to track the variable and add it to the onClick.我的假设是跟踪变量并将其添加到 onClick。

I guess you are asking for a solution that does not require much hassle and much changing in code and moreover without any need to change your previous code.我猜您正在寻求一种不需要太多麻烦和代码更改的解决方案,而且不需要更改您以前的代码。 you can use event.target.你可以使用event.target. + things you need to know to get info. +获取信息需要知道的事情。

    function mouseTrack(){
        var element_name = event.target.tagName;
        alert("mouse click was detecteted at: "+ element_name);
    }
    window.addEventListener('click', mouseTrack(), false);

this code will alert the Tag Name of Element clicked (like DIV, a, SPAN etc you know the list.).此代码将提醒单击的元素的标记名称(如 DIV、a、SPAN 等您知道列表。)。 But this code is awful.It wont work in Mozilla FF, It wont work In IE 9 below.但是这段代码很糟糕。它在 Mozilla FF 中不起作用,在下面的 IE 9 中不起作用。 I took some time to create a fiddle on JSFiddle.net you can view example I made Here我花了一些时间在JSFiddle.net上创建了一个小提琴,您可以在此处查看我制作的示例

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

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