@axceera/playstep-analytics 0.11.3 → 0.11.4
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/README.md +3 -1
- package/dist/index.js +1 -1
- package/dist/react.js +1 -1
- package/dist/{src-DzSCbLW0.js → src-CcBXBGlb.js} +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -50,4 +50,6 @@ go. `playstep.reset()` forgets the user, the device and those properties too. Sc
|
|
|
50
50
|
About 3.5 KB gzipped from npm (the event queue comes from `@axceera/playstep`), 4.2 KB as the script tag.
|
|
51
51
|
|
|
52
52
|
A page view takes the title the page has half a second after the URL changes, since single-page apps set it after
|
|
53
|
-
navigating
|
|
53
|
+
navigating, and again at 1.5 s for a page that loads first and sets it later (the one after signing in, say). Batches go
|
|
54
|
+
3 seconds after their first event, so the title is in before it is sent. Calling `identify()` again for the same user
|
|
55
|
+
sends `$identify` only when the traits changed.
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as analytics}from"./src-
|
|
1
|
+
export{t as analytics}from"./src-CcBXBGlb.js";
|
package/dist/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./src-
|
|
1
|
+
import{t as e}from"./src-CcBXBGlb.js";import{playstep as t}from"@axceera/playstep";function n(n){return e(t,n)}export{n as useInsights};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createQueue as e,store as t}from"@axceera/playstep/plugin";const n=/^(:|radix-|headlessui-|react-|ember\d|mui-|v-|css-|sc-|jsx-)|\d{3,}|[a-f0-9]{8,}|__/i,r=/active|selected|current|open|hover|focus|disabled|hidden|show|visible|checked|loading/i,i=e=>`"${e.replace(/["\\]/g,`\\$&`)}"`,a=e=>CSS.escape(e);function o(e,t){try{return e.querySelectorAll(t).length===1}catch{return!1}}function s(e){let t=e.getAttribute(`role`),n=e.tagName,r=(e.getAttribute(`type`)??``).toLowerCase();return t===`tab`||t===`menuitem`||t===`link`||t===`button`?t:t===`checkbox`||t===`switch`||n===`INPUT`&&(r===`checkbox`||r===`radio`)?`checkbox`:n===`A`?`link`:n===`BUTTON`||n===`SUMMARY`||n===`INPUT`&&/^(submit|button|reset|image)$/.test(r)?`button`:n===`SELECT`?`select`:n===`INPUT`||n===`TEXTAREA`?`input`:`other`}function c(e){let t=e.ownerDocument,s=e.tagName.toLowerCase(),c=[];e.id&&!n.test(e.id)&&c.push(`#${a(e.id)}`);for(let t of[`data-testid`,`data-test`,`data-cy`,`data-qa`]){let n=e.getAttribute(t);n&&c.push(`[${t}=${i(n)}]`)}for(let t of[`aria-label`,`name`,`title`,`placeholder`]){let n=e.getAttribute(t);n&&n.length<=80&&c.push(`${s}[${t}=${i(n)}]`)}let l=e.getAttribute(`href`);s===`a`&&l&&!/^javascript:|[?#]/i.test(l)&&l.length<=200&&c.push(`a[href=${i(l)}]`);let u=[...e.classList].filter(e=>/^[a-z][\w-]{1,40}$/i.test(e)&&!n.test(e)&&!r.test(e));u.length&&c.push(`${s}.${u.slice(0,3).map(a).join(`.`)}`);for(let e of c)if(o(t,e))return e;let d=[],f=e;for(;f&&d.length<7;){if(f===t.body){d.unshift(`body`);break}if(f!==e&&f.id&&!n.test(f.id)){d.unshift(`#${a(f.id)}`);break}let r=f.tagName.toLowerCase(),i=f.parentElement?[...f.parentElement.children].filter(e=>e.tagName===f.tagName):[];d.unshift(i.length>1?`${r}:nth-of-type(${i.indexOf(f)+1})`:r),f=f.parentElement}let p=d.join(`>`);return o(t,p)?p:void 0}function l(e){let t=e.getAttribute(`aria-label`)||e.getAttribute(`title`);if(t)return t;let n=e.getAttribute(`aria-labelledby`);if(n)return n.split(/\s+/).map(t=>e.ownerDocument.getElementById(t)?.textContent??``).join(` `);let r=e.labels;return r?.length?r[0].innerText:``}function u(e,t=[]){if(e.closest(`[data-private],[aria-hidden=true],[inert],[data-ps-no-capture],playstep-root,playstep-capture`))return!0;for(let n of t)try{if(e.closest(n))return!0}catch{}return!1}const d=()=>crypto.randomUUID(),f=async e=>`u_`+[...new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e)),0,20)].map(e=>e.toString(16).padStart(2,`0`)).join(``),p=e=>/^(string|number|boolean)$/.test(typeof e),m=e=>Object.keys(e).length,h=e=>(e??``).replace(/\s+/g,` `).trim().slice(0,80),g=e=>{try{localStorage.removeItem(`playstep:${e}`)}catch{}},_=()=>void 0;function v(e,t=!0){let n={};for(let r in e){let i=e[r];m(n)<50&&/^[A-Za-z_$][\w.:-]{0,63}$/.test(r)&&(i===null||p(i)||t&&Array.isArray(i)&&i.every(p))&&(n[r]=Array.isArray(i)?i.slice(0,25):i)}return n}function y(){let e={};for(let[t,n]of new URLSearchParams(location.search))t.startsWith(`utm_`)&&(e[t.slice(4)]=n);let t=document.referrer&&new URL(document.referrer);return{r:t&&t.host!=location.host?t.origin:void 0,u:m(e)?e:void 0}}function b(e,t,n,r){let i=``;if(n&&!e.matches(`input,select,textarea`)){i=e.innerText;for(let t of e.querySelectorAll(`*`)){let e=u(t,r)&&t.innerText;e&&(i=i.includes(e)?i.replace(e,``):``)}}let a=e.href;return{selector:c(e),text:n&&(h(i)||h(l(e)))||void 0,role:s(e),href:typeof a==`string`&&a.split(/[?#]/)[0]||void 0,x:t.pageX|0,y:t.pageY|0,vw:innerWidth,vh:innerHeight}}function x(n={}){let r,i=``,a,o,s=[],p,x,S,C=!1,w,T,E,D={},O,k={},A={},j=[],M=e=>{let n=t.get(`a:d`);return!n&&e&&t.set(`a:d`,n=`d_${d()}`),n},N=()=>r&&(T??(!w&&r.anonymous?M(!0):void 0)),P=()=>{let e=N();if(!e)return null;let n=t.get(`a:s`),o=e=>typeof e==`string`?e:void 0;return{v:1,key:i,sdk:a,actor:e,device:T&&M()||void 0,guide_key:E,traits:m(D)?D:void 0,user:r.identities&&w?{id:w,email:o(D.email),name:o(D.name)}:void 0,groups:m(k)?k:void 0,context:{platform:`web`,locale:navigator.language,referrer:n?.r,utm:n?.u}}};function F(e){let n=Date.now(),r=t.get(`a:s`);(!r||n-r.t>18e5)&&(r={id:d(),t:n,...y()},x.push({id:d(),name:`$session_start`,ts:e.ts,session:r.id})),r.t=n,t.set(`a:s`,r),x.push({...e,session:r.id})}let I=()=>p==`granted`&&N()&&j.splice(0).forEach(F);function L(e,t={}){if(!r||p==`denied`)return;let n={...A,...t.props},i={id:d(),name:e,ts:Date.now(),page:t.el&&O,...t,props:m(n)?n:void 0};p==`granted`&&N()?F(i):j.length<100&&w!==``&&j.push(i)}function R(e,t){let n=JSON.stringify(D)==JSON.stringify(D=v(t,!1));if(e==w&&e)return void(T&&!n&&L(`$identify`));if(x.flush(),w&&!e&&(j=[],g(`a:d`)),w=e||w&&``,T=E=void 0,!e)return void(k={});Promise.all([f(`${r.hash_key}:${e}`),f(`${i}:${e}`)]).then(t=>{w==e&&([T,E]=t,L(`$identify`),I())})}function z(e){let t=O={path:e};o.pages&&L(`$pageview`,{page:t})
|
|
1
|
+
import{createQueue as e,store as t}from"@axceera/playstep/plugin";const n=/^(:|radix-|headlessui-|react-|ember\d|mui-|v-|css-|sc-|jsx-)|\d{3,}|[a-f0-9]{8,}|__/i,r=/active|selected|current|open|hover|focus|disabled|hidden|show|visible|checked|loading/i,i=e=>`"${e.replace(/["\\]/g,`\\$&`)}"`,a=e=>CSS.escape(e);function o(e,t){try{return e.querySelectorAll(t).length===1}catch{return!1}}function s(e){let t=e.getAttribute(`role`),n=e.tagName,r=(e.getAttribute(`type`)??``).toLowerCase();return t===`tab`||t===`menuitem`||t===`link`||t===`button`?t:t===`checkbox`||t===`switch`||n===`INPUT`&&(r===`checkbox`||r===`radio`)?`checkbox`:n===`A`?`link`:n===`BUTTON`||n===`SUMMARY`||n===`INPUT`&&/^(submit|button|reset|image)$/.test(r)?`button`:n===`SELECT`?`select`:n===`INPUT`||n===`TEXTAREA`?`input`:`other`}function c(e){let t=e.ownerDocument,s=e.tagName.toLowerCase(),c=[];e.id&&!n.test(e.id)&&c.push(`#${a(e.id)}`);for(let t of[`data-testid`,`data-test`,`data-cy`,`data-qa`]){let n=e.getAttribute(t);n&&c.push(`[${t}=${i(n)}]`)}for(let t of[`aria-label`,`name`,`title`,`placeholder`]){let n=e.getAttribute(t);n&&n.length<=80&&c.push(`${s}[${t}=${i(n)}]`)}let l=e.getAttribute(`href`);s===`a`&&l&&!/^javascript:|[?#]/i.test(l)&&l.length<=200&&c.push(`a[href=${i(l)}]`);let u=[...e.classList].filter(e=>/^[a-z][\w-]{1,40}$/i.test(e)&&!n.test(e)&&!r.test(e));u.length&&c.push(`${s}.${u.slice(0,3).map(a).join(`.`)}`);for(let e of c)if(o(t,e))return e;let d=[],f=e;for(;f&&d.length<7;){if(f===t.body){d.unshift(`body`);break}if(f!==e&&f.id&&!n.test(f.id)){d.unshift(`#${a(f.id)}`);break}let r=f.tagName.toLowerCase(),i=f.parentElement?[...f.parentElement.children].filter(e=>e.tagName===f.tagName):[];d.unshift(i.length>1?`${r}:nth-of-type(${i.indexOf(f)+1})`:r),f=f.parentElement}let p=d.join(`>`);return o(t,p)?p:void 0}function l(e){let t=e.getAttribute(`aria-label`)||e.getAttribute(`title`);if(t)return t;let n=e.getAttribute(`aria-labelledby`);if(n)return n.split(/\s+/).map(t=>e.ownerDocument.getElementById(t)?.textContent??``).join(` `);let r=e.labels;return r?.length?r[0].innerText:``}function u(e,t=[]){if(e.closest(`[data-private],[aria-hidden=true],[inert],[data-ps-no-capture],playstep-root,playstep-capture`))return!0;for(let n of t)try{if(e.closest(n))return!0}catch{}return!1}const d=()=>crypto.randomUUID(),f=async e=>`u_`+[...new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e)),0,20)].map(e=>e.toString(16).padStart(2,`0`)).join(``),p=e=>/^(string|number|boolean)$/.test(typeof e),m=e=>Object.keys(e).length,h=e=>(e??``).replace(/\s+/g,` `).trim().slice(0,80),g=e=>{try{localStorage.removeItem(`playstep:${e}`)}catch{}},_=()=>void 0;function v(e,t=!0){let n={};for(let r in e){let i=e[r];m(n)<50&&/^[A-Za-z_$][\w.:-]{0,63}$/.test(r)&&(i===null||p(i)||t&&Array.isArray(i)&&i.every(p))&&(n[r]=Array.isArray(i)?i.slice(0,25):i)}return n}function y(){let e={};for(let[t,n]of new URLSearchParams(location.search))t.startsWith(`utm_`)&&(e[t.slice(4)]=n);let t=document.referrer&&new URL(document.referrer);return{r:t&&t.host!=location.host?t.origin:void 0,u:m(e)?e:void 0}}function b(e,t,n,r){let i=``;if(n&&!e.matches(`input,select,textarea`)){i=e.innerText;for(let t of e.querySelectorAll(`*`)){let e=u(t,r)&&t.innerText;e&&(i=i.includes(e)?i.replace(e,``):``)}}let a=e.href;return{selector:c(e),text:n&&(h(i)||h(l(e)))||void 0,role:s(e),href:typeof a==`string`&&a.split(/[?#]/)[0]||void 0,x:t.pageX|0,y:t.pageY|0,vw:innerWidth,vh:innerHeight}}function x(n={}){let r,i=``,a,o,s=[],p,x,S,C=!1,w,T,E,D={},O,k={},A={},j=[],M=e=>{let n=t.get(`a:d`);return!n&&e&&t.set(`a:d`,n=`d_${d()}`),n},N=()=>r&&(T??(!w&&r.anonymous?M(!0):void 0)),P=()=>{let e=N();if(!e)return null;let n=t.get(`a:s`),o=e=>typeof e==`string`?e:void 0;return{v:1,key:i,sdk:a,actor:e,device:T&&M()||void 0,guide_key:E,traits:m(D)?D:void 0,user:r.identities&&w?{id:w,email:o(D.email),name:o(D.name)}:void 0,groups:m(k)?k:void 0,context:{platform:`web`,locale:navigator.language,referrer:n?.r,utm:n?.u}}};function F(e){let n=Date.now(),r=t.get(`a:s`);(!r||n-r.t>18e5)&&(r={id:d(),t:n,...y()},x.push({id:d(),name:`$session_start`,ts:e.ts,session:r.id})),r.t=n,t.set(`a:s`,r),x.push({...e,session:r.id})}let I=()=>p==`granted`&&N()&&j.splice(0).forEach(F);function L(e,t={}){if(!r||p==`denied`)return;let n={...A,...t.props},i={id:d(),name:e,ts:Date.now(),page:t.el&&O,...t,props:m(n)?n:void 0};p==`granted`&&N()?F(i):j.length<100&&w!==``&&j.push(i)}function R(e,t){let n=JSON.stringify(D)==JSON.stringify(D=v(t,!1));if(e==w&&e)return void(T&&!n&&L(`$identify`));if(x.flush(),w&&!e&&(j=[],g(`a:d`)),w=e||w&&``,T=E=void 0,!e)return void(k={});Promise.all([f(`${r.hash_key}:${e}`),f(`${i}:${e}`)]).then(t=>{w==e&&([T,E]=t,L(`$identify`),I())})}function z(e){let t=O={path:e};o.pages&&L(`$pageview`,{page:t});let n=()=>O==t&&(t.title=document.title);setTimeout(n,500),setTimeout(n,1500)}function B(){R(``,{}),A={},j=[],g(`a:d`),g(`a:s`)}function V(){S={url:r.url,storageKey:`playstep:a:q:${i}`,envelope:P,send:p==`denied`?_:n.send,delayMs:3e3},x=e(S)}function H(){let e=[];addEventListener(`click`,t=>{let n=t.target;if(!(n instanceof Element))return;let r=n.closest(`a[href],button,input:not([type=hidden]),select,textarea,summary,[role=button],[role=link],[role=tab],[role=menuitem],[role=checkbox],[role=switch],[data-guide]`);if(u(r??n,s))return;let i=!!r?.matches(`a[href],button,input:not([type=hidden]),select,textarea,summary,[role=button],[role=link],[role=tab],[role=menuitem],[role=checkbox],[role=switch]`)&&o.text!=0;if(o.rage&&(e=e.filter(e=>t.timeStamp-e.t<700&&Math.abs(e.x-t.clientX)<30&&Math.abs(e.y-t.clientY)<30),e.push({t:t.timeStamp,x:t.clientX,y:t.clientY})==3&&L(`$rage_click`,{el:b(r??n,t,i,s)})),!r)return;let a=b(r,t,i,s);if(o.clicks&&L(`$click`,{el:a}),o.dead){let e=!1,t=location.href,n=new MutationObserver(()=>e=!0);n.observe(document,{subtree:!0,childList:!0,attributes:!0}),setTimeout(()=>{n.disconnect(),!e&&t==location.href&&L(`$dead_click`,{el:a})},1e3)}},!0),o.forms&&addEventListener(`submit`,e=>{let t=e.target;t instanceof HTMLFormElement&&!u(t,s)&&L(`$submit`,{el:{selector:c(t),role:`form`,text:h(l(t)||t.getAttribute(`name`))}})},!0)}function U(e,c){if(!(r||!e||c.preview)){if(!crypto.subtle)return void(C||(C=(console.warn(`PlayStep Insights needs a secure context`),!0)));r=e,i=c.appKey,a={name:c.sdkName||`web`,version:`0.11.4`},o={...e.autocapture,...n.autocapture},s=[...e.mask,...n.mask??[]],p=t.get(`a:c`)??e.consent,V(),H()}}return{plugin:(...e)=>{e[0]==`config`?U(e[1].analytics,e[2]):r&&(e[0]==`identify`?R(e[1],e[2]):e[0]==`track`?L(e[1],{props:v(e[2])}):e[0]==`page`?z(e[1]):B())},setConsent:e=>{p=e?`granted`:`denied`,t.set(`a:c`,p),e?(S?.send==_&&V(),I()):(j=[],g(`a:d`),S&&(S.send=_,S.envelope=()=>null,x.flush()))},register:e=>void(A={...A,...v(e)}),unregister:e=>void delete A[e],group:(e,t,n)=>{(e in k||m(k)<5)&&(k[e]=t),L(`$group`,{props:{...v(n),group_type:e,group_id:t}})},flush:()=>x?.flush()}}const S=new WeakMap;function C(e,t){let n=S.get(e);return n||(S.set(e,n=x(t)),e.use(n.plugin)),n}export{C as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axceera/playstep-analytics",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
4
4
|
"description": "PlayStep Insights: product analytics for your web app (pages, clicks, forms, your own events) as an add-on to @axceera/playstep. Loaded only when you add it; signed-in users only unless you allow anonymous tracking.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"tsdown": "^0.23.0",
|
|
40
40
|
"typescript": "~6.0.3",
|
|
41
41
|
"vitest": "^4.1.11",
|
|
42
|
-
"@playstep
|
|
43
|
-
"@
|
|
42
|
+
"@axceera/playstep": "0.11.5",
|
|
43
|
+
"@playstep/spec": "0.1.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsdown",
|