-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathauto-events.js
More file actions
4 lines (3 loc) · 2.72 KB
/
auto-events.js
File metadata and controls
4 lines (3 loc) · 2.72 KB
1
2
3
4
/* Simple Analytics - Privacy-first analytics (docs.simpleanalytics.com/script; 2025-06-13; 7048; v12) */
function r(t,e){var a,n;t.hasAttribute("data-simple-event")||(a=!1,h.downloads&&/^https?:\/\//i.test(t.href)&&new RegExp("\\.("+(h.downloadsExtensions||[]).join("|")+")$","i").test(t.pathname)?a="download":h.outbound&&/^https?:\/\//i.test(t.href)&&t.hostname!==m.location.hostname?a="outbound":h.emails&&/^mailto:/i.test(t.href)&&(a="email"),a&&(e?(n="saAutomatedLink(this, '"+a+"');",t.hasAttribute("target")&&"_self"!==t.getAttribute("target")||(n+=" return false;"),t.setAttribute("onclick",n)):t.addEventListener("click",function(){g(t,a)})))}function e(){try{for(var t=document.getElementsByTagName("a"),e=0;e<t.length;e++){var a=t[e],n=a.getAttribute("href");n&&(a.getAttribute("onclick")||/^mailto:/.test(n)?r(a,!1):r(a,!0))}}catch(o){b(o.message,"warn")}}var m,b,t,o,a,n,i,l,p,h,g;void 0!==(m=window)&&(b=function(t,e){var a="warn"===e?console.warn:console.info;return a&&a("Simple Analytics auto events:",t)},t=m.document,o=t.currentScript||t.querySelector('script[src*="auto-events.js"]'),n=(a=function(t,e,a){var n=o&&o.dataset[t];return"bool"!==e||"true"!==n&&"false"!==n?"bool"===e?a:"array"===e&&n?n.split(",").map(function(t){return t.trim()}).filter(Boolean):"array"!==e&&n||a:"true"===n})("collect","array",["outbound","emails","downloads"]),i=a("fullUrls","bool",!1),l={outbound:-1<n.indexOf("outbound"),emails:-1<n.indexOf("emails"),downloads:-1<n.indexOf("downloads"),downloadsExtensions:a("extensions","array",["pdf","csv","docx","xlsx","zip","doc","xls"]),title:a("useTitle","bool",!0),outboundFullUrl:i,downloadsFullUrl:i},p=a("saGlobal","string","sa_event"),void 0===(h=l)&&b("options object not found, please specify","warn"),g=function g(t,e){try{if(!t)return b("no element found");var a=!1,n=function(){a||t.hasAttribute("target")||(document.location=t.getAttribute("href")),a=!0};if(m[p]&&m[p+"_loaded"]){var o,r=t.hostname,i=t.pathname,l={title:t.getAttribute("title")||undefined},s=t.href||undefined,u=!1;if(h.title&&t.hasAttribute("title")&&(""!=(o=t.getAttribute("title").trim())&&(u=!0)),u)d=o;else switch(e){case"outbound":d=r+(h.outboundFullUrl?i:""),l.url=s;break;case"download":d=h.downloadsFullUrl?r+i:i.split("/").pop(),l.url=s;break;case"email":var d=(t.getAttribute("href").split(":")[1]||"").split("?")[0];l.email=d}var c=e+"_"+d.replace(/[^a-z0-9]+/gi,"_").replace(/(^_+|_+$)/g,"");return m[p](c,l,n),b("collected "+c),"email"===e?n():m.setTimeout(n,5e3)}return b(p+" is not defined","warn"),n()}catch(f){b(f.message,"warn")}},m.saAutomatedLink=g,"ready"===t.readyState||"complete"===t.readyState?e():document.addEventListener("readystatechange",function(t){"complete"===t.target.readyState&&e()}));
//# sourceMappingURL=auto-events.js.map