-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanchorjs.min.js
More file actions
7 lines (7 loc) · 1.59 KB
/
anchorjs.min.js
File metadata and controls
7 lines (7 loc) · 1.59 KB
1
2
3
4
5
6
7
/*!
* Anchor.js - 1.0.0
* https://github.com/mitmelon/anchor.js
* MIT License
* Copyright (C) 2020-2021 Manomite https://github.com/mitmelon/
*/
class AnchorJS{events=["click","dblclick","touchstart","touchend","contextmenu","mousedown","mouseenter","mouseleave","mousemove","mouseout","mouseover","mouseup"];endpoint=null;init(e,n=null){if(e.classList.contains("MAnchors_")){var t=e.getAttribute("anchor-name");if(null==t||""===t)return void console.error('Anchor Name for MAnchors_ cannot be Null. Please set element anchor_name using anchor-name="Anchor Name".');let s={page_name:window.location.href,origin:document.referrer,platform:navigator.platform,connection_speed:navigator.connection.rtt+" ms",userAgent:navigator.userAgent,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};var o=Object.keys(s).map((e=>e+"="+s[e])).join("&");for(const n of this.events)e.addEventListener(n,(e=>this.handleInteraction(e,t,o)));if(null===n)for(const n of this.events)e.addEventListener(n,(e=>this.handleInteraction(e,t,o)));else for(const s of n)e.addEventListener(s,(e=>this.handleInteraction(e,t,o)))}else console.error("Your element does not contain the MAnchors_ class.")}handleInteraction(e,n,t){this.postData(this.endpoint,"anchor_name="+n+"&trigger="+e.type+"&x="+e.clientX+"&y="+e.clientY+"&screenX="+e.screenX+"&screenY="+e.screenY+"&"+t)}async postData(e="",n){var t=new XMLHttpRequest;t.open("POST",e,!0),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.onreadystatechange=function(){this.readyState===XMLHttpRequest.DONE&&200===this.status&&console.log("Tracker initiated")},t.send(n)}}