• Skip to main content
  • Skip to secondary navigation
  • Skip to primary sidebar
  • Skip to footer

recoveryArea

Content Management for Everyone!

  • About me
  • Blog
  • Contact me
  • AB Testing
  • WordPress
  • Portfolio

Track That!

7 February 2016 By iPasqualito

This function tracks every event with all its attributes in the div that’s set in the caller function. Handy if you need custom tracking for your AB test.


var trackThat = function() {
    
    var t = {},
        r = {},
        a = window.event ? window.event.srcElement : i.target,
        c = document.getElementsByTagName(a.tagName),
        k = "";
    try {
        for (var d = 0; d < c.length; ++d) c[d] == a && (r.tag = a.tagName, r.index = d, r.text = a.hasChildNodes() ? a.childNodes[0].data : "null"); for (var l, d = 0, o = a.attributes, g = o.length; g > d; d++) l = o[d], t[l.nodeName] = l.nodeValue;
        r.attrs = t, k = JSON.stringify(r);
    } catch (i) {
        k = "error: " + i.message;
    } finally {
        return k;
    }
};

$( 'div.main-holder' ).on('click', function(e){
    console.log(trackThat(e));
});

Filed Under: JavaScript

Pascal Louwes

Me
Creative, resourceful and innovative Front End Developer / User Experience Optimizer. I love to make stuff work, perform and convert better.

Buzzwords
JavaScript, jQuery, User Experience & Conversion Optimization, Web Strategy, Interaction Design, Accessibility, Wordpress Design, Development & Optimization. check out my full profile

Primary Sidebar

Recent Posts

  • Notify Enter Viewport the proper way: Intersection Observer.
  • Notify Enter Viewport
  • AB Test jQuery Performance Cheat Sheet
  • Track That!
  • A smarter console.info

Archives

  • February 2020
  • June 2018
  • October 2016
  • February 2016
  • February 2011

Categories

  • AB Testing
  • JavaScript
  • Performance

Footer

Office

recoveryArea
Nijverheidstraat 11-1
7511 JM Enschede

KvK: 65594940

Goals

Let's make a more elegant, easy to use internet, accessible for everyone. Let's move forward to an empathic, secular, sustainable future, enabled through science and technology.

Read my full profile

Get in touch

  • GitHub
  • LinkedIn
  • Twitter

Copyright © 2021 · Author Pro On Genesis Framework · WordPress · From recoveryArea with