Skip to content

Instantly share code, notes, and snippets.

@catchamonkey
Created May 30, 2012 08:41
Show Gist options
  • Save catchamonkey/2834596 to your computer and use it in GitHub Desktop.
Save catchamonkey/2834596 to your computer and use it in GitHub Desktop.
Infinity Tracking - Custom Trigger for all mailto links
/**
* Registers a click handler for all mailto links on the page and fires
* an Infinity Tracking custom trigger when clicked
* We use 'live' for mailto links loaded after the DOM is ready
* @author Chris Sedlmayr <chris.sedlmayr@infinity-tracking.com>
*/
// copy of initialise the infinity var
var _ictt = _ictt || [];
$(document).ready(function() {
// find 'a' elements that have an href starting with mailto:
$('a[href^="mailto:"]').live('click', function() {
// ensure the infinity variable is available
if (typeof _ictt != 'undefined') {
// track this, using the mailto location as the title
_ictt.push([
'_customTrigger',
'MAILTOCLICK',
{
't':this.href.replace(/^mailto\:/i, '')
}
]);
};
});
});
@parkji
Copy link

parkji commented May 30, 2012

And in native JS:

// copy of initialise the infinity var
var _ictt = _ictt || [];
document.addEventListener("DOMContentLoaded", function() {
    // find 'a' elements that have an href starting with mailto:
    [].forEach.call(document.querySelectorAll('a[href^="mailto:"]'), function(el) {
        el.addEventListener('click', function() {
            if (typeof _ictt != 'undefined') {
                // track this, using the mailto location as the title
                _ictt.push([
                    '_customTrigger',
                    'MAILTOCLICK',
                    {
                        't':this.href.replace(/^mailto\:/i, '')
                    }
                ]);
            };
        });
    });
});

@catchamonkey
Copy link
Author

Nice one, that was next up. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment