@onramp-sdk/web 0.7.0 → 0.7.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.
- package/dist/onramp.min.js +1 -1
- package/package.json +2 -2
package/dist/onramp.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var te=Object.create;var D=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var m=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var oe=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ie(e))!re.call(t,s)&&s!==n&&D(t,s,{get:()=>e[s],enumerable:!(i=ne(e,s))||i.enumerable});return t};var ue=(t,e,n)=>(n=t!=null?te(se(t)):{},oe(e||!t||!t.__esModule?D(n,"default",{value:t,enumerable:!0}):n,t));var k=m(j=>{"use strict";Object.defineProperty(j,"__esModule",{value:!0})});var K=m(U=>{"use strict";Object.defineProperty(U,"__esModule",{value:!0})});var H=m(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.API_KEY_HEADER=c.INGEST_ROUTE=c.MAX_EVENTS_PER_BATCH=c.SCHEMA_VERSION=void 0;c.SCHEMA_VERSION="1.0";c.MAX_EVENTS_PER_BATCH=50;c.INGEST_ROUTE="/v1/events";c.API_KEY_HEADER="x-onramp-key"});var E=m(f=>{"use strict";var ae=f&&f.__createBinding||(Object.create?(function(t,e,n,i){i===void 0&&(i=n);var s=Object.getOwnPropertyDescriptor(e,n);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,i,s)}):(function(t,e,n,i){i===void 0&&(i=n),t[i]=e[n]})),I=f&&f.__exportStar||function(t,e){for(var n in t)n!=="default"&&!Object.prototype.hasOwnProperty.call(e,n)&&ae(e,t,n)};Object.defineProperty(f,"__esModule",{value:!0});I(k(),f);I(K(),f);I(H(),f)});var T=m(b=>{"use strict";Object.defineProperty(b,"__esModule",{value:!0});b.BatchQueue=void 0;var O=E(),ce=3,le=1e3,R=class{queue=[];timer=null;retryTimer=null;retryCount=0;sending=!1;flushIntervalMs;flushFn;constructor(e,n=5e3){this.flushFn=e,this.flushIntervalMs=n}push(e){this.queue.push(e),this.queue.length>=O.MAX_EVENTS_PER_BATCH?this.sendWhenReady():!this.timer&&!this.retryTimer&&(this.timer=setTimeout(()=>this.sendWhenReady(),this.flushIntervalMs))}async flushNow(){for(this.cancelTimers();this.queue.length>0;){let e=this.queue.splice(0,O.MAX_EVENTS_PER_BATCH);await this.flushFn(e).catch(()=>{})}}destroy(){this.cancelTimers()}sendWhenReady(){this.sending||(this.cancelTimers(),this.trySend())}async trySend(){if(this.sending||this.queue.length===0)return;this.sending=!0;let e=this.queue.splice(0,O.MAX_EVENTS_PER_BATCH);try{await this.flushFn(e),this.retryCount=0,this.queue.length>0&&!this.timer&&(this.timer=setTimeout(()=>this.sendWhenReady(),this.flushIntervalMs))}catch{if(this.queue.unshift(...e),this.retryCount<ce){let n=le*2**this.retryCount;this.retryCount++,this.retryTimer=setTimeout(()=>this.sendWhenReady(),n)}else this.queue.splice(0,e.length),this.retryCount=0}finally{this.sending=!1}}cancelTimers(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)}};b.BatchQueue=R});var B=m(w=>{"use strict";Object.defineProperty(w,"__esModule",{value:!0});w.OnRampClient=void 0;var de=T(),_=E(),A=class{config;queue;constructor(e){this.config={host:"https://ingest.getonramp.dev",platform:"other",framework:null,appVersion:null,flushIntervalMs:5e3,...e},this.queue=new de.BatchQueue(this.sendBatch.bind(this),this.config.flushIntervalMs)}track(e){let n={schema_version:_.SCHEMA_VERSION,event_id:this.config.uuidFn(),event_type:e.eventType??"step_entered",app_key:this.config.apiKey,session_id:e.sessionId,anonymous_id:e.anonymousId,step_name:e.stepName,step_index:e.stepIndex,client_timestamp_ms:Date.now(),platform:this.config.platform,os_version:e.osVersion??null,app_version:this.config.appVersion,device_model:e.deviceModel??null,device_type:e.deviceType??null,properties:this.config.framework?{_framework:this.config.framework,...e.properties}:e.properties??null};this.queue.push(n)}identify(e){let n={schema_version:_.SCHEMA_VERSION,event_id:this.config.uuidFn(),event_type:"identify",app_key:this.config.apiKey,session_id:e.sessionId,anonymous_id:e.anonymousId,step_name:"_identify",step_index:0,client_timestamp_ms:Date.now(),platform:this.config.platform,os_version:null,app_version:this.config.appVersion,device_model:null,device_type:null,properties:e.traits};this.queue.push(n)}flush(){return this.queue.flushNow()}beacon(e){if(typeof fetch>"u")return;let n={schema_version:_.SCHEMA_VERSION,event_id:this.config.uuidFn(),event_type:"heartbeat",app_key:this.config.apiKey,session_id:e.sessionId,anonymous_id:e.anonymousId,step_name:"_heartbeat",step_index:0,client_timestamp_ms:Date.now(),platform:this.config.platform,os_version:null,app_version:this.config.appVersion,device_model:null,device_type:null,properties:null};fetch(`${this.config.host}${_.INGEST_ROUTE}`,{method:"POST",headers:{"Content-Type":"application/json",[_.API_KEY_HEADER]:this.config.apiKey},body:JSON.stringify({events:[n]}),keepalive:!0}).catch(()=>{})}destroy(){this.queue.destroy()}async sendBatch(e){let n=`${this.config.host}${_.INGEST_ROUTE}`,i=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",[_.API_KEY_HEADER]:this.config.apiKey},body:JSON.stringify({events:e})});if(!i.ok)throw new Error(`Ingest failed: ${i.status}`)}};w.OnRampClient=A});var F=m(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.BatchQueue=g.OnRampClient=void 0;var fe=B();Object.defineProperty(g,"OnRampClient",{enumerable:!0,get:function(){return fe.OnRampClient}});var he=T();Object.defineProperty(g,"BatchQueue",{enumerable:!0,get:function(){return he.BatchQueue}})});var X=ue(F()),x="@onramp/anonymous_id",G="@onramp/session",y="@onramp/pending_acquisition",Y=1800*1e3,pe=365*24*60*60*1e3;function V(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function Q(t){try{return localStorage.getItem(t)}catch{return null}}function N(t,e){try{localStorage.setItem(t,e)}catch{}}function me(t){let e=Q(x);if(e)try{let i=JSON.parse(e);if(Date.now()-i.createdAt<t)return i.id}catch{let i={id:e,createdAt:Date.now()};return N(x,JSON.stringify(i)),i.id}let n={id:V(),createdAt:Date.now()};return N(x,JSON.stringify(n)),n.id}function _e(){let t=Q(G);if(!t)return null;try{return JSON.parse(t)}catch{return null}}function v(){o&&N(G,JSON.stringify({id:o,lastActive:p,stepCounter:S}))}function P(){o=V(),S=0,p=Date.now(),v()}function M(){(!o||Date.now()-p>C)&&P()}function $(){if(typeof navigator>"u")return{osVersion:"web",browser:""};let t=navigator.userAgent,e="web",n="";if(/iPad/.test(t))e="ipados",n=(t.match(/OS (\d+[_.]\d+)/)??[])[1]?.replace("_",".")??"";else if(/iPhone|iPod/.test(t))e="ios",n=(t.match(/OS (\d+[_.]\d+)/)??[])[1]?.replace("_",".")??"";else if(/Android (\d+\.?\d*)/.test(t))e="android",n=(t.match(/Android (\d+\.?\d*)/)??[])[1]??"";else if(/Windows NT (\d+\.\d+)/.test(t)){e="windows";let s=(t.match(/Windows NT (\d+\.\d+)/)??[])[1]??"";n={"10.0":"10","6.3":"8.1","6.2":"8","6.1":"7"}[s]??s}else/Mac OS X (\d+[_.]\d+)/.test(t)?(e="macos",n=(t.match(/Mac OS X (\d+[_.]\d+)/)??[])[1]?.replace("_",".")??""):/Linux/.test(t)&&(e="linux");let i="";return/Edg\/(\d+)/.test(t)?i=`Edge ${(t.match(/Edg\/(\d+)/)??[])[1]??""}`:/OPR\/(\d+)/.test(t)?i=`Opera ${(t.match(/OPR\/(\d+)/)??[])[1]??""}`:/Firefox\/(\d+)/.test(t)?i=`Firefox ${(t.match(/Firefox\/(\d+)/)??[])[1]??""}`:/Chrome\/(\d+)/.test(t)?i=`Chrome ${(t.match(/Chrome\/(\d+)/)??[])[1]??""}`:/Version\/(\d+).*Safari/.test(t)?i=`Safari ${(t.match(/Version\/(\d+)/)??[])[1]??""}`:/Safari\//.test(t)&&(i="Safari"),{osVersion:n?`${e} ${n}`:e,browser:i}}function L(){if(typeof navigator>"u")return"desktop";let t=navigator.userAgent;return/iPad|Tablet|(Android(?!.*Mobile))/i.test(t)?"tablet":/Mobi|Android|iPhone|iPod/i.test(t)?"phone":"desktop"}var u=null,o=null,l=null,S=0,p=0,J=0,C=Y,a=null,d=null;function ge(t){try{return sessionStorage.getItem(t)}catch{return null}}function W(t,e){try{sessionStorage.setItem(t,e)}catch{}}function z(t){try{sessionStorage.removeItem(t)}catch{}}var ye=[["gclid","google","cpc"],["gbraid","google","cpc"],["wbraid","google","cpc"],["msclkid","bing","cpc"],["ttclid","tiktok","cpc"],["twclid","twitter","cpc"],["li_fat_id","linkedin","cpc"],["fbclid","facebook","social"]];function ve(t){for(let[e,n,i]of ye)if(t.get(e))return{_utm_source:n,_utm_medium:i};return null}function Se(t){if(a=null,d=null,document.referrer)try{new URL(document.referrer).origin!==window.location.origin&&(a=document.referrer)}catch{a=document.referrer}let e=new URLSearchParams(window.location.search),n=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],i={};for(let r of n){let h=e.get(r);h&&(i[`_${r}`]=h)}if(Object.keys(i).length>0?d=i:d=ve(e),a||d){W(y,JSON.stringify({referrer:a,utm:d}));return}let s=ge(y);if(!s){t&&(a="direct"),a&&W(y,JSON.stringify({referrer:a,utm:null}));return}try{let r=JSON.parse(s);a=r.referrer,d=r.utm}catch{z(y)}}var Z={init(t){if(typeof window>"u")return;C=t.sessionTimeoutMs??Y,l=me(t.anonymousIdMaxAgeMs??pe);let e=_e(),n=!(e&&Date.now()-e.lastActive<C);!n&&e?(o=e.id,S=e.stepCounter,p=e.lastActive):P(),Se(n),u=new X.OnRampClient({apiKey:t.apiKey,host:t.host,platform:"web",appVersion:t.appVersion??null,uuidFn:V});function i(){if(!u||!o||!l)return;let s=Date.now();s-J<500||(J=s,u.beacon({sessionId:o,anonymousId:l}))}window.addEventListener("pagehide",()=>{p=Date.now(),v(),i(),u?.flush()}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"?(p=Date.now(),v(),i(),u?.flush()):M()}),setInterval(()=>{document.visibilityState!=="hidden"&&i()},5e3),document.addEventListener("click",s=>{let r=s.target?.closest?.("a");if(!r)return;let h=r.getAttribute("href")??"";if(!(!h||h.startsWith("#")||h.startsWith("mailto:")||h.startsWith("tel:")))try{let q=new URL(h,window.location.href);if(q.hostname===window.location.hostname||!u||!o||!l)return;M();let ee=S++;p=Date.now(),v(),u.track({sessionId:o,anonymousId:l,eventType:"nav_entered",stepName:q.href.slice(0,128),stepIndex:ee,osVersion:$().osVersion,deviceType:L(),properties:null})}catch{}},{capture:!0,passive:!0})},step(t,e){if(!u||!o||!l){console.warn("[OnRamp] call OnRamp.init() before tracking steps");return}M();let n=S++;p=Date.now(),v();let{osVersion:i,browser:s}=$(),r={};s&&(r._browser=s),a&&(r._referrer=a),d&&Object.assign(r,d),(a||d)&&(a=null,d=null,z(y)),u.track({sessionId:o,anonymousId:l,stepName:t,stepIndex:n,osVersion:i,deviceType:L(),properties:Object.keys(r).length||e?.properties?{...r,...e?.properties}:null})},identify(t){if(!u||!o||!l){console.warn("[OnRamp] call OnRamp.init() before calling identify()");return}u.identify({sessionId:o,anonymousId:l,traits:t})},newSession(){P()},flush(){return u?.flush()??Promise.resolve()},getIds(){return{anonymousId:l,sessionId:o}},get isInitialized(){return u!==null}};globalThis.OnRamp=Z;})();
|
|
1
|
+
"use strict";(()=>{var te=Object.create;var D=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var m=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var oe=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ie(e))!re.call(t,s)&&s!==n&&D(t,s,{get:()=>e[s],enumerable:!(i=ne(e,s))||i.enumerable});return t};var ue=(t,e,n)=>(n=t!=null?te(se(t)):{},oe(e||!t||!t.__esModule?D(n,"default",{value:t,enumerable:!0}):n,t));var k=m(j=>{"use strict";Object.defineProperty(j,"__esModule",{value:!0})});var K=m(U=>{"use strict";Object.defineProperty(U,"__esModule",{value:!0})});var H=m(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.API_KEY_HEADER=c.INGEST_ROUTE=c.MAX_EVENTS_PER_BATCH=c.SCHEMA_VERSION=void 0;c.SCHEMA_VERSION="1.0";c.MAX_EVENTS_PER_BATCH=50;c.INGEST_ROUTE="/v1/events";c.API_KEY_HEADER="x-onramp-key"});var E=m(f=>{"use strict";var ae=f&&f.__createBinding||(Object.create?(function(t,e,n,i){i===void 0&&(i=n);var s=Object.getOwnPropertyDescriptor(e,n);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,i,s)}):(function(t,e,n,i){i===void 0&&(i=n),t[i]=e[n]})),I=f&&f.__exportStar||function(t,e){for(var n in t)n!=="default"&&!Object.prototype.hasOwnProperty.call(e,n)&&ae(e,t,n)};Object.defineProperty(f,"__esModule",{value:!0});I(k(),f);I(K(),f);I(H(),f)});var T=m(b=>{"use strict";Object.defineProperty(b,"__esModule",{value:!0});b.BatchQueue=void 0;var O=E(),ce=3,le=1e3,R=class{queue=[];timer=null;retryTimer=null;retryCount=0;sending=!1;flushIntervalMs;flushFn;constructor(e,n=5e3){this.flushFn=e,this.flushIntervalMs=n}push(e){this.queue.push(e),this.queue.length>=O.MAX_EVENTS_PER_BATCH?this.sendWhenReady():!this.timer&&!this.retryTimer&&(this.timer=setTimeout(()=>this.sendWhenReady(),this.flushIntervalMs))}async flushNow(){for(this.cancelTimers();this.queue.length>0;){let e=this.queue.splice(0,O.MAX_EVENTS_PER_BATCH);await this.flushFn(e).catch(()=>{})}}destroy(){this.cancelTimers()}sendWhenReady(){this.sending||(this.cancelTimers(),this.trySend())}async trySend(){if(this.sending||this.queue.length===0)return;this.sending=!0;let e=this.queue.splice(0,O.MAX_EVENTS_PER_BATCH);try{await this.flushFn(e),this.retryCount=0,this.queue.length>0&&!this.timer&&(this.timer=setTimeout(()=>this.sendWhenReady(),this.flushIntervalMs))}catch{if(this.queue.unshift(...e),this.retryCount<ce){let n=le*2**this.retryCount;this.retryCount++,this.retryTimer=setTimeout(()=>this.sendWhenReady(),n)}else this.queue.splice(0,e.length),this.retryCount=0}finally{this.sending=!1}}cancelTimers(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)}};b.BatchQueue=R});var B=m(w=>{"use strict";Object.defineProperty(w,"__esModule",{value:!0});w.OnRampClient=void 0;var de=T(),_=E(),A=class{config;queue;constructor(e){this.config={...e,host:e.host??"https://ingest.getonramp.dev",platform:e.platform??"other",framework:e.framework??null,appVersion:e.appVersion??null,flushIntervalMs:e.flushIntervalMs??5e3},this.queue=new de.BatchQueue(this.sendBatch.bind(this),this.config.flushIntervalMs)}track(e){let n={schema_version:_.SCHEMA_VERSION,event_id:this.config.uuidFn(),event_type:e.eventType??"step_entered",app_key:this.config.apiKey,session_id:e.sessionId,anonymous_id:e.anonymousId,step_name:e.stepName,step_index:e.stepIndex,client_timestamp_ms:Date.now(),platform:this.config.platform,os_version:e.osVersion??null,app_version:this.config.appVersion,device_model:e.deviceModel??null,device_type:e.deviceType??null,properties:this.config.framework?{_framework:this.config.framework,...e.properties}:e.properties??null};this.queue.push(n)}identify(e){let n={schema_version:_.SCHEMA_VERSION,event_id:this.config.uuidFn(),event_type:"identify",app_key:this.config.apiKey,session_id:e.sessionId,anonymous_id:e.anonymousId,step_name:"_identify",step_index:0,client_timestamp_ms:Date.now(),platform:this.config.platform,os_version:null,app_version:this.config.appVersion,device_model:null,device_type:null,properties:e.traits};this.queue.push(n)}flush(){return this.queue.flushNow()}beacon(e){if(typeof fetch>"u")return;let n={schema_version:_.SCHEMA_VERSION,event_id:this.config.uuidFn(),event_type:"heartbeat",app_key:this.config.apiKey,session_id:e.sessionId,anonymous_id:e.anonymousId,step_name:"_heartbeat",step_index:0,client_timestamp_ms:Date.now(),platform:this.config.platform,os_version:null,app_version:this.config.appVersion,device_model:null,device_type:null,properties:null};fetch(`${this.config.host}${_.INGEST_ROUTE}`,{method:"POST",headers:{"Content-Type":"application/json",[_.API_KEY_HEADER]:this.config.apiKey},body:JSON.stringify({events:[n]}),keepalive:!0}).catch(()=>{})}destroy(){this.queue.destroy()}async sendBatch(e){let n=`${this.config.host}${_.INGEST_ROUTE}`,i=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",[_.API_KEY_HEADER]:this.config.apiKey},body:JSON.stringify({events:e})});if(!i.ok)throw new Error(`Ingest failed: ${i.status}`)}};w.OnRampClient=A});var F=m(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.BatchQueue=g.OnRampClient=void 0;var fe=B();Object.defineProperty(g,"OnRampClient",{enumerable:!0,get:function(){return fe.OnRampClient}});var he=T();Object.defineProperty(g,"BatchQueue",{enumerable:!0,get:function(){return he.BatchQueue}})});var X=ue(F()),x="@onramp/anonymous_id",G="@onramp/session",y="@onramp/pending_acquisition",Y=1800*1e3,pe=365*24*60*60*1e3;function V(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function Q(t){try{return localStorage.getItem(t)}catch{return null}}function N(t,e){try{localStorage.setItem(t,e)}catch{}}function me(t){let e=Q(x);if(e)try{let i=JSON.parse(e);if(Date.now()-i.createdAt<t)return i.id}catch{let i={id:e,createdAt:Date.now()};return N(x,JSON.stringify(i)),i.id}let n={id:V(),createdAt:Date.now()};return N(x,JSON.stringify(n)),n.id}function _e(){let t=Q(G);if(!t)return null;try{return JSON.parse(t)}catch{return null}}function v(){o&&N(G,JSON.stringify({id:o,lastActive:p,stepCounter:S}))}function P(){o=V(),S=0,p=Date.now(),v()}function M(){(!o||Date.now()-p>C)&&P()}function $(){if(typeof navigator>"u")return{osVersion:"web",browser:""};let t=navigator.userAgent,e="web",n="";if(/iPad/.test(t))e="ipados",n=(t.match(/OS (\d+[_.]\d+)/)??[])[1]?.replace("_",".")??"";else if(/iPhone|iPod/.test(t))e="ios",n=(t.match(/OS (\d+[_.]\d+)/)??[])[1]?.replace("_",".")??"";else if(/Android (\d+\.?\d*)/.test(t))e="android",n=(t.match(/Android (\d+\.?\d*)/)??[])[1]??"";else if(/Windows NT (\d+\.\d+)/.test(t)){e="windows";let s=(t.match(/Windows NT (\d+\.\d+)/)??[])[1]??"";n={"10.0":"10","6.3":"8.1","6.2":"8","6.1":"7"}[s]??s}else/Mac OS X (\d+[_.]\d+)/.test(t)?(e="macos",n=(t.match(/Mac OS X (\d+[_.]\d+)/)??[])[1]?.replace("_",".")??""):/Linux/.test(t)&&(e="linux");let i="";return/Edg\/(\d+)/.test(t)?i=`Edge ${(t.match(/Edg\/(\d+)/)??[])[1]??""}`:/OPR\/(\d+)/.test(t)?i=`Opera ${(t.match(/OPR\/(\d+)/)??[])[1]??""}`:/Firefox\/(\d+)/.test(t)?i=`Firefox ${(t.match(/Firefox\/(\d+)/)??[])[1]??""}`:/Chrome\/(\d+)/.test(t)?i=`Chrome ${(t.match(/Chrome\/(\d+)/)??[])[1]??""}`:/Version\/(\d+).*Safari/.test(t)?i=`Safari ${(t.match(/Version\/(\d+)/)??[])[1]??""}`:/Safari\//.test(t)&&(i="Safari"),{osVersion:n?`${e} ${n}`:e,browser:i}}function L(){if(typeof navigator>"u")return"desktop";let t=navigator.userAgent;return/iPad|Tablet|(Android(?!.*Mobile))/i.test(t)?"tablet":/Mobi|Android|iPhone|iPod/i.test(t)?"phone":"desktop"}var u=null,o=null,l=null,S=0,p=0,J=0,C=Y,a=null,d=null;function ge(t){try{return sessionStorage.getItem(t)}catch{return null}}function W(t,e){try{sessionStorage.setItem(t,e)}catch{}}function z(t){try{sessionStorage.removeItem(t)}catch{}}var ye=[["gclid","google","cpc"],["gbraid","google","cpc"],["wbraid","google","cpc"],["msclkid","bing","cpc"],["ttclid","tiktok","cpc"],["twclid","twitter","cpc"],["li_fat_id","linkedin","cpc"],["fbclid","facebook","social"]];function ve(t){for(let[e,n,i]of ye)if(t.get(e))return{_utm_source:n,_utm_medium:i};return null}function Se(t){if(a=null,d=null,document.referrer)try{new URL(document.referrer).origin!==window.location.origin&&(a=document.referrer)}catch{a=document.referrer}let e=new URLSearchParams(window.location.search),n=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],i={};for(let r of n){let h=e.get(r);h&&(i[`_${r}`]=h)}if(Object.keys(i).length>0?d=i:d=ve(e),a||d){W(y,JSON.stringify({referrer:a,utm:d}));return}let s=ge(y);if(!s){t&&(a="direct"),a&&W(y,JSON.stringify({referrer:a,utm:null}));return}try{let r=JSON.parse(s);a=r.referrer,d=r.utm}catch{z(y)}}var Z={init(t){if(typeof window>"u")return;C=t.sessionTimeoutMs??Y,l=me(t.anonymousIdMaxAgeMs??pe);let e=_e(),n=!(e&&Date.now()-e.lastActive<C);!n&&e?(o=e.id,S=e.stepCounter,p=e.lastActive):P(),Se(n),u=new X.OnRampClient({apiKey:t.apiKey,host:t.host,platform:"web",appVersion:t.appVersion??null,uuidFn:V});function i(){if(!u||!o||!l)return;let s=Date.now();s-J<500||(J=s,u.beacon({sessionId:o,anonymousId:l}))}window.addEventListener("pagehide",()=>{p=Date.now(),v(),i(),u?.flush()}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"?(p=Date.now(),v(),i(),u?.flush()):M()}),setInterval(()=>{document.visibilityState!=="hidden"&&i()},5e3),document.addEventListener("click",s=>{let r=s.target?.closest?.("a");if(!r)return;let h=r.getAttribute("href")??"";if(!(!h||h.startsWith("#")||h.startsWith("mailto:")||h.startsWith("tel:")))try{let q=new URL(h,window.location.href);if(q.hostname===window.location.hostname||!u||!o||!l)return;M();let ee=S++;p=Date.now(),v(),u.track({sessionId:o,anonymousId:l,eventType:"nav_entered",stepName:q.href.slice(0,128),stepIndex:ee,osVersion:$().osVersion,deviceType:L(),properties:null})}catch{}},{capture:!0,passive:!0})},step(t,e){if(!u||!o||!l){console.warn("[OnRamp] call OnRamp.init() before tracking steps");return}M();let n=S++;p=Date.now(),v();let{osVersion:i,browser:s}=$(),r={};s&&(r._browser=s),a&&(r._referrer=a),d&&Object.assign(r,d),(a||d)&&(a=null,d=null,z(y)),u.track({sessionId:o,anonymousId:l,stepName:t,stepIndex:n,osVersion:i,deviceType:L(),properties:Object.keys(r).length||e?.properties?{...r,...e?.properties}:null})},identify(t){if(!u||!o||!l){console.warn("[OnRamp] call OnRamp.init() before calling identify()");return}u.identify({sessionId:o,anonymousId:l,traits:t})},newSession(){P()},flush(){return u?.flush()??Promise.resolve()},getIds(){return{anonymousId:l,sessionId:o}},get isInitialized(){return u!==null}};globalThis.OnRamp=Z;})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onramp-sdk/web",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "OnRamp Analytics SDK for web apps - track onboarding steps and see where users drop off.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@onramp-sdk/core": "0.6.
|
|
37
|
+
"@onramp-sdk/core": "0.6.3",
|
|
38
38
|
"@onramp-sdk/shared": "0.4.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|