Adding a handler for touch events as well as click

Tealium Expert
Tealium Expert

I need to write a handler for a click or a touch event.  I've done lots of click handlers before, using the jQuery onHandler extensions.  But this extension doesn't have any touch events in the drop down.

Do I need to use raw JS extensions to manage these clicks/touch events? Or is there a way to capture touch events using Tealium extension templates?


Adding a handler for touch events as well as click

Tealium Employee

Hi @BenStephenson

So if you want to use jQuery there is a module for mobile you can use. 

If you want to use native JS, you can do something like:

var el = document.getElementById("myBtn");
el.addEventListener("touchstart", handleStart, false);
el.addEventListener("touchend", handleEnd, false);
el.addEventListener("touchcancel", handleCancel, false);
el.addEventListener("touchmove", handleMove, false);

However, to note, the click event will be triggered as well, like a normal mouse click.




Ask me anything Tealium related or TypeScript/JavaScript, or NodeJS.
Please remember to mark solutions as accepted for future searchers.