• Skip to primary navigation
  • Skip to content
  • Skip to footer

recoveryArea

Front End Development & UX Optimization

  • About
  • Code
  • For Sale
  • Contact

Pascal Louwes

JavaScript / 7 February 2016

Track That!

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));
});

JavaScript / 9 February 2011

A smarter console.info

Here is a little piece of code you can use in your project for slightly smarter console messages. Objects and arrays are handled differently when logged to the console than strings. Firebug gives you a stringified version of the object while console.dir gives you an expandable object. Both give you the expandable object in Chrome. To work around this you can use this little snippet, it will always give you the correct version.


var debug = function(message) {
    "object" === typeof console && ("object" === typeof message || "array" === typeof message ? console.dir(message) : console.info(message));
};
« Previous Page

Footer

Contact me

recoveryArea
Nijverheidstraat 11-1
7511 JM Enschede

+31 6 14 77 98 45
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

  • Flickr
  • GitHub
  • LinkedIn
  • Twitter

Copyright © 2019 · Another recoveryArea production · All rights reserved