简体   繁体   中英

Track JavaScript event

I have GA on my website and i'm trying to track every click on the website. The following JavaScript must be used, it acts like an overlay on the page:

<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?

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.

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. + 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.). But this code is awful.It wont work in Mozilla FF, It wont work In IE 9 below. I took some time to create a fiddle on JSFiddle.net you can view example I made Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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