Repository navigation
Expand file tree
/
Copy pathauto-events.js
More file actions
4 lines (3 loc) · 2.84 KB
/
Copy pathauto-events.js
File metadata and controls
4 lines (3 loc) · 2.84 KB
1
2
3
4
/* Simple Analytics - Privacy-first analytics (docs.simpleanalytics.com/script; 2025-06-13; 644f; v12) */
function r(e,t){var a,n;e.hasAttribute("data-simple-event")||(a=!1,v.downloads&&/^https?:\/\//i.test(e.href)&&new RegExp("\\.("+(v.downloadsExtensions||[]).join("|")+")$","i").test(e.pathname)?a="download":v.outbound&&/^https?:\/\//i.test(e.href)&&e.hostname!==b.location.hostname?a="outbound":v.emails&&/^mailto:/i.test(e.href)&&(a="email"),a&&(t?(n="return saAutomatedLink(this, '"+a+"', event);",e.setAttribute("onclick",n)):e.addEventListener("click",function(t){g(e,a,t)})))}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,v,g;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===(v=l)&&p("options object not found, please specify","warn"),g=function g(t,e,a){try{if(!t)return p("no element found");var n=!1,o=t.hasAttribute("target")&&"_self"!==t.getAttribute("target")||a&&(a.metaKey||a.ctrlKey||a.shiftKey||a.altKey||1===a.button);a&&!o&&a.preventDefault&&a.preventDefault();var r=function(){n||o||t.hasAttribute("target")||(document.location=t.getAttribute("href")),n=!0};if(b[h]&&b[h+"_loaded"]){var i,l=t.hostname,s=t.pathname,u={title:t.getAttribute("title")||undefined},d=t.href||undefined,c=!1;if(v.title&&t.hasAttribute("title")&&(""!=(i=t.getAttribute("title").trim())&&(c=!0)),c)a=i;else switch(e){case"outbound":a=l+(v.outboundFullUrl?s:""),u.url=d;break;case"download":a=v.downloadsFullUrl?l+s:s.split("/").pop(),u.url=d;break;case"email":a=(t.getAttribute("href").split(":")[1]||"").split("?")[0],u.email=a}var f=e+"_"+a.replace(/[^a-z0-9]+/gi,"_").replace(/(^_+|_+$)/g,"");return b[h](f,u,r),p("collected "+f),"email"===e?r():b.setTimeout(r,5e3),o}return p(h+" is not defined","warn"),r(),o}catch(m){return p(m.message,"warn"),o}},b.saAutomatedLink=g,"ready"===t.readyState||"complete"===t.readyState?e():document.addEventListener("readystatechange",function(t){"complete"===t.target.readyState&&e()}));
//# sourceMappingURL=auto-events.js.map