@axceera/playstep-referrals 0.1.0 → 0.1.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/README.md +3 -0
- package/dist/cdn/referrals.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,9 @@ until `ref.consent(true)`), `api`. Full docs: [playstep.app/docs/sdk/referrals](
|
|
|
39
39
|
core's own code.
|
|
40
40
|
- `src/cdn.ts` and `scripts/cdn.ts`: the script-tag build and its CDN release (`referrals/<version>/` and the `v1`
|
|
41
41
|
channel, with a manifest of SRI hashes); `scripts/upload-cdn.ts` puts it in R2 (`pnpm release cdn`, RUNBOOK.md › 4).
|
|
42
|
+
The script tag attaches to `window.playstep` whenever the PlayStep loader puts it there: already present, or set
|
|
43
|
+
later (an app that adds the loader itself once it knows the user), through a setter on `window.playstep`, before
|
|
44
|
+
anything can call `identify()` on it.
|
|
42
45
|
- Budgets in `.size-limit.json` (`pnpm size` after `pnpm build`); they only go down.
|
|
43
46
|
|
|
44
47
|
```bash
|
package/dist/cdn/referrals.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){let e=[];for(let t=2;e.length<64;t++){let r=!0;for(let e=2;e*e<=t;e++)t%e===0&&(r=!1);r&&e.push(Math.cbrt(t)%1*2**32|0)}let t=(e,t)=>e>>>t|e<<32-t;function r(r){let n=(new TextEncoder).encode(r),o=n.length,l=new Uint32Array(16*(o+8>>6)+16);for(let e=0;e<o;e++)l[e>>2]|=n[e]<<24-e%4*8;l[o>>2]|=128<<24-o%4*8,l[l.length-1]=8*o,l[l.length-2]=Math.floor(o/536870912);let i=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],a=new Uint32Array(64);for(let r=0;r<l.length;r+=16){for(let e=0;e<64;e++)if(e<16)a[e]=l[r+e];else{let r=a[e-15],n=a[e-2];a[e]=a[e-16]+(t(r,7)^t(r,18)^r>>>3)+a[e-7]+(t(n,17)^t(n,19)^n>>>10)}let[n,o,s,c,p,f,u,
|
|
1
|
+
!function(){let e=[];for(let t=2;e.length<64;t++){let r=!0;for(let e=2;e*e<=t;e++)t%e===0&&(r=!1);r&&e.push(Math.cbrt(t)%1*2**32|0)}let t=(e,t)=>e>>>t|e<<32-t;function r(r){let n=(new TextEncoder).encode(r),o=n.length,l=new Uint32Array(16*(o+8>>6)+16);for(let e=0;e<o;e++)l[e>>2]|=n[e]<<24-e%4*8;l[o>>2]|=128<<24-o%4*8,l[l.length-1]=8*o,l[l.length-2]=Math.floor(o/536870912);let i=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],a=new Uint32Array(64);for(let r=0;r<l.length;r+=16){for(let e=0;e<64;e++)if(e<16)a[e]=l[r+e];else{let r=a[e-15],n=a[e-2];a[e]=a[e-16]+(t(r,7)^t(r,18)^r>>>3)+a[e-7]+(t(n,17)^t(n,19)^n>>>10)}let[n,o,s,c,p,f,u,m]=i;for(let r=0;r<64;r++){let l=m+(t(p,6)^t(p,11)^t(p,25))+(p&f^~p&u)+e[r]+a[r]|0,i=(t(n,2)^t(n,13)^t(n,22))+(n&o^n&s^o&s)|0;m=u,u=f,f=p,p=c+l|0,c=s,s=o,o=n,n=l+i|0}[n,o,s,c,p,f,u,m].forEach((e,t)=>i[t]=i[t]+e|0)}return i.map(e=>(e>>>0).toString(16).padStart(8,"0")).join("")}let n=(e,t)=>e?.trim().slice(0,t)||void 0;function o(e=location,t=document.referrer,r=Date.now()){let o=new URLSearchParams(e.search),l={at:r},i={},a=!1;for(let e of["source","medium","campaign","term","content"]){let t=n(o.get(`utm_${e}`),100);t&&(a=!!(i[e]=t))}a&&(l.utm=i),(l.click=n(o.get("ps_ref"),200))&&(a=!0),(l.ref=n(o.get("ref"),64))&&(a=!0);let s=/^https?:\/\/([^/:?#]+)/i.exec(t)?.[1]?.toLowerCase(),c=e.hostname.split(".").slice(-2).join(".");return s&&s!==c&&!s.endsWith(`.${c}`)&&(a=!!(l.referrer=s.slice(0,255))),a?l:void 0}function l(e,t){document.cookie=`_ps_ref=${e?encodeURIComponent(JSON.stringify(e)):""};path=/;samesite=lax;max-age=${e?7776e3:0}${t?`;domain=${t}`:""}${"https:"===location.protocol?";secure":""}`}let i="__playstepReferrals",a="playstep:ref:sent";function s(e,t){let r=e;if(r[i])return r[i];let{identify:n,reset:o}=r;return r.identify=(e,o)=>{let l=n.call(r,e,o);return t.identify(e,o),l},r.reset=()=>{let e=o.call(r);return t.reset(),e},r[i]=t}let c=document.currentScript?.dataset??{};if(c.appKey&&!window.playstepReferrals){let e=function(e,t){let n,i,c=(t.api??"https://cdn.playstep.app").replace(/\/$/,""),p=function(){let e=location.hostname.split(".");if(e.length<2||/^[\d.]+$/.test(location.hostname))return"";for(let t=e.length-2;t>=0;t--){let r=`;domain=${e.slice(t).join(".")};path=/`;if(document.cookie=`_ps_t=1${r}`,document.cookie.includes("_ps_t=1"))return document.cookie=`_ps_t=${r};max-age=0`,e.slice(t).join(".")}return""}(),f="required"!==t.consent,u=((e,t)=>t?{first:e.first??t,last:t}:e)(function(){try{return JSON.parse(decodeURIComponent(/(?:^|; )_ps_ref=([^;]+)/.exec(document.cookie)?.[1]??"{}"))}catch{return{}}}(),o());f&&l(u,p);let m=t.appDomains?.map(e=>e.toLowerCase());m?.length&&document.addEventListener("click",e=>{let t=e.target?.closest?.("a[href]"),r=u.last;if(!t||!r||!m.includes(t.hostname)||t.hostname===location.hostname)return;let n=new URL(t.href);r.click&&n.searchParams.set("ps_ref",r.click),r.ref&&n.searchParams.set("ref",r.ref),t.href=n.href},!0);let d=()=>{if(!n||!f)return;let e="";try{e=localStorage.getItem(a)??""}catch{}let o=r(n+JSON.stringify(u)).slice(0,16);e.includes(o)||fetch(`${c}/v1/referrals/attribution`,{method:"POST",keepalive:!0,body:JSON.stringify({key:t.appKey,user:n,...u,email:i})}).then(t=>t.ok&&localStorage.setItem(a,`${o},${e}`.slice(0,340))).catch(()=>{})},h={get touches(){return u},consent(e){f=e,e||(u={}),l(e?u:null,p),d()},identify(e,o){if(!e)return;n=((e,t)=>`u_${r(`${e}:${t}`).slice(0,40)}`)(t.appKey,`${e}`);let l=o?.email;i="string"==typeof l&&l.trim()?r(l.trim().toLowerCase()):void 0,d()},reset(){n=i=void 0},myLink:()=>n?fetch(`${c}/v1/referrals/me?key=${t.appKey}&user=${n}`).then(e=>e.ok?e.json():null).catch(()=>null):Promise.resolve(null)};return e?s(e,h):h}(window.playstep,{appKey:c.appKey,api:c.api,appDomains:c.appDomains?.split(/[\s,]+/).filter(Boolean),consent:c.consent});if(window.playstepReferrals=e,!window.playstep){let t;Object.defineProperty(window,"playstep",{configurable:!0,get:()=>t,set:r=>{(t=r)&&s(r,e)}})}}}();
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=[];for(let t=2;e.length<64;t++){let n=!0;for(let e=2;e*e<=t;e++)t%e===0&&(n=!1);n&&e.push(Math.cbrt(t)%1*2**32|0)}const t=(e,t)=>e>>>t|e<<32-t;function n(n){let r=new TextEncoder().encode(n),i=r.length,a=new Uint32Array((i+8>>6)*16+16);for(let e=0;e<i;e++)a[e>>2]|=r[e]<<24-e%4*8;a[i>>2]|=128<<24-i%4*8,a[a.length-1]=i*8,a[a.length-2]=Math.floor(i/536870912);let o=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],s=new Uint32Array(64);for(let n=0;n<a.length;n+=16){for(let e=0;e<64;e++)if(e<16)s[e]=a[n+e];else{let n=s[e-15],r=s[e-2];s[e]=s[e-16]+(t(n,7)^t(n,18)^n>>>3)+s[e-7]+(t(r,17)^t(r,19)^r>>>10)}let[r,i,c,l,u,d,f,p]=o;for(let n=0;n<64;n++){let a=p+(t(u,6)^t(u,11)^t(u,25))+(u&d^~u&f)+e[n]+s[n]|0,o=(t(r,2)^t(r,13)^t(r,22))+(r&i^r&c^i&c)|0;p=f,f=d,d=u,u=l+a|0,l=c,c=i,i=r,r=a+o|0}[r,i,c,l,u,d,f,p].forEach((e,t)=>o[t]=o[t]+e|0)}return o.map(e=>(e>>>0).toString(16).padStart(8,`0`)).join(``)}const r=(e,t)=>e?.trim().slice(0,t)||void 0;function i(){let e=location.hostname.split(`.`);if(e.length<2||/^[\d.]+$/.test(location.hostname))return``;for(let t=e.length-2;t>=0;t--){let n=`;domain=${e.slice(t).join(`.`)};path=/`;if(document.cookie=`_ps_t=1${n}`,document.cookie.includes(`_ps_t=1`))return document.cookie=`_ps_t=${n};max-age=0`,e.slice(t).join(`.`)}return``}function a(e=location,t=document.referrer,n=Date.now()){let i=new URLSearchParams(e.search),a={at:n},o={},s=!1;for(let e of[`source`,`medium`,`campaign`,`term`,`content`]){let t=r(i.get(`utm_${e}`),100);t&&(s=!!(o[e]=t))}s&&(a.utm=o),(a.click=r(i.get(`ps_ref`),200))&&(s=!0),(a.ref=r(i.get(`ref`),64))&&(s=!0);let c=/^https?:\/\/([^/:?#]+)/i.exec(t)?.[1]?.toLowerCase(),l=e.hostname.split(`.`).slice(-2).join(`.`);return c&&c!==l&&!c.endsWith(`.${l}`)&&(s=!!(a.referrer=c.slice(0,255))),s?a:void 0}function o(){try{return JSON.parse(decodeURIComponent(/(?:^|; )_ps_ref=([^;]+)/.exec(document.cookie)?.[1]??`{}`))}catch{return{}}}function s(e,t){document.cookie=`_ps_ref=${e?encodeURIComponent(JSON.stringify(e)):``};path=/;samesite=lax;max-age=${e?7776e3:0}${t?`;domain=${t}`:``}${location.protocol===`https:`?`;secure`:``}`}const c=(e,t)=>t?{first:e.first??t,last:t}:e,l=`__playstepReferrals`,u=`playstep:ref:sent`,d=(e,t)=>`u_${n(`${e}:${t}`).slice(0,40)}`;function f(e,t){let r=(t.api??`https://cdn.playstep.app`).replace(/\/$/,``),l=i(),f=t.consent!==`required`,m=c(o(),a()),h,g;f&&s(m,l);let _=t.appDomains?.map(e=>e.toLowerCase());_?.length&&document.addEventListener(`click`,e=>{let t=e.target?.closest?.(`a[href]`),n=m.last;if(!t||!n||!_.includes(t.hostname)||t.hostname===location.hostname)return;let r=new URL(t.href);n.click&&r.searchParams.set(`ps_ref`,n.click),n.ref&&r.searchParams.set(`ref`,n.ref),t.href=r.href},!0);let v=()=>{if(!h||!f)return;let e=``;try{e=localStorage.getItem(u)??``}catch{}let i=n(h+JSON.stringify(m)).slice(0,16);e.includes(i)||fetch(`${r}/v1/referrals/attribution`,{method:`POST`,keepalive:!0,
|
|
1
|
+
const e=[];for(let t=2;e.length<64;t++){let n=!0;for(let e=2;e*e<=t;e++)t%e===0&&(n=!1);n&&e.push(Math.cbrt(t)%1*2**32|0)}const t=(e,t)=>e>>>t|e<<32-t;function n(n){let r=new TextEncoder().encode(n),i=r.length,a=new Uint32Array((i+8>>6)*16+16);for(let e=0;e<i;e++)a[e>>2]|=r[e]<<24-e%4*8;a[i>>2]|=128<<24-i%4*8,a[a.length-1]=i*8,a[a.length-2]=Math.floor(i/536870912);let o=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],s=new Uint32Array(64);for(let n=0;n<a.length;n+=16){for(let e=0;e<64;e++)if(e<16)s[e]=a[n+e];else{let n=s[e-15],r=s[e-2];s[e]=s[e-16]+(t(n,7)^t(n,18)^n>>>3)+s[e-7]+(t(r,17)^t(r,19)^r>>>10)}let[r,i,c,l,u,d,f,p]=o;for(let n=0;n<64;n++){let a=p+(t(u,6)^t(u,11)^t(u,25))+(u&d^~u&f)+e[n]+s[n]|0,o=(t(r,2)^t(r,13)^t(r,22))+(r&i^r&c^i&c)|0;p=f,f=d,d=u,u=l+a|0,l=c,c=i,i=r,r=a+o|0}[r,i,c,l,u,d,f,p].forEach((e,t)=>o[t]=o[t]+e|0)}return o.map(e=>(e>>>0).toString(16).padStart(8,`0`)).join(``)}const r=(e,t)=>e?.trim().slice(0,t)||void 0;function i(){let e=location.hostname.split(`.`);if(e.length<2||/^[\d.]+$/.test(location.hostname))return``;for(let t=e.length-2;t>=0;t--){let n=`;domain=${e.slice(t).join(`.`)};path=/`;if(document.cookie=`_ps_t=1${n}`,document.cookie.includes(`_ps_t=1`))return document.cookie=`_ps_t=${n};max-age=0`,e.slice(t).join(`.`)}return``}function a(e=location,t=document.referrer,n=Date.now()){let i=new URLSearchParams(e.search),a={at:n},o={},s=!1;for(let e of[`source`,`medium`,`campaign`,`term`,`content`]){let t=r(i.get(`utm_${e}`),100);t&&(s=!!(o[e]=t))}s&&(a.utm=o),(a.click=r(i.get(`ps_ref`),200))&&(s=!0),(a.ref=r(i.get(`ref`),64))&&(s=!0);let c=/^https?:\/\/([^/:?#]+)/i.exec(t)?.[1]?.toLowerCase(),l=e.hostname.split(`.`).slice(-2).join(`.`);return c&&c!==l&&!c.endsWith(`.${l}`)&&(s=!!(a.referrer=c.slice(0,255))),s?a:void 0}function o(){try{return JSON.parse(decodeURIComponent(/(?:^|; )_ps_ref=([^;]+)/.exec(document.cookie)?.[1]??`{}`))}catch{return{}}}function s(e,t){document.cookie=`_ps_ref=${e?encodeURIComponent(JSON.stringify(e)):``};path=/;samesite=lax;max-age=${e?7776e3:0}${t?`;domain=${t}`:``}${location.protocol===`https:`?`;secure`:``}`}const c=(e,t)=>t?{first:e.first??t,last:t}:e,l=`__playstepReferrals`,u=`playstep:ref:sent`,d=(e,t)=>`u_${n(`${e}:${t}`).slice(0,40)}`;function f(e,t){let r=(t.api??`https://cdn.playstep.app`).replace(/\/$/,``),l=i(),f=t.consent!==`required`,m=c(o(),a()),h,g;f&&s(m,l);let _=t.appDomains?.map(e=>e.toLowerCase());_?.length&&document.addEventListener(`click`,e=>{let t=e.target?.closest?.(`a[href]`),n=m.last;if(!t||!n||!_.includes(t.hostname)||t.hostname===location.hostname)return;let r=new URL(t.href);n.click&&r.searchParams.set(`ps_ref`,n.click),n.ref&&r.searchParams.set(`ref`,n.ref),t.href=r.href},!0);let v=()=>{if(!h||!f)return;let e=``;try{e=localStorage.getItem(u)??``}catch{}let i=n(h+JSON.stringify(m)).slice(0,16);e.includes(i)||fetch(`${r}/v1/referrals/attribution`,{method:`POST`,keepalive:!0,body:JSON.stringify({key:t.appKey,user:h,...m,email:g})}).then(t=>t.ok&&localStorage.setItem(u,`${i},${e}`.slice(0,340))).catch(()=>{})},y={get touches(){return m},consent(e){f=e,e||(m={}),s(e?m:null,l),v()},identify(e,r){if(!e)return;h=d(t.appKey,`${e}`);let i=r?.email;g=typeof i==`string`&&i.trim()?n(i.trim().toLowerCase()):void 0,v()},reset(){h=g=void 0},myLink:()=>h?fetch(`${r}/v1/referrals/me?key=${t.appKey}&user=${h}`).then(e=>e.ok?e.json():null).catch(()=>null):Promise.resolve(null)};return e?p(e,y):y}function p(e,t){let n=e;if(n[l])return n[l];let{identify:r,reset:i}=n;return n.identify=(e,i)=>{let a=r.call(n,e,i);return t.identify(e,i),a},n.reset=()=>{let e=i.call(n);return t.reset(),e},n[l]=t}export{p as attach,f as referrals,d as userKey};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axceera/playstep-referrals",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "PlayStep Referrals: knows where your users came from (referral and affiliate links, promo codes, UTM tags) and tells PlayStep when they sign in. An add-on to @axceera/playstep; nothing is added to the core.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|