OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix: bump web sdk
Carl-Gerhard Lindesvärd44184236a80d
diff --git a/apps/public/package.json b/apps/public/package.jsonindex a59684314..9eeb79b20 100644--- a/apps/public/package.json+++ b/apps/public/package.json@@ -14,7 +14,7 @@"@hyperdx/node-opentelemetry": "^0.8.1","@number-flow/react": "0.3.5","@openpanel/common": "workspace:*",- "@openpanel/nextjs": "^1.0.15",+ "@openpanel/nextjs": "^1.0.17","@openpanel/payments": "workspace:^","@openpanel/sdk-info": "workspace:^","@openstatus/react": "0.0.3",diff --git a/apps/public/public/op1.js b/apps/public/public/op1.jsindex 41bce1e68..e4261f3e7 100644--- a/apps/public/public/op1.js+++ b/apps/public/public/op1.js@@ -1 +1 @@-"use strict";(()=>{var u=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":"application/json",...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[i,t]of Object.entries(this.headers)){let s=await t;s!==null&&(e[i]=s)}return e}addHeader(e,i){this.headers[e]=i}async post(e,i,t,s){try{let n=await fetch(e,{method:"POST",headers:await this.resolveHeaders(),body:JSON.stringify(i??{}),keepalive:!0,...t});if(n.status===401)return null;if(n.status!==200&&n.status!==202)throw new Error(`HTTP error! status: ${n.status}`);let r=await n.text();return r?JSON.parse(r):null}catch(n){if(s<this.maxRetries){let r=this.initialRetryDelay*2**s;return await new Promise(a=>setTimeout(a,r)),this.post(e,i,t,s+1)}return console.error("Max retries reached:",n),null}}async fetch(e,i,t={}){let s=`${this.baseUrl}${e}`;return this.post(s,i,t,0)}},l=class{constructor(e){this.options=e,this.queue=[];let i={"openpanel-client-id":e.clientId};e.clientSecret&&(i["openpanel-client-secret"]=e.clientSecret),i["openpanel-sdk-name"]=e.sdk||"node",i["openpanel-sdk-version"]=e.sdkVersion||"1.0.1",this.api=new u({baseUrl:e.apiUrl||"https://api.openpanel.dev",defaultHeaders:i})}init(){}ready(){this.options.waitForProfile=!1,this.flush()}async send(e){return this.options.disabled||this.options.filter&&!this.options.filter(e)?Promise.resolve():this.options.waitForProfile&&!this.profileId?(this.queue.push(e),Promise.resolve()):this.api.fetch("/track",e)}setGlobalProperties(e){this.global={...this.global,...e}}async track(e,i){return this.send({type:"track",payload:{name:e,profileId:i?.profileId??this.profileId,properties:{...this.global??{},...i??{}}}})}async identify(e){if(e.profileId&&(this.profileId=e.profileId,this.flush()),Object.keys(e).length>1)return this.send({type:"identify",payload:{...e,properties:{...this.global,...e.properties}}})}async alias(e){return this.send({type:"alias",payload:e})}async increment(e){return this.send({type:"increment",payload:e})}async decrement(e){return this.send({type:"decrement",payload:e})}async revenue(e,i){let t=i?.deviceId;return delete i?.deviceId,this.track("revenue",{...i??{},...t?{__deviceId:t}:{},__revenue:e})}async fetchDeviceId(){return(await this.api.fetch("/track/device-id",void 0,{method:"GET",keepalive:!1}))?.deviceId??""}clear(){this.profileId=void 0}flush(){this.queue.forEach(e=>{this.send({...e,payload:{...e.payload,profileId:e.payload.profileId??this.profileId}})}),this.queue=[]}};function h(e){return e.replace(/([-_][a-z])/gi,i=>i.toUpperCase().replace("-","").replace("_",""))}var c=class extends l{constructor(t){super({sdk:"web",sdkVersion:"1.0.3",...t});this.options=t;this.lastPath="";this.pendingRevenues=[];if(!this.isServer()){console.log("OpenPanel.dev - Initialized",this.options);try{let s=sessionStorage.getItem("openpanel-pending-revenues");if(s){let n=JSON.parse(s);Array.isArray(n)&&(this.pendingRevenues=n)}}catch{this.pendingRevenues=[]}this.setGlobalProperties({__referrer:document.referrer}),this.options.trackScreenViews&&(this.trackScreenViews(),setTimeout(()=>this.screenView(),0)),this.options.trackOutgoingLinks&&this.trackOutgoingLinks(),this.options.trackAttributes&&this.trackAttributes()}}debounce(t,s){clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(t,s)}isServer(){return typeof document>"u"}trackOutgoingLinks(){this.isServer()||document.addEventListener("click",t=>{let s=t.target,n=s.closest("a");if(n&&s){let r=n.getAttribute("href");if(r?.startsWith("http"))try{let a=new URL(r),o=window.location.hostname;a.hostname!==o&&super.track("link_out",{href:r,text:n.innerText||n.getAttribute("title")||s.getAttribute("alt")||s.getAttribute("title")})}catch{}}})}trackScreenViews(){if(this.isServer())return;let t=history.pushState;history.pushState=function(...a){let o=t.apply(this,a);return window.dispatchEvent(new Event("pushstate")),window.dispatchEvent(new Event("locationchange")),o};let s=history.replaceState;history.replaceState=function(...a){let o=s.apply(this,a);return window.dispatchEvent(new Event("replacestate")),window.dispatchEvent(new Event("locationchange")),o},window.addEventListener("popstate",()=>{window.dispatchEvent(new Event("locationchange"))});let n=()=>this.debounce(()=>this.screenView(),50);this.options.trackHashChanges?window.addEventListener("hashchange",n):window.addEventListener("locationchange",n)}trackAttributes(){this.isServer()||document.addEventListener("click",t=>{let s=t.target,n=s.closest("button"),r=s.closest("a"),a=n?.getAttribute("data-track")?n:r?.getAttribute("data-track")?r:null;if(a){let o={};for(let p of a.attributes)p.name.startsWith("data-")&&p.name!=="data-track"&&(o[h(p.name.replace(/^data-/,""))]=p.value);let d=a.getAttribute("data-track");d&&super.track(d,o)}})}screenView(t,s){if(this.isServer())return;let n,r;typeof t=="string"?(n=t,r=s):(n=window.location.href,r=t),this.lastPath!==n&&(this.lastPath=n,console.log("OpenPanel.dev - Track page view"),super.track("screen_view",{...r??{},__path:n,__title:document.title}))}async flushRevenue(){let t=this.pendingRevenues.map(s=>super.revenue(s.amount,s.properties));await Promise.all(t),this.clearRevenue()}clearRevenue(){if(this.pendingRevenues=[],!this.isServer())try{sessionStorage.removeItem("openpanel-pending-revenues")}catch{}}pendingRevenue(t,s){if(this.pendingRevenues.push({amount:t,properties:s}),!this.isServer())try{sessionStorage.setItem("openpanel-pending-revenues",JSON.stringify(this.pendingRevenues))}catch{}}};(e=>{if(e.op){let i=e.op.q||[],t=new c(i.shift()[1]);i.forEach(n=>{n[0]in t&&t[n[0]](...n.slice(1))});let s=new Proxy((n,...r)=>{let a=t[n]?t[n].bind(t):void 0;typeof a=="function"?a(...r):console.warn(`OpenPanel: ${n} is not a function`)},{get(n,r){if(r==="q")return;let a=t[r];return typeof a=="function"?a.bind(t):a}});e.op=s,e.openpanel=t}})(window);})();+"use strict";(()=>{var c=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":"application/json",...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[t,n]of Object.entries(this.headers)){let r=await n;r!==null&&(e[t]=r)}return e}addHeader(e,t){this.headers[e]=t}async post(e,t,n,r){try{let i=await fetch(e,{method:"POST",headers:await this.resolveHeaders(),body:JSON.stringify(t??{}),keepalive:!0,...n});if(i.status===401)return null;if(i.status!==200&&i.status!==202)throw new Error(`HTTP error! status: ${i.status}`);let s=await i.text();return s?JSON.parse(s):null}catch(i){if(r<this.maxRetries){let s=this.initialRetryDelay*2**r;return await new Promise(a=>setTimeout(a,s)),this.post(e,t,n,r+1)}return console.error("Max retries reached:",i),null}}async fetch(e,t,n={}){let r=`${this.baseUrl}${e}`;return this.post(r,t,n,0)}};var l=class{constructor(e){this.options=e;this.queue=[];let t={"openpanel-client-id":e.clientId};e.clientSecret&&(t["openpanel-client-secret"]=e.clientSecret),t["openpanel-sdk-name"]=e.sdk||"node",t["openpanel-sdk-version"]=e.sdkVersion||process.env.SDK_VERSION,this.api=new c({baseUrl:e.apiUrl||"https://api.openpanel.dev",defaultHeaders:t})}init(){}ready(){this.options.waitForProfile=!1,this.flush()}async send(e){return this.options.disabled||this.options.filter&&!this.options.filter(e)?Promise.resolve():this.options.waitForProfile&&!this.profileId?(this.queue.push(e),Promise.resolve()):this.api.fetch("/track",e)}setGlobalProperties(e){this.global={...this.global,...e}}async track(e,t){return this.send({type:"track",payload:{name:e,profileId:t?.profileId??this.profileId,properties:{...this.global??{},...t??{}}}})}async identify(e){if(e.profileId&&(this.profileId=e.profileId,this.flush()),Object.keys(e).length>1)return this.send({type:"identify",payload:{...e,properties:{...this.global,...e.properties}}})}async alias(e){return this.send({type:"alias",payload:e})}async increment(e){return this.send({type:"increment",payload:e})}async decrement(e){return this.send({type:"decrement",payload:e})}async revenue(e,t){let n=t?.deviceId;return delete t?.deviceId,this.track("revenue",{...t??{},...n?{__deviceId:n}:{},__revenue:e})}async fetchDeviceId(){return(await this.api.fetch("/track/device-id",void 0,{method:"GET",keepalive:!1}))?.deviceId??""}clear(){this.profileId=void 0}flush(){this.queue.forEach(e=>{this.send({...e,payload:{...e.payload,profileId:e.payload.profileId??this.profileId}})}),this.queue=[]}};function h(o){return o.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace("-","").replace("_",""))}var d=class extends l{constructor(t){super({sdk:"web",sdkVersion:"1.0.4",...t});this.options=t;this.lastPath="";this.pendingRevenues=[];if(!this.isServer()){console.log("OpenPanel.dev - Initialized",this.options);try{let n=sessionStorage.getItem("openpanel-pending-revenues");if(n){let r=JSON.parse(n);Array.isArray(r)&&(this.pendingRevenues=r)}}catch{this.pendingRevenues=[]}this.setGlobalProperties({__referrer:document.referrer}),this.options.trackScreenViews&&(this.trackScreenViews(),setTimeout(()=>this.screenView(),0)),this.options.trackOutgoingLinks&&this.trackOutgoingLinks(),this.options.trackAttributes&&this.trackAttributes()}}debounce(t,n){clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(t,n)}isServer(){return typeof document>"u"}trackOutgoingLinks(){this.isServer()||document.addEventListener("click",t=>{let n=t.target,r=n.closest("a");if(r&&n){let i=r.getAttribute("href");if(i?.startsWith("http"))try{let s=new URL(i),a=window.location.hostname;s.hostname!==a&&super.track("link_out",{href:i,text:r.innerText||r.getAttribute("title")||n.getAttribute("alt")||n.getAttribute("title")})}catch{}}})}trackScreenViews(){if(this.isServer())return;let t=history.pushState;history.pushState=function(...s){let a=t.apply(this,s);return window.dispatchEvent(new Event("pushstate")),window.dispatchEvent(new Event("locationchange")),a};let n=history.replaceState;history.replaceState=function(...s){let a=n.apply(this,s);return window.dispatchEvent(new Event("replacestate")),window.dispatchEvent(new Event("locationchange")),a},window.addEventListener("popstate",()=>{window.dispatchEvent(new Event("locationchange"))});let r=()=>this.debounce(()=>this.screenView(),50);this.options.trackHashChanges?window.addEventListener("hashchange",r):window.addEventListener("locationchange",r)}trackAttributes(){this.isServer()||document.addEventListener("click",t=>{let n=t.target,r=n.closest("button"),i=n.closest("a"),s=r?.getAttribute("data-track")?r:i?.getAttribute("data-track")?i:null;if(s){let a={};for(let p of s.attributes)p.name.startsWith("data-")&&p.name!=="data-track"&&(a[h(p.name.replace(/^data-/,""))]=p.value);let u=s.getAttribute("data-track");u&&super.track(u,a)}})}screenView(t,n){if(this.isServer())return;let r,i;typeof t=="string"?(r=t,i=n):(r=window.location.href,i=t),this.lastPath!==r&&(this.lastPath=r,console.log("OpenPanel.dev - Track page view"),super.track("screen_view",{...i??{},__path:r,__title:document.title}))}async flushRevenue(){let t=this.pendingRevenues.map(n=>super.revenue(n.amount,n.properties));await Promise.all(t),this.clearRevenue()}clearRevenue(){if(this.pendingRevenues=[],!this.isServer())try{sessionStorage.removeItem("openpanel-pending-revenues")}catch{}}pendingRevenue(t,n){if(this.pendingRevenues.push({amount:t,properties:n}),!this.isServer())try{sessionStorage.setItem("openpanel-pending-revenues",JSON.stringify(this.pendingRevenues))}catch{}}};(o=>{if(o.op){let e=o.op.q||[],t=new d(e.shift()[1]);e.forEach(r=>{r[0]in t&&t[r[0]](...r.slice(1))});let n=new Proxy((r,...i)=>{let s=t[r]?t[r].bind(t):void 0;typeof s=="function"?s(...i):console.warn(`OpenPanel: ${r} is not a function`)},{get(r,i){if(i==="q")return;let s=t[i];return typeof s=="function"?s.bind(t):s}});o.op=n,o.openpanel=t}})(window);})();diff --git a/packages/sdks/astro/package.json b/packages/sdks/astro/package.jsonindex 83163a437..ce1e376fa 100644--- a/packages/sdks/astro/package.json+++ b/packages/sdks/astro/package.json@@ -1,6 +1,6 @@{"name": "@openpanel/astro",- "version": "1.0.3-local",+ "version": "1.0.4-local","config": {"transformPackageJson": false,"transformEnvs": true@@ -14,7 +14,7 @@"files": ["src", "index.ts"],"keywords": ["astro-component"],"dependencies": {- "@openpanel/web": "workspace:1.0.3-local"+ "@openpanel/web": "workspace:1.0.4-local"},"devDependencies": {"astro": "^5.7.7"diff --git a/packages/sdks/astro/src/OpenPanelComponent.astro b/packages/sdks/astro/src/OpenPanelComponent.astroindex 3972c1924..dcb06ed47 100644--- a/packages/sdks/astro/src/OpenPanelComponent.astro+++ b/packages/sdks/astro/src/OpenPanelComponent.astro@@ -33,7 +33,7 @@ const methods: { name: OpenPanelMethodNames; value: unknown }[] = [value: {...options,sdk: 'astro',- sdkVersion: '1.0.3',+ sdkVersion: '1.0.4',},},];diff --git a/packages/sdks/nextjs/package.json b/packages/sdks/nextjs/package.jsonindex 5b763654c..716478404 100644--- a/packages/sdks/nextjs/package.json+++ b/packages/sdks/nextjs/package.json@@ -1,13 +1,13 @@{"name": "@openpanel/nextjs",- "version": "1.0.16-local",+ "version": "1.0.17-local","module": "index.ts","scripts": {"build": "rm -rf dist && tsup","typecheck": "tsc --noEmit"},"dependencies": {- "@openpanel/web": "workspace:1.0.3-local"+ "@openpanel/web": "workspace:1.0.4-local"},"peerDependencies": {"next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",diff --git a/packages/sdks/web/package.json b/packages/sdks/web/package.jsonindex e7e1f32b7..95ba7e6d8 100644--- a/packages/sdks/web/package.json+++ b/packages/sdks/web/package.json@@ -1,6 +1,6 @@{"name": "@openpanel/web",- "version": "1.0.3-local",+ "version": "1.0.4-local","module": "index.ts","scripts": {"build": "rm -rf dist && tsup",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex a48c83b6e..12acdf499 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -275,8 +275,8 @@ importers:specifier: workspace:*version: link:../../packages/common'@openpanel/nextjs':- specifier: ^1.0.15- version: 1.0.15([email protected](@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])+ specifier: ^1.0.17+ version: 1.0.17([email protected](@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])'@openpanel/payments':specifier: workspace:^version: link:../../packages/payments@@ -1404,7 +1404,7 @@ importers:packages/sdks/astro:dependencies:'@openpanel/web':- specifier: workspace:1.0.3-local+ specifier: workspace:1.0.4-localversion: link:../webdevDependencies:astro:@@ -1442,7 +1442,7 @@ importers:packages/sdks/nextjs:dependencies:'@openpanel/web':- specifier: workspace:1.0.3-local+ specifier: workspace:1.0.4-localversion: link:../webnext:specifier: ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0@@ -4796,8 +4796,8 @@ packages:resolution: {integrity: sha512-T8TbSnGsxo6TDBJx/Sgv/BlVJL3tshxZP7Aq5R1mSnM5OcHY2dQaxLMu2+E8u3gN0MLOzdjurqN4ZRVuzQycOQ==}engines: {node: '>=8.0'}- '@openpanel/[email protected]':- resolution: {integrity: sha512-qc8CKcQ5i7+EANDBZ7yRixDZHd2S7C379UcplH7b58gcLexkp3LRlhw3Y/ujPX1hnE28QkoPY5As+n7H6OBZ7g==}+ '@openpanel/[email protected]':+ resolution: {integrity: sha512-vH1PHlO43WJq2wOpQ36kxvWqsht6S26HHC/NyjA9uPVGAptYlXqVJi4fx5MI79azTaGMZzuxmW2yXAJhy9gjhQ==}peerDependencies:next: ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0@@ -4806,11 +4806,14 @@ packages:'@openpanel/[email protected]':resolution: {integrity: sha512-FNmmfjdXoC/VHEjA+WkrQ4lyM5lxEmV7xDd57uj4E+lIS0sU3DLG2mV/dpS8AscnZbUvuMn3kPhiLCqYzuv/gg==}+ '@openpanel/[email protected]':+ resolution: {integrity: sha512-9YQlrEnmqyr5u+y+MRE/pHYnrtV/oInPJZclVqVDiiQyEL4GmpaU/ZAbJPNVln7ZPw4i5Voj7vrlVY3rlbWfyw==}+'@openpanel/[email protected]':resolution: {integrity: sha512-cVZ7Kr9SicczJ/RDIfEtZs8+1iGDzwkabVA/j3NqSl8VSucsC8m1+LVbjmCDzCJNnK4yVn6tEcc9PJRi2rtllw==}- '@openpanel/[email protected]':- resolution: {integrity: sha512-vU9Z9Kc0dxyE4abTi9KAu2zDE2/z4RDcHDLk9NwNRgrZGDlYereOatwKNnvrwfU96066bjfOrSd+vbjmkmsOoA==}+ '@openpanel/[email protected]':+ resolution: {integrity: sha512-wEmVXAk6K5hRO/2KJc7GSrt6V8YhzmzntyLkEPshysnFMsWLNFDYUdu11sNy+Wn0cEb4HKDv/Nn34wNLJX0ydw==}'@openstatus/[email protected]':resolution: {integrity: sha512-uDiegz7e3H67pG8lTT+op+6w5keTT7XpcENrREaqlWl5j53TYyO8nheOG1PeNw2/Qgd5KaGeRJJFn1crhTUSYw==}@@ -5300,6 +5303,7 @@ packages:'@opentelemetry/[email protected]':resolution: {integrity: sha512-gxxxwfk0inDMb5DLeuxQ3L8TtptxSiTNHE4nnAJH34IQXAVRhXSXW1rK8PmDKDngRPIZ6J7ncUCjjIn8b+AgqQ==}engines: {node: '>=14'}+ deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.peerDependencies:'@opentelemetry/api': ^1.0.0@@ -13470,6 +13474,7 @@ packages:resolution: {integrity: sha512-X0jWUcAlxORhOqqBREgPMgnshB7ZGYszBNspP+tS9hPD3l13CdaXcHbgImoHUHlrvGx/7AvFEkTRhAGYh+jzjQ==}+ deprecated: use oniguruma-to-es insteadresolution: {integrity: sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==}@@ -19879,22 +19884,24 @@ snapshots:'@oozcitak/[email protected]': {}- '@openpanel/[email protected]([email protected](@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])':+ '@openpanel/[email protected]([email protected](@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])':dependencies:- '@openpanel/web': 1.0.2+ '@openpanel/web': 1.0.4next: 15.0.3(@opentelemetry/[email protected])([email protected]([email protected]))([email protected])react: 19.1.1react-dom: 19.1.1([email protected])'@openpanel/[email protected]': {}+ '@openpanel/[email protected]': {}+'@openpanel/[email protected]':dependencies:'@openpanel/sdk': 1.0.0- '@openpanel/[email protected]':+ '@openpanel/[email protected]':dependencies:- '@openpanel/sdk': 1.0.0+ '@openpanel/sdk': 1.0.1'@openstatus/[email protected]([email protected])':dependencies: