UNPKG

web-event-tracker-sdk

Version:

Auto-capture web events like page views, button clicks, and link clicks.

3 lines (2 loc) 915 B
var t=function(){function t(){}return t.init=function(t){this.config=t,!1!==t.autoCapture&&this.setupAutoCapture(),this.capturePageView()},t.setupAutoCapture=function(){document.addEventListener("click",this.handleClick,!0)},t.handleClick=function(e){var n=e.target;if(n){var i="";i="A"===n.tagName?"link_click":"BUTTON"===n.tagName?"button_click":"element_click",t.sendEvent({type:i,tag:n.tagName,text:n.innerText||"",href:n.href||"",timestamp:Date.now()})}},t.capturePageView=function(){this.sendEvent({type:"page_view",url:window.location.href,title:document.title,timestamp:Date.now()})},t.sendEvent=function(t){this.config&&this.config.endpoint&&fetch(this.config.endpoint,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(this.config.apiKey)},body:JSON.stringify(t)}).catch(function(){})},t}();export{t as default}; //# sourceMappingURL=web-event-tracker-sdk.esm.js.map