@bigchill101/iris 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ interface IrisConfig {
2
+ host: string;
3
+ siteId: string;
4
+ autocapture?: boolean;
5
+ debug?: boolean;
6
+ }
7
+
8
+ declare class Iris {
9
+ private transport;
10
+ private config;
11
+ constructor(config: IrisConfig);
12
+ start(): void;
13
+ track(name: string, props?: object): void;
14
+ private trackPageview;
15
+ private enableHistoryPatch;
16
+ }
17
+
18
+ export { Iris };
@@ -0,0 +1,18 @@
1
+ interface IrisConfig {
2
+ host: string;
3
+ siteId: string;
4
+ autocapture?: boolean;
5
+ debug?: boolean;
6
+ }
7
+
8
+ declare class Iris {
9
+ private transport;
10
+ private config;
11
+ constructor(config: IrisConfig);
12
+ start(): void;
13
+ track(name: string, props?: object): void;
14
+ private trackPageview;
15
+ private enableHistoryPatch;
16
+ }
17
+
18
+ export { Iris };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var s=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var b=(n,t)=>{for(var e in t)s(n,e,{get:t[e],enumerable:!0})},w=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of v(t))!m.call(n,o)&&o!==e&&s(n,o,{get:()=>t[o],enumerable:!(i=h(t,o))||i.enumerable});return n};var y=n=>w(s({},"__esModule",{value:!0}),n);var P={};b(P,{Iris:()=>c});module.exports=y(P);var a=class{constructor(t){this.config=t}send(t){let e=`${this.config.host}/api/event`,i=JSON.stringify({...t,s:this.config.siteId});if(navigator.sendBeacon){let o=new Blob([i],{type:"application/json"});navigator.sendBeacon(e,o)}else fetch(e,{method:"POST",body:i,keepalive:!0,headers:{"Content-Type":"application/json"}}).catch(o=>{this.config.debug&&console.error("Iris: Failed to send",o)});this.config.debug&&console.log("Iris: Event Sent",t)}};function f(n){window.addEventListener("click",t=>{var l;let i=t.target.closest('button, a, input[type="submit"], [role="button"]');if(!i||i.classList.contains("iris-ignore")||i instanceof HTMLInputElement&&i.type==="password")return;let o=i.tagName.toLowerCase(),u="$click",p={$tag:o,$id:i.id||void 0,$class:i.className||void 0,$text:((l=i.innerText)==null?void 0:l.slice(0,50))||""};if(o==="a"){let d=i.getAttribute("href");d&&(p.$href=d)}n(u,p)},{capture:!0})}var r=require("web-vitals");function g(n){let t=e=>{n("$web_vital",{$id:e.id,$name:e.name,$val:e.value,$rating:e.rating})};(0,r.onCLS)(t),(0,r.onINP)(t),(0,r.onLCP)(t)}var c=class{transport;config;constructor(t){this.config={autocapture:!0,debug:!1,...t},this.transport=new a(this.config)}start(){this.trackPageview(),this.enableHistoryPatch(),this.config.autocapture&&f(this.track.bind(this)),g(this.track.bind(this))}track(t,e){let i={n:t,u:window.location.href,d:window.location.hostname,r:document.referrer||null,w:window.innerWidth,p:e};this.transport.send(i)}trackPageview(){this.track("$pageview")}enableHistoryPatch(){let t=history.pushState;history.pushState=(...e)=>{t.apply(history,e),this.trackPageview()},window.addEventListener("popstate",()=>{this.trackPageview()})}};0&&(module.exports={Iris});
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var r=class{constructor(t){this.config=t}send(t){let i=`${this.config.host}/api/event`,e=JSON.stringify({...t,s:this.config.siteId});if(navigator.sendBeacon){let n=new Blob([e],{type:"application/json"});navigator.sendBeacon(i,n)}else fetch(i,{method:"POST",body:e,keepalive:!0,headers:{"Content-Type":"application/json"}}).catch(n=>{this.config.debug&&console.error("Iris: Failed to send",n)});this.config.debug&&console.log("Iris: Event Sent",t)}};function p(o){window.addEventListener("click",t=>{var s;let e=t.target.closest('button, a, input[type="submit"], [role="button"]');if(!e||e.classList.contains("iris-ignore")||e instanceof HTMLInputElement&&e.type==="password")return;let n=e.tagName.toLowerCase(),f="$click",a={$tag:n,$id:e.id||void 0,$class:e.className||void 0,$text:((s=e.innerText)==null?void 0:s.slice(0,50))||""};if(n==="a"){let c=e.getAttribute("href");c&&(a.$href=c)}o(f,a)},{capture:!0})}import{onCLS as g,onINP as u,onLCP as h}from"web-vitals";function l(o){let t=i=>{o("$web_vital",{$id:i.id,$name:i.name,$val:i.value,$rating:i.rating})};g(t),u(t),h(t)}var d=class{transport;config;constructor(t){this.config={autocapture:!0,debug:!1,...t},this.transport=new r(this.config)}start(){this.trackPageview(),this.enableHistoryPatch(),this.config.autocapture&&p(this.track.bind(this)),l(this.track.bind(this))}track(t,i){let e={n:t,u:window.location.href,d:window.location.hostname,r:document.referrer||null,w:window.innerWidth,p:i};this.transport.send(e)}trackPageview(){this.track("$pageview")}enableHistoryPatch(){let t=history.pushState;history.pushState=(...i)=>{t.apply(history,i),this.trackPageview()},window.addEventListener("popstate",()=>{this.trackPageview()})}};export{d as Iris};
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@bigchill101/iris",
3
+ "version": "0.0.1",
4
+ "description": "Privacy-first, self-hosted analytics client",
5
+ "license": "MIT",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "README.md"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "scripts": {
17
+ "build": "tsup src/index.ts --format esm,cjs --dts --minify"
18
+ },
19
+ "devDependencies": {
20
+ "tsup": "^8.0.0",
21
+ "typescript": "^5.0.0"
22
+ },
23
+ "dependencies": {
24
+ "web-vitals": "^5.1.0"
25
+ }
26
+ }