I have a tracking pixel that I need to load in JS, at the click of a button. So the process is as follow :
- The user clicks a link
- I prevent the click (e.preventDefault)
- load the tracking pixel
- Redirect the user
Here is the code :
$('.btn-cta').on('click', function (e) {
e.preventDefault();
$('body').append('<img width="1" height="1" src="http://main.exoclick.com/tag.php?goal=xyz">');
window.location.replace($(this).attr('href'));
});
My problem is that not 100% of the people who click are tracked, seems like about 40/50% of them are not tracked. I don't see another method to do this, do you have a better idea to track this kind of thing in JS ?
All ideas welcome.
John
onloadevent listener on the image.