-
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.74 KB
/
auto-events.js
File metadata and controls
4 lines (3 loc) · 2.74 KB
1
2
3
4
/* Simple Analytics - Privacy-first analytics (docs.simpleanalytics.com/script; 2025-06-24; 9e4f; v12) */
function r(t,e){var a,n;t.hasAttribute("data-simple-event")||(a=!1,g.downloads&&/^https?:\/\//i.test(t.href)&&new RegExp("\\.("+(g.downloadsExtensions||[]).join("|")+")$","i").test(t.pathname)?a="download":g.outbound&&/^https?:\/\//i.test(t.href)&&t.hostname!==b.location.hostname?a="outbound":g.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(){w(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){p(o.message,"warn")}}var b,p,t,o,a,n,i,l,h,g,w;void 0!==(b=window)&&(p=function(t,e){var a="warn"===e?console.warn:console.info;return a&&a("Simple Analytics auto events:",t)},t=b.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},h=a("saGlobal","string","sa_event"),void 0===(g=l)&&p("options object not found, please specify","warn"),w=function w(t,e){try{if(!t)return p("no element found");var a=!1,n=t.getAttribute("href"),o=function(){a||t.hasAttribute("target")||!n||(document.location=n),a=!0};if(b[h]&&b[h+"_loaded"]){var r,i=t.hostname,l=t.pathname,s={title:t.getAttribute("title")||undefined},u=t.href||undefined,d=!1;if(g.title&&t.hasAttribute("title")&&(""!=(r=t.getAttribute("title").trim())&&(d=!0)),d)c=r;else switch(e){case"outbound":c=i+(g.outboundFullUrl?l:""),s.url=u;break;case"download":c=g.downloadsFullUrl?i+l:l.split("/").pop(),s.url=u;break;case"email":var c=((n=t.getAttribute("href")).split(":")[1]||"").split("?")[0];s.email=c}var f=e+"_"+c.replace(/[^a-z0-9]+/gi,"_").replace(/(^_+|_+$)/g,"");return b[h](f,s,o),p("collected "+f),"email"===e?o():b.setTimeout(o,5e3)}return p(h+" is not defined","warn"),o()}catch(m){p(m.message,"warn")}},b.saAutomatedLink=w,"ready"===t.readyState||"complete"===t.readyState?e():document.addEventListener("readystatechange",function(t){"complete"===t.target.readyState&&e()}));
//# sourceMappingURL=auto-events.js.map