@axceera/playstep-analytics 0.0.0-stage → 0.11.2
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/LICENSE +19 -0
- package/README.md +44 -2
- package/dist/index-BHJ9eOBw.d.ts +49 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/react.d.ts +6 -0
- package/dist/react.js +1 -0
- package/dist/src-C9pnehdK.js +1 -0
- package/package.json +49 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PlayStep
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
7
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
11
|
+
Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
14
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
15
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
16
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
+
|
|
18
|
+
Icons: Lucide (https://lucide.dev), ISC License. Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022
|
|
19
|
+
as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @axceera/playstep-analytics
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Insights, PlayStep's product analytics, as an add-on to [`@axceera/playstep`](https://www.npmjs.com/package/@axceera/playstep):
|
|
4
|
+
pages, clicks, rage clicks, form submits and your own events, for the people using your app. Apps that don't add it
|
|
5
|
+
carry none of it.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @axceera/playstep @axceera/playstep-analytics
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { playstep } from '@axceera/playstep'
|
|
13
|
+
import { analytics } from '@axceera/playstep-analytics'
|
|
14
|
+
|
|
15
|
+
const insights = analytics(playstep) // before or after playstep.init()
|
|
16
|
+
playstep.identify(user.id, { plan: user.plan })
|
|
17
|
+
playstep.track('invoice_sent', { amount: 49 })
|
|
18
|
+
insights.group('company', account.id, { seats: 12 })
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
It captures only once Insights is turned on for the app in the dashboard, so it can ship before then. With the script
|
|
22
|
+
tag there is nothing to install: the loader fetches the same code (`insights.js`, checked against its hash) for an app
|
|
23
|
+
with Insights on. React apps on `@axceera/playstep-react` call `useInsights()` from `@axceera/playstep-analytics/react`.
|
|
24
|
+
|
|
25
|
+
- **Signed-in users only, by default.** Until `identify()`, up to 100 events wait in memory, then go under the user.
|
|
26
|
+
Allowing anonymous tracking (a dashboard setting) tracks a random device id instead, joined to the user when they
|
|
27
|
+
sign in.
|
|
28
|
+
- **Ids are hashed in the browser** with the environment's analytics key. Ids, emails and names are stored only where
|
|
29
|
+
the app turns identities on (Pro and Business).
|
|
30
|
+
- **Consent:** start `pending` (events wait in memory) or `denied` in the dashboard, then call
|
|
31
|
+
`insights.setConsent(true | false)` from your banner. The answer is remembered in the browser.
|
|
32
|
+
- **Clicks record the element, never what was typed:** its selector, label, role and link, and the page it was on
|
|
33
|
+
(the path PlayStep last saw, so heatmaps and reports can place it). Elements marked
|
|
34
|
+
`data-private` or `data-ps-no-capture`, hidden ones, PlayStep's own UI and the app's mask list are skipped.
|
|
35
|
+
`analytics(playstep, { mask: ['.billing'] })` adds selectors for one page, and `autocapture: { clicks: false }`
|
|
36
|
+
turns a part off.
|
|
37
|
+
- **Needs a secure page** (https or localhost): it hashes with the browser's `crypto.subtle`.
|
|
38
|
+
- Batches go to `POST /v1/batch`, kept in local storage and retried when offline, never on the guide queue.
|
|
39
|
+
|
|
40
|
+
API: `setConsent(granted)`, `register(props)` / `unregister(key)` (properties on every event), `group(type, id,
|
|
41
|
+
traits?)` (at most 5 kinds), `flush()`. On sign-out, `playstep.identify('')` stops filing events under the user (what
|
|
42
|
+
follows waits for the next one; consent and properties stay, groups go) and keeps their guide progress;
|
|
43
|
+
`playstep.reset()` forgets the user, the device and those properties too. Script tag: `(window.playstepInsights ||= []).push(['setConsent', true])` works before it loads.
|
|
44
|
+
|
|
45
|
+
About 3.3 KB gzipped from npm (the event queue comes from `@axceera/playstep`), 4 KB as the script tag.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PlayStep, PlayStepPlugin, QueueOptions } from "@axceera/playstep/plugin";
|
|
2
|
+
//#region ../spec/src/types.d.ts
|
|
3
|
+
/** Insights' settings, present when the app turned analytics on (see analyticsConfigSchema). */
|
|
4
|
+
interface AnalyticsConfig {
|
|
5
|
+
url: string;
|
|
6
|
+
hash_key: string;
|
|
7
|
+
anonymous: boolean;
|
|
8
|
+
consent: 'granted' | 'pending' | 'denied';
|
|
9
|
+
autocapture: {
|
|
10
|
+
pages: boolean;
|
|
11
|
+
clicks: boolean;
|
|
12
|
+
forms: boolean;
|
|
13
|
+
rage: boolean;
|
|
14
|
+
dead: boolean;
|
|
15
|
+
};
|
|
16
|
+
identities: boolean;
|
|
17
|
+
mask: string[];
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/insights.d.ts
|
|
21
|
+
type Autocapture = AnalyticsConfig['autocapture'];
|
|
22
|
+
type Props = Record<string, unknown>;
|
|
23
|
+
interface InsightsOptions {
|
|
24
|
+
/** Over the app's autocapture settings for this page: `{ clicks: false }`, or `{ dead: true }`. */
|
|
25
|
+
autocapture?: Partial<Autocapture>;
|
|
26
|
+
/** More CSS selectors whose elements are never captured, besides the app's mask list. */
|
|
27
|
+
mask?: string[];
|
|
28
|
+
/** Tests and the e2e harness: replaces fetch and sendBeacon. */
|
|
29
|
+
send?: QueueOptions['send'];
|
|
30
|
+
}
|
|
31
|
+
interface Insights {
|
|
32
|
+
/** The add-on itself, for playstep.use() (analytics() attaches it for you). */
|
|
33
|
+
plugin: PlayStepPlugin;
|
|
34
|
+
/** Your consent banner's answer, remembered in this browser: true captures, false stops and forgets the device. */
|
|
35
|
+
setConsent: (granted: boolean) => void;
|
|
36
|
+
/** Properties sent with every event from now on, until unregister() or reset(). */
|
|
37
|
+
register: (props: Props) => void;
|
|
38
|
+
unregister: (key: string) => void;
|
|
39
|
+
/** Puts the user in a company (or another kind of group, at most 5 kinds), with the group's traits. */
|
|
40
|
+
group: (type: string, id: string, traits?: Props) => void;
|
|
41
|
+
/** Sends what is waiting now. */
|
|
42
|
+
flush: () => void;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/index.d.ts
|
|
46
|
+
/** Attaches Insights to PlayStep, once per SDK (a second call returns the first one's API). */
|
|
47
|
+
declare function analytics(playstep: Pick<PlayStep, 'use'>, options?: InsightsOptions): Insights;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { Props as a, InsightsOptions as i, Autocapture as n, Insights as r, analytics as t };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as analytics}from"./src-C9pnehdK.js";
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { i as InsightsOptions, r as Insights } from "./index-BHJ9eOBw.js";
|
|
2
|
+
//#region src/react.d.ts
|
|
3
|
+
/** Attaches Insights to PlayStep (the first call's options win) and returns its API. */
|
|
4
|
+
export declare function useInsights(options?: InsightsOptions): Insights;
|
|
5
|
+
//#endregion
|
|
6
|
+
export type { Insights, InsightsOptions };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./src-C9pnehdK.js";import{playstep as t}from"@axceera/playstep";function n(n){return e(t,n)}export{n as useInsights};
|
|
@@ -0,0 +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=>[...new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e)))].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);function g(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 _(){let e={};for(let[t,n]of new URLSearchParams(location.search))t.startsWith(`utm_`)&&(e[t.slice(4)]=n);let t;try{t=new URL(document.referrer)}catch{}return{r:t&&t.host!=location.host?t.origin:void 0,u:m(e)?e:void 0}}function v(e,t,n){let r=n&&h(/^(INPUT|SELECT|TEXTAREA)$/.test(e.tagName)?l(e):e.innerText||l(e)),i=e.href;return{selector:c(e),text:r||void 0,role:s(e),href:typeof i==`string`&&i||void 0,x:t.pageX|0,y:t.pageY|0,vw:innerWidth,vh:innerHeight}}function y(n={}){let r,i=``,a,o,s=[],p,y,b,x,S,C={},w,T={},E={},D=[],O=e=>{let n=t.get(`a:d`);return!n&&e&&t.set(`a:d`,n=`d_${d()}`),n||void 0},k=()=>r&&(x??(!b&&r.anonymous?O(!0):void 0)),A=()=>{let e=k();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:x&&O()||void 0,guide_key:S,traits:m(C)?C:void 0,user:r.identities&&b?{id:b,email:o(C.email),name:o(C.name)}:void 0,groups:m(T)?T:void 0,context:{platform:`web`,locale:navigator.language,referrer:n?.r,utm:n?.u}}};function j(e){let n=Date.now(),r=t.get(`a:s`);(!r||n-r.t>18e5)&&(r={id:d(),t:n,..._()},y.push({id:d(),name:`$session_start`,ts:e.ts,session:r.id})),r.t=n,t.set(`a:s`,r),y.push({...e,session:r.id})}let M=()=>p==`granted`&&k()&&D.splice(0).forEach(j);function N(e,t={}){if(!r||p==`denied`)return;let n={...E,...t.props},i={id:d(),name:e,ts:Date.now(),page:t.el&&w,...t,props:m(n)?n:void 0};p==`granted`&&k()?j(i):D.length<100&&D.push(i)}function P(e,t){if(C=g(t,!1),e==b&&e)return void(x&&N(`$identify`));if(y.flush(),b=e,x=S=void 0,!e)return void(T={});Promise.all([f(`${r.hash_key}:${e}`),f(`${i}:${e}`)]).then(([t,n])=>{b==e&&(x=`u_${t.slice(0,40)}`,S=`u_${n.slice(0,40)}`,N(`$identify`),M())})}function F(){P(``,{}),E={},D=[],t.set(`a:d`,null),t.set(`a:s`,null)}function I(){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)||(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&&N(`$rage_click`,{el:v(r??n,t,!!r)})),!r))return;let i=v(r,t,!0);if(o.clicks&&N(`$click`,{el:i}),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&&N(`$dead_click`,{el:i})},1e3)}},!0),o.forms&&addEventListener(`submit`,e=>{let t=e.target;t instanceof HTMLFormElement&&!u(t,s)&&N(`$submit`,{el:{selector:c(t),role:`form`,text:h(l(t)||t.getAttribute(`name`))}})},!0)}function L(c,l){!r&&c&&!l.preview&&crypto.subtle&&(r=c,i=l.appKey,a={name:l.sdkName||`web`,version:`0.11.2`},o={...c.autocapture,...n.autocapture},s=[...c.mask,...n.mask??[]],p=t.get(`a:c`)??c.consent,y=e({url:c.url,storageKey:`playstep:a:q:${i}`,envelope:A,send:n.send}),I())}return{plugin:(...e)=>{e[0]==`config`?L(e[1].analytics,e[2]):r&&(e[0]==`identify`?P(e[1],e[2]):e[0]==`track`?N(e[1],{props:g(e[2])}):e[0]==`page`?(w={path:e[1]},o.pages&&N(`$pageview`,{page:{path:e[1],title:document.title}})):F())},setConsent:e=>{p=e?`granted`:`denied`,t.set(`a:c`,p),e?M():(D=[],t.set(`a:d`,null))},register:e=>void(E={...E,...g(e)}),unregister:e=>void delete E[e],group:(e,t,n)=>{(e in T||m(T)<5)&&(T[e]=t),N(`$group`,{props:{...g(n),group_type:e,group_id:t}})},flush:()=>y?.flush()}}const b=new WeakMap;function x(e,t){let n=b.get(e);return n||(b.set(e,n=y(t)),e.use(n.plugin)),n}export{x as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axceera/playstep-analytics",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.11.2",
|
|
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
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"homepage": "https://playstep.app/docs/sdk/web",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"product analytics",
|
|
10
|
+
"analytics",
|
|
11
|
+
"onboarding",
|
|
12
|
+
"playstep"
|
|
13
|
+
],
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./react": {
|
|
23
|
+
"types": "./dist/react.d.ts",
|
|
24
|
+
"import": "./dist/react.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist/*.js",
|
|
30
|
+
"dist/*.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@axceera/playstep": ">=0.10.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@size-limit/file": "^14.2.0",
|
|
37
|
+
"happy-dom": "^20.14.6",
|
|
38
|
+
"size-limit": "^14.2.0",
|
|
39
|
+
"tsdown": "^0.23.0",
|
|
40
|
+
"typescript": "~6.0.3",
|
|
41
|
+
"vitest": "^4.1.11",
|
|
42
|
+
"@axceera/playstep": "0.11.2",
|
|
43
|
+
"@playstep/spec": "0.1.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsdown",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"size": "size-limit",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"lint": "eslint ."
|
|
51
|
+
}
|
|
6
52
|
}
|