@datacub/web 0.0.0-stage → 0.4.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/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +26 -2
- package/dist/datacub.js +4 -0
- package/dist/datacub.mjs +4 -0
- package/dist/feedback.js +64 -0
- package/dist/feedback.mjs +64 -0
- package/dist/flags.js +1 -0
- package/dist/flags.mjs +1 -0
- package/dist/insights.js +1 -0
- package/package.json +65 -4
- package/types/bucket.d.ts +6 -0
- package/types/datacub.d.ts +102 -0
- package/types/feedback.d.ts +84 -0
- package/types/flags-npm.d.ts +2 -0
- package/types/flags.d.ts +9 -0
- package/types/index.d.ts +100 -0
- package/types/scrub.d.ts +24 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.4.2](https://github.com/datacub/sdk/compare/web-v0.4.0...web-v0.4.2) (2026-11-22)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **web:** accept the 8-character project id (data-id), send to the host the script came from ([37df73b](https://github.com/datacub/sdk/commit/37df73bbf498362c55dff04363550ffcf66a7f90))
|
|
9
|
+
|
|
10
|
+
## 0.4.0
|
|
11
|
+
|
|
12
|
+
- `datacub.identify({ id, ...traits })` works: the id can be `id`, `userId` or `user_id`, and `fullName` and `phoneNumber` count as `name` and `phone`.
|
|
13
|
+
- Visitor cookies are per project key (`datacub_id_<key part>` and so on; `datacub_optout` stays shared), so existing visitors get a new anon_id once.
|
|
14
|
+
|
|
15
|
+
## 0.3.1
|
|
16
|
+
|
|
17
|
+
First release on npm.
|
|
18
|
+
|
|
19
|
+
- Install from npm with `npm install @datacub/web`, or keep using the script tag. Both are built from the same source, and the script-tag files at `https://in.datacub.to/v1/sdk/datacub-0.3.1.min.js` are the same bytes as `dist/datacub.js` in the package.
|
|
20
|
+
- The default ingestion host is now `https://in.datacub.to`. Sites that pass `apiHost` (or `data-api-host`) are unaffected.
|
|
21
|
+
- Entry points: `@datacub/web` (the SDK), `@datacub/web/flags` (feature flags and experiments) and `@datacub/web/feedback` (the feedback widget's renderer).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 datacub
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @datacub/web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
datacub product analytics for websites. Page views, route changes, clicks, forms and errors are tracked automatically.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @datacub/web
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import datacub from '@datacub/web'
|
|
11
|
+
|
|
12
|
+
datacub.init('YOUR_PROJECT_ID')
|
|
13
|
+
|
|
14
|
+
datacub.track('signup_completed', { plan: 'pro' }) // a custom event
|
|
15
|
+
datacub.identify(user.id, { email, name }) // after login
|
|
16
|
+
datacub.reset() // at logout
|
|
17
|
+
|
|
18
|
+
// only when the project asks for consent first: init(key, { requireConsent: true })
|
|
19
|
+
datacub.consent.grant()
|
|
20
|
+
datacub.consent.revoke()
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Feature flags: `import { flag, experiment } from '@datacub/web/flags'`, then `await flag('new_checkout')`.
|
|
24
|
+
|
|
25
|
+
No form values, passwords, card numbers or IDs are collected. First-party cookies, no fingerprinting.
|
|
26
|
+
|
|
27
|
+
Install with an AI agent, options, cookies, proxy and CSP: [docs.datacub.to](https://docs.datacub.to/install-web). Source: [datacub/sdk](https://github.com/datacub/sdk).
|
package/dist/datacub.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
(()=>{var v={n:0},vt=(t)=>t.replace(/[\u0660-\u0669\u06f0-\u06f9\uff10-\uff19]/g,(e)=>String(e.charCodeAt(0)&15)),ve=/[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]/g,Bt=(t)=>vt(t).replace(ve,""),ke=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|bearer\s+\S{16,}|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]+|PRIVATE KEY|[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}|eyJ[\w-]+\.[\w-]+\.[\w-]*|\d(?:[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]*\d){8,}|[\w+/=]{32,}/gi;function Z(t){let e="",n=0;for(let r of vt(t).matchAll(ke)){if(/^[0-9a-f]{8}-/i.test(r[0])&&r[0].length===36)continue;e+=`${t.slice(n,r.index)}[redacted]`,n=r.index+r[0].length,v.n++}return e+t.slice(n)}function F(t,e=1024){if(t=t.normalize("NFC"),t.length>256||t.trim().split(/\s+/).length>11)return v.n++,"[redacted]";return Z(t).slice(0,e).replace(/[\uD800-\uDBFF]$/,"")}var H=(t)=>/[\u0000-\u001f\u007f-\u009f\u200e\u200f\u061c\u202a-\u202e\u2066-\u2069]/.test(t),Ee=/(?:passw(?:or)?d|passcode|pwd|pin|pincode|otp|otpcode|onetimecode|mfacode|2facode|tfacode|smscode|secretkey|privatekey|authcode|verificationcode|securitycode|resetcode|cvv|cvc|cardnumber|ccnumber|creditcard|pan|iban|iqama|hawiya|nationalid|nid|idnumber|ssn|token|authorization|secret|apikey|sessionid|cookie|jwt|bearer|csrf|xsrf|passport|\u0643\u0644\u0645\u0647\u0627\u0644\u0645\u0631\u0648\u0631|\u0643\u0644\u0645\u0647\u0627\u0644\u0633\u0631|\u0627\u0644\u0631\u0645\u0632\u0627\u0644\u0633\u0631\u064a|\u0627\u0644\u0631\u0642\u0645\u0627\u0644\u0633\u0631\u064a|\u0631\u0645\u0632\u0627\u0644\u062a\u062d\u0642\u0642|\u0631\u0642\u0645\u0627\u0644\u0647\u0648\u064a\u0647|\u0627\u0644\u0647\u0648\u064a\u0647\u0627\u0644\u0648\u0637\u0646\u064a\u0647|\u0627\u0644\u0627\u0642\u0627\u0645\u0647|\u0627\u0644\u0628\u0637\u0627\u0642\u0647|\u0627\u0644\u0627\u064a\u0628\u0627\u0646)$/;function Kt(t,e){let n=t.normalize("NFKD").replace(/[\p{M}\u0640]/gu,"").replace(/\u0629/g,"\u0647").replace(/\u0649/g,"\u064a").replace(/(\p{Ll})(?=\p{Lu})|(\p{N}+)/gu,"$1 $2 ").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);while(n.length>1&&/^\p{N}+$/u.test(n[n.length-1]))n.pop();return!t||[...t].length>200||/\./.test(t)||H(t)||/^(?:__proto__|constructor|prototype)$/.test(t)||e&&/^(?:\$|(?:distinct_id|person_id|project_id|timestamp|uuid|ip|api_key)$)/.test(t)||Ee.test(n.join(""))&&!/^(?:japan|span|timespan|lifespan|wingspan|saucepan|spin|chopin|android)$/.test(n[n.length-1])||n.some((r)=>/^(?:password|passwd|pwd|passcode|otp|pin|secret|iqama|ssn|cvv|cvc|iban)$/.test(r))}function D(t,e=0){if(typeof t==="string")return F(t);if(typeof t==="number")return Number.isFinite(t)?Number.isInteger(t)&&Z(`${t}`)!==`${t}`?"[redacted]":t:void 0;if(typeof t==="boolean"||t===null)return t;if(t instanceof Date)return Number.isNaN(+t)?void 0:t.toISOString();if(typeof t!=="object")return;if(e>2)return"[depth]";if(Array.isArray(t))return t.slice(0,100).map((i)=>D(i,e+1)).filter((i)=>i!==void 0);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n)return;let r={};for(let[i,s]of Object.entries(t).slice(0,200)){let o=i.trim();if(Kt(o,!e))v.n++;else{let a=D(s,e+1);if(a!==void 0)r[o]=a}}return r}function Xt(t){let e=t;try{e=decodeURIComponent(t)}catch{}e=vt(e);let n=v.n;if(Z(e)!==e)return v.n=n+1,":redacted";if(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(e))return":uuid";if(/^[0-9a-f]{16,}$/i.test(e))return e.length===24?":id":":hash";if(/^[\w-]{20,}$/.test(e)&&/\d/.test(e)&&/[a-z]/.test(e)&&/[A-Z]/.test(e))return":token";let r=e.replace(/\D/g,"").length;return r&&(r===e.length||r>3&&r*2>=e.length)?":id":t}var xe=/^(?:reset|invite|sid|token|jwt|otp|code|key|state|sig(?:nature)?|auth\w*|nonce|session\w*|hash|q|query|search\w*|s|keywords?|term|text|msg|message|comments?|\w*name|e?-?mail\w*|phone|mobile|tel|address\w*|city|zip|postcode|dob|birth\w*)$/i,Se=(t)=>/^(?:[a-z0-9][a-z0-9._~-]*|[A-Z0-9][A-Z0-9_-]*)$/.test(t)&&!(t.length>=8&&/\d/.test(t)&&/[a-z]/i.test(t)),k=(t,e)=>Z(t.normalize("NFC")).slice(0,e),Vt=(t)=>t.split("/").map((e)=>e&&Xt(e)).join("/");function R(t,e,n){let r;try{r=new URL(t)}catch{return null}let i=r.protocol;if(/^(?:mailto|tel|sms|whatsapp):$/.test(i))return{url:i,path:i};if(!/^https?:$/.test(i))return null;let s=Vt(r.pathname);if(e&&/^#!?\//.test(r.hash))s+=`#${Vt(r.hash.slice(1).split("?")[0])}`;s=s.slice(0,1024);let o={url:(r.origin+s).slice(0,2048),path:s};for(let[a,f]of r.searchParams){let g=a.toLowerCase();if(/^utm_(?:source|medium|campaign|term|content)$/.test(g)&&f)o.utm={...o.utm,[g.slice(4)]:F(f,200)};else if(/^(?:gclid|gbraid|wbraid|fbclid|ttclid|msclkid|sccid|twclid|li_fat_id)$/.test(g))o.click_id_type=g.replace(/^[gw]braid$/,"gclid");else if(n&&Object.keys(o.q||{}).length<30){let m=Xt(f);o.q??={},o.q[k(a,64)]=Kt(a,!1)||xe.test(a)||f.length>40||!(m[0]===":"||Se(f))?"":m===":redacted"?"":m}}return o}function Yt(t){let e=t.trim().normalize("NFC");return!e||[...e].length>100||e[0]==="$"||H(e)||/[0-9a-f]{8}-[0-9a-f]{4}-|[0-9a-f]{16}|@/i.test(e)||/\d{6}/.test(Bt(e))?null:e}function kt(t,e){if(typeof t==="number"&&Number.isFinite(t))t=`${t}`;if(typeof t!=="string")return null;let n=t.trim().normalize("NFC"),r=Bt(n),i=0;for(let s=0;s<r.length;s++){let o=+r[r.length-1-s];i+=s%2?o>4?o*2-9:o*2:o}return!n||[...n].length>128||/^(?:null|undefined|0|-1|anonymous|guest|\[object object\]|none|nan|false|true|user|test|unknown|not_authenticated|distinct_id|id)$/i.test(n)||H(n)||/@|^eyJ/.test(n)||/^(?:[12]\d{9}|(?:\+?966|00966|0)5\d{8}|\+\d{8,15})$/.test(r)||/^[2-6]\d{14,15}$/.test(r)&&i%10===0||e.includes(n)?null:n}var Rt="0.4.2",Wt=1800000,Re=86400000,Ae=34560000,At=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,$t=".datacub-no-capture,[data-datacub-no-capture]",re=["datacub_id","datacub_u","datacub_a","datacub_ss"],c,ft=!1,O={},ie=!0,It=0,et=0,nt=0,rt=0,it={},Ot=new Set,Tt,C=0,dt=0,w,ot,pt,J,q={},oe=!1,Ut="",T="",Nt=!1,se=null,Y="pending",Ct=!1,_=!1,B="",gt="",l="",E=null,j=null,P=null,h="",st=0,A=0,ae,G=0,W="",K=null,Ie=0,at=0,mt=0,ht=0,ce="",ct=!0,Q,Zt=0,u=[],qt,le=!1,Jt="",V=!1,lt=0,bt=!1,y=0,Pt=[],x=Date.now;function yt(t){if(oe)console.warn(`[datacub] ${t}`)}var S=(t)=>(...e)=>{try{t(...e)}catch{}},d=(t,e,n)=>t.addEventListener(e,S(n),!0);function L(t){let e=crypto.getRandomValues(new Uint8Array(16));for(let r=5,i=t;t&&r>=0;r--,i=Math.floor(i/256))e[r]=i&255;return e[6]=e[6]&15|(t?112:64),e[8]=e[8]&63|128,Array.from(e,(r)=>(r+256).toString(16).slice(1)).join("").replace(/(.{8})(.{4})(.{4})(.{4})/,"$1-$2-$3-$4-")}function X(){let t={};try{for(let e of c.cookie.split("; ")){let n=e.indexOf("="),r=e.slice(0,n);if(r==="datacub_optout"||B&&r.endsWith(B))t[r==="datacub_optout"?r:r.slice(0,-B.length)]=decodeURIComponent(e.slice(n+1))}}catch{}return t}function b(t,e,n=gt,r=e?Ae:0){try{c.cookie=`${t==="datacub_optout"?t:t+B}=${encodeURIComponent(e||"")};Path=/;Max-Age=${r};SameSite=Lax${n}${location.protocol==="https:"?";Secure":""}`}catch{}}function ue(){let t=location.hostname.split(".");return/^[\d.]+$|:/.test(location.hostname)?[]:t.slice(0,-1).map((e,n)=>`;Domain=${t.slice(n).join(".")}`)}function Mt(){if(!_)return;let t=X(),e=t.datacub_id??null;if(e!==l)l=e&&At.test(e)?e:L(),b("datacub_id",l),h="";E=t.datacub_u??null,j=t.datacub_a??null;let[n,r,i]=(t.datacub_ss||"").split(".");if(ae=n,G=+i,n&&At.test(n)&&G&&(n!==h||G>A))h=n,st=+r,A=G}function fe(t,e){if(!h||t-A>Wt||t-st>Re){if(h=L(x()),st=A=t,_)b("datacub_id",l)}else if(e&&t>A)A=t;if(_&&(ae!==h||A-G>5000))b("datacub_ss",`${h}.${st}.${A}`,gt,Wt/1000)}function I(t){clearTimeout(qt),le=t===0,qt=t==null?void 0:setTimeout(S(zt),t)}function de(t){if((t||u.length>19||c.visibilityState==="hidden")&&!le&&!lt)I(0);else if(!qt)I(5000)}var Oe=new TextEncoder;function p(t,e,n,r){if(!l)return;let i=x();if(Mt(),fe(i,!/^\$(?:pageleave|error|request|form_fields)$/.test(t)),v.n)e={...e,$d:v.n};let s=JSON.stringify([L(i),t,i,l,E,j,h,W||null,Ie++,+(Y==="granted"),+_,K?.url,ce,e,n]),o=Oe.encode(s).length;if(o>31000){y++;return}v.n=0,u.push([s,o]),ye(),de(r)}function Te(t,e){if(!l||typeof t!=="string")return;let n=Yt(t);if(!n)return yt("bad name");p(n,e&&typeof e==="object"&&!Array.isArray(e)&&D(e)||{})}function Dt(t=x()){if(at)mt+=t-at;at=c.visibilityState==="visible"?t:0}var ut=()=>{C=innerWidth,dt=innerHeight,ce=C<360?"xs":C<480?"s":C<768?"m":C<1280?"l":"xl",ht=Math.max(ht,scrollY+dt)};function Ft(t,e){return it[t]=(it[t]||0)+1,it[t]<=e}function pe(){if(!W)return;Dt();let t=mt-It;if(ct&&t<1)return;let e=c.documentElement.scrollHeight,n={$v:t,$s:e?ht/e:null};if(ct)n.$e=!0;if(et)n.$ec=et;if(nt)n.$rq=nt;if(rt)n.$rf=rt;et=nt=rt=0;try{Object.assign(n,q.l?.())}catch{}ct=!0,It=mt,p("$pageleave",n)}function Ht(t,e){if(!l)return;let n=location.pathname+(Nt?location.hash.split("?")[0]:"");if(!t&&n===Jt)return;let r=R(location.href,Nt,O.query!==!1);if(!r)return;Jt=n,pe();let i={};if(K)i.$p=K.path;if(t&&!e)i.$b=!0;if(i.$N=e?performance.getEntriesByType?.("navigation")[0]?.type:t?"back_forward":Tt,r.q)i.$q=r.q;if(O.title!==!1&&c.title)i.$T=k(c.title,200);K=r,W=L(x()),ct=!1,mt=ht=at=It=0,it={},Ot.clear(),Dt(),ut(),i.$vw=C,i.$vh=dt;let s=null;if(e)try{let o=new URL(c.referrer);s=o.hostname,i.$R=R(o.href)?.path}catch{}p("$pageview",i,[r.utm,r.click_id_type,s],e)}var Et=(t)=>()=>{if(!(Q&&t==="replace"&&Tt==="push"))Tt=t;w?.(),clearTimeout(Q),Q=setTimeout(S(()=>{Q=void 0,Ht()}),100)},ge=(t)=>{let e=t.closest("[data-datacub-name]")?.getAttribute("data-datacub-name");return e?F(e,100):null},me=!0;function Ne(t){let e="";for(let n=0;t&&n<10&&t!==c.body;n++,t=t.parentElement){let r=1;for(let o=t.previousElementSibling;o;o=o.previousElementSibling)if(o.localName===t.localName)r++;let i=t.id,s=t.getAttribute("data-datacub-name");e=`${t.localName}${i&&!/\d{4}|[\da-f]{8}|^:|radix-|headlessui-|mui-|ember\d|react-select/i.test(i)?`#${k(i,64)}`:""}${r>1?`:${r}`:""}${s?`[${k(s,64)}]`:""}${e&&">"}${e}`}return e.slice(-512)}function Ce(t){let e=t.querySelector(`input,textarea,select,[contenteditable],${$t}`)?"":(t.textContent||"").replace(/\s+/g," ").trim();return k(e&&e.length<101?e:t.getAttribute("aria-label")||t.getAttribute("title")||t.querySelector("img")?.getAttribute("alt")||"",100)||void 0}function qe(t,e){w?.(),ot=void 0;let n=c.activeElement,r=new MutationObserver(()=>w?.()),i=setTimeout(S(()=>{w?.();let s=e.target.closest('a[href]:not([href^="javascript:"]):not([href^="#"])');if(c.activeElement===n&&!(s&&!e.defaultPrevented)&&!(ot&&!ot.defaultPrevented))p("$deadclick",t)}),1000);w=()=>{r.disconnect(),clearTimeout(i),w=void 0},r.observe(c,{subtree:!0,childList:!0,attributes:!0,characterData:!0})}function Pe(t){let e=t.target,n=t;if(!l||!(e instanceof Element)||e.closest(`${$t},input:not([type=submit]):not([type=button]),textarea,select,[contenteditable]:not([contenteditable=false])`))return;let r=e.closest("a,button,summary,input,[data-datacub-name],[role=button],[role=link],[role=menuitem],[role=tab]"),i=!r&&!/^(?:canvas|video)$/.test(e.localName)&&getComputedStyle(e).cursor==="pointer",s=r||e,o={$t:s.localName,$n:ge(e),$g:Ne(s)};if(s.closest("form"))o.$o=!0;if(n.detail)o.$cx=Math.round(n.clientX/C*100),o.$cy=Math.round(n.clientY/dt*100);if((r||i)&&O.text!==!1)o.$l=Ce(s);if(r){let a=r.getAttribute("role");if(a&&/^(?:button|link|menuitem|tab)$/.test(a))o.$r=a;if(r.localName==="input")o.$y=r.type;if(r.localName==="a"&&r.hasAttribute("href"))o.$h=R(r.href)?.url;p("$click",o)}if(me&&n.detail===3&&!(s.textContent?.trim()&&getSelection()?.isCollapsed===!1))p("$rageclick",{...o});if((r||i)&&!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&!s.closest("[target=_blank],[download]"))qe(o,t)}var wt=(t)=>({$f:ge(t),$a:R(new URL(t.getAttribute("action")||"",location.href).href)?.url,$i:t.querySelectorAll("input,select,textarea").length});function je(t){let e=t.target;if(ot=t,!l||e.localName!=="form"||e.closest($t))return;p("$form_submit",wt(e))}var he=(t)=>{let e=t.target.form;return l&&e&&O.forms!==!1&&!e.closest($t)?e:null},Qt=new WeakSet;function Le(t){w?.();let e=he(t);if(e&&!Qt.has(e))Qt.add(e),p("$form_start",wt(e))}var tt=new Map;function Ue(t){w?.();let e=he(t);if(!e)return;let n=tt.get(e)||0;if(tt.set(e,n+1),!n)setTimeout(S(()=>{if(Ft("i",10))p("$form_invalid",{...wt(e),$iv:tt.get(e)});tt.delete(e)}))}var te=(t)=>t.replace(/https?:\/\/[^\s'"<>()]+/g,(e)=>{let n=/(?::\d+){1,2}$/.exec(e)?.[0]||"";return(R(e.slice(0,e.length-n.length))?.url??"")+n});function xt(t,e,n,r,i){let s=`${r}`.startsWith(T.slice(0,-5));if(!l||O.errors===!1||t==="resource"&&(!i||s))return;et++;let o=e&&typeof e==="object"?e:{},a=k(te(`${o.message??n??(e&&e!==o?e:"")}`).replace(/(["'\u201c\u201d\u00ab\u00bb\u2018\u2019])[^"'\u201c\u201d\u00ab\u00bb\u2018\u2019]*["'\u201c\u201d\u00ab\u00bb\u2018\u2019]/g,'"\u2026"'),200),f=typeof o.stack==="string"?k(te(o.stack.split(`
|
|
2
|
+
`).filter((m)=>/:\d+:\d+/.test(m)).slice(0,5).map((m)=>m.trim().replace(/@(?=https?:)/," ")).join(`
|
|
3
|
+
`)),1000):void 0,g=`${t}${o.name}${a}${f?.split(`
|
|
4
|
+
`)[0]}${r}`;if(Ot.has(g)||!Ft("e",20))return;Ot.add(g),p("$error",{$ek:t,$en:typeof o.name==="string"?k(o.name,64):void 0,$em:a||void 0,$es:f||void 0,$eu:r?R(`${r}`)?.url:void 0,$et:i})}function be(t,e,n,r,i){if(!l||O.network===!1)return;let s=new URL(e,location.href).href;if(s.startsWith(T.slice(0,-5)))return;nt++;let o=x()-r,a=i==="AbortError"?"abort":i?"network_error":n>399?"http_error":o>2999&&"slow";if(!a)return;if(a!=="slow"&&a!=="abort")rt++;if(Ft("r",30))p("$request",{$nm:`${t}`.toUpperCase().slice(0,10),$nu:R(s)?.url,$ns:n,$nd:o,$nk:a})}var ee=S(be);function ye(){let t=u.length-1000;if(t>0)y+=u.splice(0,t).length}function Me(){if(!J)try{let r=(s)=>+matchMedia(`(${s})`).matches,i=navigator;J=[screen.width,screen.height,Math.round(devicePixelRatio*100)/100,null,i.hardwareConcurrency,i.deviceMemory,i.maxTouchPoints,r("pointer:coarse")?"c":"f",r("prefers-color-scheme:dark")?"d":"l",r("prefers-reduced-motion:reduce")]}catch{J=Array(10)}let t=navigator.connection||{},e=q.h||[];return[...J,t.effectiveType,t.rtt,t.downlink,+t.saveData,e[0],e[1],-new Date().getTimezoneOffset()]}var jt=(t,e)=>`${JSON.stringify([3,Ut,x(),Rt,e,se,navigator.language,!!navigator.webdriver,Me()]).slice(0,-1)},${t.map((n)=>n[0])}]`;function Lt(t){let e=0,n=200;while(e<u.length&&e<100){if(n+=u[e][1]+1,n>t)break;e++}return u.splice(0,e||1)}var St=!1;async function zt(){if(I(),V)St=!0;if(V||bt||!u.length||!navigator.onLine)return;V=!0;let t=Lt(30720),e=y;y=0;let n=0;try{let r=await pt(T,{method:"POST",body:jt(t,e),keepalive:!0,credentials:"omit",referrerPolicy:"no-referrer"}),i=r.status;if(i===401||i===403)bt=!0,u=[];else if(i===429||i>499)n=Math.min(+(r.headers.get("Retry-After")||0),3600)*1000||-1;else if(lt=0,i>299)y+=t.length+e;else if((await r.json().catch(()=>0)).directives?.includes("rotate_anon_id"))Gt()}catch{n=-1}V=!1;try{if(n&&l){if(u=t.concat(u),y+=e,ye(),++lt<11)I(n>0?n:Math.random()*Math.min(1000*2**lt,300000))}else if(u.length)de(St);St=!1}catch{}}function ne(){if(w?.(),pe(),I(),typeof Request==="function"&&"keepalive"in Request.prototype){let t=V?0:61440;while(u.length&&!bt&&t>2048){let e=Lt(t),n=y,r=jt(e,n);t-=r.length,y=0;let i=()=>{u=e.concat(u),y+=n,I(1000)};try{pt(T,{method:"POST",body:r,keepalive:!0,credentials:"omit",referrerPolicy:"no-referrer"}).catch(i)}catch{i();break}}}else{let t=61440;while(u.length&&!bt&&navigator.sendBeacon){let e=Lt(t);if(navigator.sendBeacon(T,jt(e,y)))y=0;else{if(u=e.concat(u),e.length<2)break;t/=2}}}if(u.length)I(1000)}function $e(t){Y=t?"granted":"not_required";for(let n of ue().reverse())if(b("datacub_tld","1",n,9),X().datacub_tld){b("datacub_tld","",n),gt=n;break}let e=X().datacub_id;if(l=e&&At.test(e)?e:L(),b("datacub_id",l),_=X().datacub_id===l,t){for(let n of["",gt])b("datacub_optout","",n);p("$consent",{$m:/^(?:banner|settings|api|cmp)$/.test(`${t.method}`)?t.method:"api",$P:typeof t.policyVersion==="string"?F(t.policyVersion,64):null})}if(P)_e(...P);if(P=null,Ht(!0,!0),ie&&!q.v){q.v=Rt,q.e=(n,r)=>n==="$form_fields"&&O.forms!==!1&&p(n,r),q.f=wt,window.__datacub=q;try{let n=c.createElement("script");n.src=`${T.slice(0,-5)}sdk/insights-${Rt}.min.js`,n.async=!0,n.referrerPolicy="no-referrer",n.integrity="sha384-7xNcWolajp48vRTTBdYbGMF2VDBSxZ5qtqZeoosFSuy8Os18qOd9cEUDuSCp9I9z",n.crossOrigin="anonymous",n.setAttribute("fetchpriority","low"),(c.head||c.documentElement).append(n)}catch{}}}function De(t={}){if(!l&&(!Ct||t.overrideGPC))$e(t)}function we(){Y="denied",I(),u=[];for(let t of re)for(let e of["",...ue()])b(t,"",e);l=h=W="",E=j=P=K=null,_=!1,b("datacub_optout","1")}function _e(t,e,n){if(Mt(),E&&E!==t)Gt();if(e!==j&&_)b("datacub_a",e);if(j=e,E!==t){if(E=t,_)b("datacub_u",t);n.$A=l}for(let r in n)return p(n.$A?"$identify":"$set",n,0,!0)}function Fe(t,e){if(t&&typeof t==="object")e=t,t=e.id??e.userId??e.user_id;let n=[l,h,W],r=kt(t,n),i=e?.account==null?null:kt(e.account,n);if(!r||e?.account!=null&&!i)return yt("bad id");let s=e&&D(e)||{};for(let o in s){let a=/^(?:account|id|user_?id|(email)|(?:full_?)?(name)|(phone)(?:_?number)?)$/i.exec(o);if(a){let f=a[1]||a[2]||a[3];if(f)s[`$${f.toLowerCase()}`]=e[o];delete s[o]}}if(l)_e(r,i,s);else if(Y==="pending")P=[r,i,s]}function Gt(){if(P=null,!l)return;if(zt(),l=L(),E=j=null,h="",_){b("datacub_id",l);for(let t of re.slice(1))b(t,"")}}function He(t,e={}){if(oe=/^(?:localhost|127\.0\.0\.1|\[::1\])$|\.(?:localhost|test)$/.test(location.hostname),ft||typeof t!=="string")return;if(/^sk_/.test(t))return console.error("[datacub] refused a secret key. Use your project ID.");let n;try{n=new URL(e.apiHost||"https://in.datacub.to",location.href)}catch{}if(!/^(?:pk_(?:live|test)_[A-Za-z0-9]{24,48}|[a-z0-9]{8})$/.test(t))return yt("init: bad key");if(!n||n.username||n.password||!(n.protocol==="https:"||n.protocol==="http:"&&/^(?:localhost|127\.0\.0\.1)$/.test(n.hostname)))return yt("init: bad apiHost");if(ft=!0,Ut=t,B=`_${t.replace(/^pk_[a-z]+_/,"").slice(0,8)}`,T=`${n.origin}${n.pathname.replace(/\/+$/,"")}/v1/batch`,Nt=e.hashRouting===!0,se=typeof e.release==="string"&&!H(e.release)?e.release.slice(0,64):null,O=e.capture&&typeof e.capture==="object"&&e.capture||{},ie=e.insights!==!1,pt=fetch,Ct=navigator.globalPrivacyControl===!0,Ct||X().datacub_optout)we();else if(!e.requireConsent)$e();if(me=e.rageClicks!==!1,e.autocapture!==!1)d(c,"click",Pe),d(c,"submit",je),d(c,"input",Le),d(c,"invalid",Ue);for(let r of["pointerdown","keydown","scroll"])d(c,r,(i)=>{let s=x();if(i.target===c)ut();if(r==="scroll")w?.();if(h&&c.visibilityState==="visible"&&s-Zt>5000)Zt=s,Mt(),fe(s,!0)});d(c,"visibilitychange",()=>{if(Dt(),c.visibilityState==="hidden")ne()}),ut(),d(window,"resize",ut),d(window,"pagehide",ne),d(window,"pageshow",(r)=>r.persisted&&Ht(!0)),d(window,"online",zt),d(window,"popstate",Et("pop")),d(window,"hashchange",Et("hash"));for(let r of["pushState","replaceState"]){let i=history[r];history[r]=function(...s){i.apply(this,s),Et(r==="pushState"?"push":"replace")()}}try{d(window,"error",(o)=>o instanceof ErrorEvent?xt("js",o.error,o.message,o.filename):xt("resource",0,"",o.target.src||o.target.href,o.target.localName)),d(window,"unhandledrejection",(o)=>xt("rejection",o.reason)),window.fetch=function(...o){let a=pt.apply(this,o);try{let f=x(),g=o[0],m=`${g.url||g}`,M=o[1]?.method||g.method||"GET";return a.then((N)=>{try{ee(M,N.url||m,N.type==="opaque"?200:N.status,f)}catch{}return N},(N)=>{throw ee(M,m,0,f,N?.name||"Error"),N})}catch{}return a};let r=XMLHttpRequest.prototype,{open:i,send:s}=r;r.open=function(...o){return this._x=o,i.apply(this,o)},r.send=function(...o){if(this._x&&!this._t)for(let a of["load","error","abort","timeout"])d(this,a,()=>be(this._x?.[0],`${this._x?.[1]}`,this.status,this._t,a==="load"?"":a==="abort"?"AbortError":"TypeError"));return this._t=x(),s.apply(this,o)}}catch{}}var z=(t)=>S((...e)=>{if(typeof window>"u")return;if(ft)t(...e);else if(Pt.length<100)Pt.push([t,e])}),ze={init:S((t,e)=>{if(typeof window>"u"||!globalThis.crypto?.getRandomValues)return;c=document;let n=S(()=>{He(t,e);for(let[r,i]of Pt.splice(0))if(ft)r(...i)});if(c.prerendering)d(c,"prerenderingchange",n);else n()}),track:z(Te),identify:z(Fe),reset:z(Gt),consent:{grant:z(De),revoke:z(we)},_fb:()=>[Y,_,Ut,T,l,E,h,p]},U=ze;var _t=window;if(!_t.datacub?._fb){let t=Array.isArray(_t.datacub)?_t.datacub:[],e=document.currentScript,n=e?.dataset,r=e?.src?new URL(e.src).origin:void 0,i=U.init;U.init=(o,a)=>{let f=a?.apiHost||r;return i(o,f?{...a,apiHost:f}:a)},_t.datacub=U;let s=n?.id||n?.key;if(s)U.init(s,{apiHost:n.apiHost,requireConsent:n.requireConsent!=null});for(let o of t)try{let[a,...f]=o,g=String(a).split(".").reduce((m,M)=>m&&Object.hasOwn(m,M)?m[M]:void 0,U);if(typeof g==="function")g(...f)}catch{}}})();
|
package/dist/datacub.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var v={n:0},$t=(t)=>t.replace(/[\u0660-\u0669\u06f0-\u06f9\uff10-\uff19]/g,(e)=>String(e.charCodeAt(0)&15)),we=/[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]/g,Gt=(t)=>$t(t).replace(we,""),_e=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|bearer\s+\S{16,}|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]+|PRIVATE KEY|[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}|eyJ[\w-]+\.[\w-]+\.[\w-]*|\d(?:[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]*\d){8,}|[\w+/=]{32,}/gi;function Y(t){let e="",n=0;for(let r of $t(t).matchAll(_e)){if(/^[0-9a-f]{8}-/i.test(r[0])&&r[0].length===36)continue;e+=`${t.slice(n,r.index)}[redacted]`,n=r.index+r[0].length,v.n++}return e+t.slice(n)}function M(t,e=1024){if(t=t.normalize("NFC"),t.length>256||t.trim().split(/\s+/).length>11)return v.n++,"[redacted]";return Y(t).slice(0,e).replace(/[\uD800-\uDBFF]$/,"")}var D=(t)=>/[\u0000-\u001f\u007f-\u009f\u200e\u200f\u061c\u202a-\u202e\u2066-\u2069]/.test(t),ve=/(?:passw(?:or)?d|passcode|pwd|pin|pincode|otp|otpcode|onetimecode|mfacode|2facode|tfacode|smscode|secretkey|privatekey|authcode|verificationcode|securitycode|resetcode|cvv|cvc|cardnumber|ccnumber|creditcard|pan|iban|iqama|hawiya|nationalid|nid|idnumber|ssn|token|authorization|secret|apikey|sessionid|cookie|jwt|bearer|csrf|xsrf|passport|\u0643\u0644\u0645\u0647\u0627\u0644\u0645\u0631\u0648\u0631|\u0643\u0644\u0645\u0647\u0627\u0644\u0633\u0631|\u0627\u0644\u0631\u0645\u0632\u0627\u0644\u0633\u0631\u064a|\u0627\u0644\u0631\u0642\u0645\u0627\u0644\u0633\u0631\u064a|\u0631\u0645\u0632\u0627\u0644\u062a\u062d\u0642\u0642|\u0631\u0642\u0645\u0627\u0644\u0647\u0648\u064a\u0647|\u0627\u0644\u0647\u0648\u064a\u0647\u0627\u0644\u0648\u0637\u0646\u064a\u0647|\u0627\u0644\u0627\u0642\u0627\u0645\u0647|\u0627\u0644\u0628\u0637\u0627\u0642\u0647|\u0627\u0644\u0627\u064a\u0628\u0627\u0646)$/;function Vt(t,e){let n=t.normalize("NFKD").replace(/[\p{M}\u0640]/gu,"").replace(/\u0629/g,"\u0647").replace(/\u0649/g,"\u064a").replace(/(\p{Ll})(?=\p{Lu})|(\p{N}+)/gu,"$1 $2 ").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);while(n.length>1&&/^\p{N}+$/u.test(n[n.length-1]))n.pop();return!t||[...t].length>200||/\./.test(t)||D(t)||/^(?:__proto__|constructor|prototype)$/.test(t)||e&&/^(?:\$|(?:distinct_id|person_id|project_id|timestamp|uuid|ip|api_key)$)/.test(t)||ve.test(n.join(""))&&!/^(?:japan|span|timespan|lifespan|wingspan|saucepan|spin|chopin|android)$/.test(n[n.length-1])||n.some((r)=>/^(?:password|passwd|pwd|passcode|otp|pin|secret|iqama|ssn|cvv|cvc|iban)$/.test(r))}function U(t,e=0){if(typeof t==="string")return M(t);if(typeof t==="number")return Number.isFinite(t)?Number.isInteger(t)&&Y(`${t}`)!==`${t}`?"[redacted]":t:void 0;if(typeof t==="boolean"||t===null)return t;if(t instanceof Date)return Number.isNaN(+t)?void 0:t.toISOString();if(typeof t!=="object")return;if(e>2)return"[depth]";if(Array.isArray(t))return t.slice(0,100).map((i)=>U(i,e+1)).filter((i)=>i!==void 0);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n)return;let r={};for(let[i,s]of Object.entries(t).slice(0,200)){let o=i.trim();if(Vt(o,!e))v.n++;else{let a=U(s,e+1);if(a!==void 0)r[o]=a}}return r}function Bt(t){let e=t;try{e=decodeURIComponent(t)}catch{}e=$t(e);let n=v.n;if(Y(e)!==e)return v.n=n+1,":redacted";if(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(e))return":uuid";if(/^[0-9a-f]{16,}$/i.test(e))return e.length===24?":id":":hash";if(/^[\w-]{20,}$/.test(e)&&/\d/.test(e)&&/[a-z]/.test(e)&&/[A-Z]/.test(e))return":token";let r=e.replace(/\D/g,"").length;return r&&(r===e.length||r>3&&r*2>=e.length)?":id":t}var ke=/^(?:reset|invite|sid|token|jwt|otp|code|key|state|sig(?:nature)?|auth\w*|nonce|session\w*|hash|q|query|search\w*|s|keywords?|term|text|msg|message|comments?|\w*name|e?-?mail\w*|phone|mobile|tel|address\w*|city|zip|postcode|dob|birth\w*)$/i,Ee=(t)=>/^(?:[a-z0-9][a-z0-9._~-]*|[A-Z0-9][A-Z0-9_-]*)$/.test(t)&&!(t.length>=8&&/\d/.test(t)&&/[a-z]/i.test(t)),k=(t,e)=>Y(t.normalize("NFC")).slice(0,e),Ht=(t)=>t.split("/").map((e)=>e&&Bt(e)).join("/");function R(t,e,n){let r;try{r=new URL(t)}catch{return null}let i=r.protocol;if(/^(?:mailto|tel|sms|whatsapp):$/.test(i))return{url:i,path:i};if(!/^https?:$/.test(i))return null;let s=Ht(r.pathname);if(e&&/^#!?\//.test(r.hash))s+=`#${Ht(r.hash.slice(1).split("?")[0])}`;s=s.slice(0,1024);let o={url:(r.origin+s).slice(0,2048),path:s};for(let[a,p]of r.searchParams){let h=a.toLowerCase();if(/^utm_(?:source|medium|campaign|term|content)$/.test(h)&&p)o.utm={...o.utm,[h.slice(4)]:M(p,200)};else if(/^(?:gclid|gbraid|wbraid|fbclid|ttclid|msclkid|sccid|twclid|li_fat_id)$/.test(h))o.click_id_type=h.replace(/^[gw]braid$/,"gclid");else if(n&&Object.keys(o.q||{}).length<30){let y=Bt(p);o.q??={},o.q[k(a,64)]=Vt(a,!1)||ke.test(a)||p.length>40||!(y[0]===":"||Ee(p))?"":y===":redacted"?"":y}}return o}function Kt(t){let e=t.trim().normalize("NFC");return!e||[...e].length>100||e[0]==="$"||D(e)||/[0-9a-f]{8}-[0-9a-f]{4}-|[0-9a-f]{16}|@/i.test(e)||/\d{6}/.test(Gt(e))?null:e}function wt(t,e){if(typeof t==="number"&&Number.isFinite(t))t=`${t}`;if(typeof t!=="string")return null;let n=t.trim().normalize("NFC"),r=Gt(n),i=0;for(let s=0;s<r.length;s++){let o=+r[r.length-1-s];i+=s%2?o>4?o*2-9:o*2:o}return!n||[...n].length>128||/^(?:null|undefined|0|-1|anonymous|guest|\[object object\]|none|nan|false|true|user|test|unknown|not_authenticated|distinct_id|id)$/i.test(n)||D(n)||/@|^eyJ/.test(n)||/^(?:[12]\d{9}|(?:\+?966|00966|0)5\d{8}|\+\d{8,15})$/.test(r)||/^[2-6]\d{14,15}$/.test(r)&&i%10===0||e.includes(n)?null:n}var Et="0.4.2",Xt=1800000,xe=86400000,Se=34560000,xt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,bt=".datacub-no-capture,[data-datacub-no-capture]",ee=["datacub_id","datacub_u","datacub_a","datacub_ss"],c,lt=!1,N={},ne=!0,St=0,Q=0,tt=0,et=0,nt={},Rt=new Set,At,O=0,ut=0,w,rt,ft,W,P={},re=!1,jt="",T="",It=!1,ie=null,K="pending",Nt=!1,_=!1,G="",dt="",l="",E=null,q=null,j=null,g="",it=0,A=0,oe,z=0,X="",V=null,Re=0,ot=0,pt=0,gt=0,se="",st=!0,Z,Yt=0,u=[],Tt,ae=!1,Wt="",H=!1,at=0,mt=!1,b=0,Ct=[],x=Date.now;function ht(t){if(re)console.warn(`[datacub] ${t}`)}var S=(t)=>(...e)=>{try{t(...e)}catch{}},f=(t,e,n)=>t.addEventListener(e,S(n),!0);function L(t){let e=crypto.getRandomValues(new Uint8Array(16));for(let r=5,i=t;t&&r>=0;r--,i=Math.floor(i/256))e[r]=i&255;return e[6]=e[6]&15|(t?112:64),e[8]=e[8]&63|128,Array.from(e,(r)=>(r+256).toString(16).slice(1)).join("").replace(/(.{8})(.{4})(.{4})(.{4})/,"$1-$2-$3-$4-")}function B(){let t={};try{for(let e of c.cookie.split("; ")){let n=e.indexOf("="),r=e.slice(0,n);if(r==="datacub_optout"||G&&r.endsWith(G))t[r==="datacub_optout"?r:r.slice(0,-G.length)]=decodeURIComponent(e.slice(n+1))}}catch{}return t}function m(t,e,n=dt,r=e?Se:0){try{c.cookie=`${t==="datacub_optout"?t:t+G}=${encodeURIComponent(e||"")};Path=/;Max-Age=${r};SameSite=Lax${n}${location.protocol==="https:"?";Secure":""}`}catch{}}function ce(){let t=location.hostname.split(".");return/^[\d.]+$|:/.test(location.hostname)?[]:t.slice(0,-1).map((e,n)=>`;Domain=${t.slice(n).join(".")}`)}function qt(){if(!_)return;let t=B(),e=t.datacub_id??null;if(e!==l)l=e&&xt.test(e)?e:L(),m("datacub_id",l),g="";E=t.datacub_u??null,q=t.datacub_a??null;let[n,r,i]=(t.datacub_ss||"").split(".");if(oe=n,z=+i,n&&xt.test(n)&&z&&(n!==g||z>A))g=n,it=+r,A=z}function le(t,e){if(!g||t-A>Xt||t-it>xe){if(g=L(x()),it=A=t,_)m("datacub_id",l)}else if(e&&t>A)A=t;if(_&&(oe!==g||A-z>5000))m("datacub_ss",`${g}.${it}.${A}`,dt,Xt/1000)}function I(t){clearTimeout(Tt),ae=t===0,Tt=t==null?void 0:setTimeout(S(Dt),t)}function ue(t){if((t||u.length>19||c.visibilityState==="hidden")&&!ae&&!at)I(0);else if(!Tt)I(5000)}var Ae=new TextEncoder;function d(t,e,n,r){if(!l)return;let i=x();if(qt(),le(i,!/^\$(?:pageleave|error|request|form_fields)$/.test(t)),v.n)e={...e,$d:v.n};let s=JSON.stringify([L(i),t,i,l,E,q,g,X||null,Re++,+(K==="granted"),+_,V?.url,se,e,n]),o=Ae.encode(s).length;if(o>31000){b++;return}v.n=0,u.push([s,o]),he(),ue(r)}function Ie(t,e){if(!l||typeof t!=="string")return;let n=Kt(t);if(!n)return ht("bad name");d(n,e&&typeof e==="object"&&!Array.isArray(e)&&U(e)||{})}function Lt(t=x()){if(ot)pt+=t-ot;ot=c.visibilityState==="visible"?t:0}var ct=()=>{O=innerWidth,ut=innerHeight,se=O<360?"xs":O<480?"s":O<768?"m":O<1280?"l":"xl",gt=Math.max(gt,scrollY+ut)};function Ut(t,e){return nt[t]=(nt[t]||0)+1,nt[t]<=e}function fe(){if(!X)return;Lt();let t=pt-St;if(st&&t<1)return;let e=c.documentElement.scrollHeight,n={$v:t,$s:e?gt/e:null};if(st)n.$e=!0;if(Q)n.$ec=Q;if(tt)n.$rq=tt;if(et)n.$rf=et;Q=tt=et=0;try{Object.assign(n,P.l?.())}catch{}st=!0,St=pt,d("$pageleave",n)}function Mt(t,e){if(!l)return;let n=location.pathname+(It?location.hash.split("?")[0]:"");if(!t&&n===Wt)return;let r=R(location.href,It,N.query!==!1);if(!r)return;Wt=n,fe();let i={};if(V)i.$p=V.path;if(t&&!e)i.$b=!0;if(i.$N=e?performance.getEntriesByType?.("navigation")[0]?.type:t?"back_forward":At,r.q)i.$q=r.q;if(N.title!==!1&&c.title)i.$T=k(c.title,200);V=r,X=L(x()),st=!1,pt=gt=ot=St=0,nt={},Rt.clear(),Lt(),ct(),i.$vw=O,i.$vh=ut;let s=null;if(e)try{let o=new URL(c.referrer);s=o.hostname,i.$R=R(o.href)?.path}catch{}d("$pageview",i,[r.utm,r.click_id_type,s],e)}var _t=(t)=>()=>{if(!(Z&&t==="replace"&&At==="push"))At=t;w?.(),clearTimeout(Z),Z=setTimeout(S(()=>{Z=void 0,Mt()}),100)},de=(t)=>{let e=t.closest("[data-datacub-name]")?.getAttribute("data-datacub-name");return e?M(e,100):null},pe=!0;function Ne(t){let e="";for(let n=0;t&&n<10&&t!==c.body;n++,t=t.parentElement){let r=1;for(let o=t.previousElementSibling;o;o=o.previousElementSibling)if(o.localName===t.localName)r++;let i=t.id,s=t.getAttribute("data-datacub-name");e=`${t.localName}${i&&!/\d{4}|[\da-f]{8}|^:|radix-|headlessui-|mui-|ember\d|react-select/i.test(i)?`#${k(i,64)}`:""}${r>1?`:${r}`:""}${s?`[${k(s,64)}]`:""}${e&&">"}${e}`}return e.slice(-512)}function Te(t){let e=t.querySelector(`input,textarea,select,[contenteditable],${bt}`)?"":(t.textContent||"").replace(/\s+/g," ").trim();return k(e&&e.length<101?e:t.getAttribute("aria-label")||t.getAttribute("title")||t.querySelector("img")?.getAttribute("alt")||"",100)||void 0}function Ce(t,e){w?.(),rt=void 0;let n=c.activeElement,r=new MutationObserver(()=>w?.()),i=setTimeout(S(()=>{w?.();let s=e.target.closest('a[href]:not([href^="javascript:"]):not([href^="#"])');if(c.activeElement===n&&!(s&&!e.defaultPrevented)&&!(rt&&!rt.defaultPrevented))d("$deadclick",t)}),1000);w=()=>{r.disconnect(),clearTimeout(i),w=void 0},r.observe(c,{subtree:!0,childList:!0,attributes:!0,characterData:!0})}function Oe(t){let e=t.target,n=t;if(!l||!(e instanceof Element)||e.closest(`${bt},input:not([type=submit]):not([type=button]),textarea,select,[contenteditable]:not([contenteditable=false])`))return;let r=e.closest("a,button,summary,input,[data-datacub-name],[role=button],[role=link],[role=menuitem],[role=tab]"),i=!r&&!/^(?:canvas|video)$/.test(e.localName)&&getComputedStyle(e).cursor==="pointer",s=r||e,o={$t:s.localName,$n:de(e),$g:Ne(s)};if(s.closest("form"))o.$o=!0;if(n.detail)o.$cx=Math.round(n.clientX/O*100),o.$cy=Math.round(n.clientY/ut*100);if((r||i)&&N.text!==!1)o.$l=Te(s);if(r){let a=r.getAttribute("role");if(a&&/^(?:button|link|menuitem|tab)$/.test(a))o.$r=a;if(r.localName==="input")o.$y=r.type;if(r.localName==="a"&&r.hasAttribute("href"))o.$h=R(r.href)?.url;d("$click",o)}if(pe&&n.detail===3&&!(s.textContent?.trim()&&getSelection()?.isCollapsed===!1))d("$rageclick",{...o});if((r||i)&&!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&!s.closest("[target=_blank],[download]"))Ce(o,t)}var yt=(t)=>({$f:de(t),$a:R(new URL(t.getAttribute("action")||"",location.href).href)?.url,$i:t.querySelectorAll("input,select,textarea").length});function Pe(t){let e=t.target;if(rt=t,!l||e.localName!=="form"||e.closest(bt))return;d("$form_submit",yt(e))}var ge=(t)=>{let e=t.target.form;return l&&e&&N.forms!==!1&&!e.closest(bt)?e:null},Zt=new WeakSet;function je(t){w?.();let e=ge(t);if(e&&!Zt.has(e))Zt.add(e),d("$form_start",yt(e))}var J=new Map;function qe(t){w?.();let e=ge(t);if(!e)return;let n=J.get(e)||0;if(J.set(e,n+1),!n)setTimeout(S(()=>{if(Ut("i",10))d("$form_invalid",{...yt(e),$iv:J.get(e)});J.delete(e)}))}var Jt=(t)=>t.replace(/https?:\/\/[^\s'"<>()]+/g,(e)=>{let n=/(?::\d+){1,2}$/.exec(e)?.[0]||"";return(R(e.slice(0,e.length-n.length))?.url??"")+n});function vt(t,e,n,r,i){let s=`${r}`.startsWith(T.slice(0,-5));if(!l||N.errors===!1||t==="resource"&&(!i||s))return;Q++;let o=e&&typeof e==="object"?e:{},a=k(Jt(`${o.message??n??(e&&e!==o?e:"")}`).replace(/(["'\u201c\u201d\u00ab\u00bb\u2018\u2019])[^"'\u201c\u201d\u00ab\u00bb\u2018\u2019]*["'\u201c\u201d\u00ab\u00bb\u2018\u2019]/g,'"\u2026"'),200),p=typeof o.stack==="string"?k(Jt(o.stack.split(`
|
|
2
|
+
`).filter((y)=>/:\d+:\d+/.test(y)).slice(0,5).map((y)=>y.trim().replace(/@(?=https?:)/," ")).join(`
|
|
3
|
+
`)),1000):void 0,h=`${t}${o.name}${a}${p?.split(`
|
|
4
|
+
`)[0]}${r}`;if(Rt.has(h)||!Ut("e",20))return;Rt.add(h),d("$error",{$ek:t,$en:typeof o.name==="string"?k(o.name,64):void 0,$em:a||void 0,$es:p||void 0,$eu:r?R(`${r}`)?.url:void 0,$et:i})}function me(t,e,n,r,i){if(!l||N.network===!1)return;let s=new URL(e,location.href).href;if(s.startsWith(T.slice(0,-5)))return;tt++;let o=x()-r,a=i==="AbortError"?"abort":i?"network_error":n>399?"http_error":o>2999&&"slow";if(!a)return;if(a!=="slow"&&a!=="abort")et++;if(Ut("r",30))d("$request",{$nm:`${t}`.toUpperCase().slice(0,10),$nu:R(s)?.url,$ns:n,$nd:o,$nk:a})}var Qt=S(me);function he(){let t=u.length-1000;if(t>0)b+=u.splice(0,t).length}function Le(){if(!W)try{let r=(s)=>+matchMedia(`(${s})`).matches,i=navigator;W=[screen.width,screen.height,Math.round(devicePixelRatio*100)/100,null,i.hardwareConcurrency,i.deviceMemory,i.maxTouchPoints,r("pointer:coarse")?"c":"f",r("prefers-color-scheme:dark")?"d":"l",r("prefers-reduced-motion:reduce")]}catch{W=Array(10)}let t=navigator.connection||{},e=P.h||[];return[...W,t.effectiveType,t.rtt,t.downlink,+t.saveData,e[0],e[1],-new Date().getTimezoneOffset()]}var Ot=(t,e)=>`${JSON.stringify([3,jt,x(),Et,e,ie,navigator.language,!!navigator.webdriver,Le()]).slice(0,-1)},${t.map((n)=>n[0])}]`;function Pt(t){let e=0,n=200;while(e<u.length&&e<100){if(n+=u[e][1]+1,n>t)break;e++}return u.splice(0,e||1)}var kt=!1;async function Dt(){if(I(),H)kt=!0;if(H||mt||!u.length||!navigator.onLine)return;H=!0;let t=Pt(30720),e=b;b=0;let n=0;try{let r=await ft(T,{method:"POST",body:Ot(t,e),keepalive:!0,credentials:"omit",referrerPolicy:"no-referrer"}),i=r.status;if(i===401||i===403)mt=!0,u=[];else if(i===429||i>499)n=Math.min(+(r.headers.get("Retry-After")||0),3600)*1000||-1;else if(at=0,i>299)b+=t.length+e;else if((await r.json().catch(()=>0)).directives?.includes("rotate_anon_id"))Ft()}catch{n=-1}H=!1;try{if(n&&l){if(u=t.concat(u),b+=e,he(),++at<11)I(n>0?n:Math.random()*Math.min(1000*2**at,300000))}else if(u.length)ue(kt);kt=!1}catch{}}function te(){if(w?.(),fe(),I(),typeof Request==="function"&&"keepalive"in Request.prototype){let t=H?0:61440;while(u.length&&!mt&&t>2048){let e=Pt(t),n=b,r=Ot(e,n);t-=r.length,b=0;let i=()=>{u=e.concat(u),b+=n,I(1000)};try{ft(T,{method:"POST",body:r,keepalive:!0,credentials:"omit",referrerPolicy:"no-referrer"}).catch(i)}catch{i();break}}}else{let t=61440;while(u.length&&!mt&&navigator.sendBeacon){let e=Pt(t);if(navigator.sendBeacon(T,Ot(e,b)))b=0;else{if(u=e.concat(u),e.length<2)break;t/=2}}}if(u.length)I(1000)}function be(t){K=t?"granted":"not_required";for(let n of ce().reverse())if(m("datacub_tld","1",n,9),B().datacub_tld){m("datacub_tld","",n),dt=n;break}let e=B().datacub_id;if(l=e&&xt.test(e)?e:L(),m("datacub_id",l),_=B().datacub_id===l,t){for(let n of["",dt])m("datacub_optout","",n);d("$consent",{$m:/^(?:banner|settings|api|cmp)$/.test(`${t.method}`)?t.method:"api",$P:typeof t.policyVersion==="string"?M(t.policyVersion,64):null})}if(j)$e(...j);if(j=null,Mt(!0,!0),ne&&!P.v){P.v=Et,P.e=(n,r)=>n==="$form_fields"&&N.forms!==!1&&d(n,r),P.f=yt,window.__datacub=P;try{let n=c.createElement("script");n.src=`${T.slice(0,-5)}sdk/insights-${Et}.min.js`,n.async=!0,n.referrerPolicy="no-referrer",n.integrity="sha384-7xNcWolajp48vRTTBdYbGMF2VDBSxZ5qtqZeoosFSuy8Os18qOd9cEUDuSCp9I9z",n.crossOrigin="anonymous",n.setAttribute("fetchpriority","low"),(c.head||c.documentElement).append(n)}catch{}}}function Ue(t={}){if(!l&&(!Nt||t.overrideGPC))be(t)}function ye(){K="denied",I(),u=[];for(let t of ee)for(let e of["",...ce()])m(t,"",e);l=g=X="",E=q=j=V=null,_=!1,m("datacub_optout","1")}function $e(t,e,n){if(qt(),E&&E!==t)Ft();if(e!==q&&_)m("datacub_a",e);if(q=e,E!==t){if(E=t,_)m("datacub_u",t);n.$A=l}for(let r in n)return d(n.$A?"$identify":"$set",n,0,!0)}function Me(t,e){if(t&&typeof t==="object")e=t,t=e.id??e.userId??e.user_id;let n=[l,g,X],r=wt(t,n),i=e?.account==null?null:wt(e.account,n);if(!r||e?.account!=null&&!i)return ht("bad id");let s=e&&U(e)||{};for(let o in s){let a=/^(?:account|id|user_?id|(email)|(?:full_?)?(name)|(phone)(?:_?number)?)$/i.exec(o);if(a){let p=a[1]||a[2]||a[3];if(p)s[`$${p.toLowerCase()}`]=e[o];delete s[o]}}if(l)$e(r,i,s);else if(K==="pending")j=[r,i,s]}function Ft(){if(j=null,!l)return;if(Dt(),l=L(),E=q=null,g="",_){m("datacub_id",l);for(let t of ee.slice(1))m(t,"")}}function De(t,e={}){if(re=/^(?:localhost|127\.0\.0\.1|\[::1\])$|\.(?:localhost|test)$/.test(location.hostname),lt||typeof t!=="string")return;if(/^sk_/.test(t))return console.error("[datacub] refused a secret key. Use your project ID.");let n;try{n=new URL(e.apiHost||"https://in.datacub.to",location.href)}catch{}if(!/^(?:pk_(?:live|test)_[A-Za-z0-9]{24,48}|[a-z0-9]{8})$/.test(t))return ht("init: bad key");if(!n||n.username||n.password||!(n.protocol==="https:"||n.protocol==="http:"&&/^(?:localhost|127\.0\.0\.1)$/.test(n.hostname)))return ht("init: bad apiHost");if(lt=!0,jt=t,G=`_${t.replace(/^pk_[a-z]+_/,"").slice(0,8)}`,T=`${n.origin}${n.pathname.replace(/\/+$/,"")}/v1/batch`,It=e.hashRouting===!0,ie=typeof e.release==="string"&&!D(e.release)?e.release.slice(0,64):null,N=e.capture&&typeof e.capture==="object"&&e.capture||{},ne=e.insights!==!1,ft=fetch,Nt=navigator.globalPrivacyControl===!0,Nt||B().datacub_optout)ye();else if(!e.requireConsent)be();if(pe=e.rageClicks!==!1,e.autocapture!==!1)f(c,"click",Oe),f(c,"submit",Pe),f(c,"input",je),f(c,"invalid",qe);for(let r of["pointerdown","keydown","scroll"])f(c,r,(i)=>{let s=x();if(i.target===c)ct();if(r==="scroll")w?.();if(g&&c.visibilityState==="visible"&&s-Yt>5000)Yt=s,qt(),le(s,!0)});f(c,"visibilitychange",()=>{if(Lt(),c.visibilityState==="hidden")te()}),ct(),f(window,"resize",ct),f(window,"pagehide",te),f(window,"pageshow",(r)=>r.persisted&&Mt(!0)),f(window,"online",Dt),f(window,"popstate",_t("pop")),f(window,"hashchange",_t("hash"));for(let r of["pushState","replaceState"]){let i=history[r];history[r]=function(...s){i.apply(this,s),_t(r==="pushState"?"push":"replace")()}}try{f(window,"error",(o)=>o instanceof ErrorEvent?vt("js",o.error,o.message,o.filename):vt("resource",0,"",o.target.src||o.target.href,o.target.localName)),f(window,"unhandledrejection",(o)=>vt("rejection",o.reason)),window.fetch=function(...o){let a=ft.apply(this,o);try{let p=x(),h=o[0],y=`${h.url||h}`,zt=o[1]?.method||h.method||"GET";return a.then((C)=>{try{Qt(zt,C.url||y,C.type==="opaque"?200:C.status,p)}catch{}return C},(C)=>{throw Qt(zt,y,0,p,C?.name||"Error"),C})}catch{}return a};let r=XMLHttpRequest.prototype,{open:i,send:s}=r;r.open=function(...o){return this._x=o,i.apply(this,o)},r.send=function(...o){if(this._x&&!this._t)for(let a of["load","error","abort","timeout"])f(this,a,()=>me(this._x?.[0],`${this._x?.[1]}`,this.status,this._t,a==="load"?"":a==="abort"?"AbortError":"TypeError"));return this._t=x(),s.apply(this,o)}}catch{}}var F=(t)=>S((...e)=>{if(typeof window>"u")return;if(lt)t(...e);else if(Ct.length<100)Ct.push([t,e])}),Fe={init:S((t,e)=>{if(typeof window>"u"||!globalThis.crypto?.getRandomValues)return;c=document;let n=S(()=>{De(t,e);for(let[r,i]of Ct.splice(0))if(lt)r(...i)});if(c.prerendering)f(c,"prerenderingchange",n);else n()}),track:F(Ie),identify:F(Me),reset:F(Ft),consent:{grant:F(Ue),revoke:F(ye)},_fb:()=>[K,_,jt,T,l,E,g,d]},Ve=Fe;export{Et as VERSION,Ve as default};
|
package/dist/feedback.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
(()=>{var B={n:0},W=(s)=>s.replace(/[\u0660-\u0669\u06f0-\u06f9\uff10-\uff19]/g,(e)=>String(e.charCodeAt(0)&15));var se=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|bearer\s+\S{16,}|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]+|PRIVATE KEY|[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}|eyJ[\w-]+\.[\w-]+\.[\w-]*|\d(?:[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]*\d){8,}|[\w+/=]{32,}/gi;function ae(s){let e="",l=0;for(let r of W(s).matchAll(se)){if(/^[0-9a-f]{8}-/i.test(r[0])&&r[0].length===36)continue;e+=`${s.slice(l,r.index)}[redacted]`,l=r.index+r[0].length,B.n++}return e+s.slice(l)}function G(s){let e=s;try{e=decodeURIComponent(s)}catch{}e=W(e);let l=B.n;if(ae(e)!==e)return B.n=l+1,":redacted";if(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(e))return":uuid";if(/^[0-9a-f]{16,}$/i.test(e))return e.length===24?":id":":hash";if(/^[\w-]{20,}$/.test(e)&&/\d/.test(e)&&/[a-z]/.test(e)&&/[A-Z]/.test(e))return":token";let r=e.replace(/\D/g,"").length;return r&&(r===e.length||r>3&&r*2>=e.length)?":id":s}var Z={en:{close:"Close",send:"Send",sending:"Sending",thanks:"Thanks for sharing!",failed:"Could not send. Try again.",yes:"Yes",no:"No",low:"Not likely",high:"Very likely",type:"Type your answer",general:"What\u2019s on your mind?",tell:"Tell us anything"},ar:{close:"\u0625\u063a\u0644\u0627\u0642",send:"\u0625\u0631\u0633\u0627\u0644",sending:"\u062c\u0627\u0631\u064d \u0627\u0644\u0625\u0631\u0633\u0627\u0644",thanks:"\u0634\u0643\u0631\u064b\u0627 \u0639\u0644\u0649 \u0645\u0634\u0627\u0631\u0643\u062a\u0643!",failed:"\u062a\u0639\u0630\u0651\u0631 \u0627\u0644\u0625\u0631\u0633\u0627\u0644\u060c \u062d\u0627\u0648\u0644 \u0645\u0631\u0629 \u062b\u0627\u0646\u064a\u0629.",yes:"\u0646\u0639\u0645",no:"\u0644\u0627",low:"\u063a\u064a\u0631 \u0645\u062d\u062a\u0645\u0644",high:"\u0645\u062d\u062a\u0645\u0644 \u062c\u062f\u064b\u0627",type:"\u0627\u0643\u062a\u0628 \u0625\u062c\u0627\u0628\u062a\u0643",general:"\u0645\u0627 \u0627\u0644\u0630\u064a \u064a\u062f\u0648\u0631 \u0641\u064a \u0628\u0627\u0644\u0643\u061f",tell:"\u0627\u0643\u062a\u0628 \u0645\u0627 \u062a\u0631\u064a\u062f"}},J="--bg:#1c1c1f;--fg:#fafafa;--mut:#a1a1aa;--opt:#2a2a2e;--opt-h:#333338;--edge:rgba(255,255,255,.08);--x:#8b8b93;--line:#55555c",Q=`
|
|
2
|
+
:host{all:initial}
|
|
3
|
+
*{box-sizing:border-box;margin:0}
|
|
4
|
+
.w{--a:#1f1f1f;--on:#fff;--bg:#fff;--fg:#18181b;--mut:#71717a;--opt:#f4f4f5;--opt-h:#ebebee;--edge:rgba(24,24,27,.07);--x:#a1a1aa;--line:#d4d4d8;
|
|
5
|
+
position:fixed;z-index:2147483000;bottom:16px;right:16px;width:360px;max-width:calc(100vw - 24px);
|
|
6
|
+
font:14px/1.45 system-ui,-apple-system,"Segoe UI","SF Arabic","Noto Sans Arabic",Tahoma,sans-serif;color:var(--fg);-webkit-font-smoothing:antialiased;transition:bottom .2s}
|
|
7
|
+
.w.dk{${J}}
|
|
8
|
+
@media (prefers-color-scheme:dark){.w.au{${J}}}
|
|
9
|
+
.w.s{right:auto;left:16px}
|
|
10
|
+
.w.p{position:relative;inset:auto;bottom:auto;right:auto;left:auto;width:100%}
|
|
11
|
+
.c{position:relative;background:var(--bg);border-radius:16px;padding:16px;box-shadow:0 0 0 1px var(--edge),0 12px 32px -8px rgba(24,24,27,.22),0 2px 6px rgba(24,24,27,.06);
|
|
12
|
+
animation:in .32s cubic-bezier(.2,.9,.25,1) both;transform-origin:bottom}
|
|
13
|
+
.c.o{animation:out .18s ease-in both}
|
|
14
|
+
.c.q{animation:none}
|
|
15
|
+
@keyframes in{from{opacity:0;transform:translateY(10px) scale(.98)}}
|
|
16
|
+
@keyframes out{to{opacity:0;transform:translateY(6px) scale(.98)}}
|
|
17
|
+
.t{display:block;width:100%;font-family:inherit;font-weight:600;font-size:15px;line-height:1.35;padding:0;padding-inline-end:28px;color:var(--fg);overflow-wrap:anywhere;background:none;border:0;resize:none;min-height:0;max-height:none;box-shadow:none}
|
|
18
|
+
.x{position:absolute;top:10px;inset-inline-end:10px;width:28px;height:28px;border:0;border-radius:8px;background:transparent;color:var(--x);cursor:pointer;display:grid;place-items:center;transition:background .15s,color .15s}
|
|
19
|
+
.x:hover{background:var(--opt);color:var(--fg)}
|
|
20
|
+
button,input{font:inherit;color:inherit;-webkit-tap-highlight-color:transparent}
|
|
21
|
+
button:focus-visible,textarea:focus-visible{outline:2px solid var(--a);outline-offset:2px}
|
|
22
|
+
.g{display:flex;flex-direction:column;gap:6px;margin-top:12px}
|
|
23
|
+
.o1{position:relative;display:flex;align-items:center;gap:10px;min-height:40px;width:100%;padding:8px 12px;border:0;border-radius:10px;background:var(--opt);text-align:start;cursor:pointer;
|
|
24
|
+
transition:background .15s,box-shadow .15s,transform .12s}
|
|
25
|
+
.o1:hover{background:var(--opt-h)}
|
|
26
|
+
.o1:active{transform:scale(.985)}
|
|
27
|
+
.o1[aria-pressed=true]{background:var(--bg);box-shadow:inset 0 0 0 1.5px var(--a)}
|
|
28
|
+
.d{flex:none;width:16px;height:16px;border-radius:50%;box-shadow:inset 0 0 0 1.5px var(--line);display:grid;place-items:center;transition:box-shadow .15s,background .15s}
|
|
29
|
+
.o1[aria-pressed=true] .d{background:var(--a);box-shadow:none}
|
|
30
|
+
.d svg{width:10px;height:10px;color:var(--on);transform:scale(0);transition:transform .2s cubic-bezier(.3,1.6,.5,1)}
|
|
31
|
+
.o1[aria-pressed=true] .d svg{transform:scale(1)}
|
|
32
|
+
.th{display:flex;gap:8px;margin-top:12px}
|
|
33
|
+
.th .o1{justify-content:center;flex:1}
|
|
34
|
+
.th svg{width:20px;height:20px}
|
|
35
|
+
.n{display:grid;grid-template-columns:repeat(11,1fr);gap:4px;margin-top:12px;direction:ltr}
|
|
36
|
+
.n .o1{min-height:36px;padding:0;justify-content:center;font-variant-numeric:tabular-nums;font-size:13px}
|
|
37
|
+
.n .o1[aria-pressed=true]{background:var(--a);color:var(--on);box-shadow:none}
|
|
38
|
+
.nl{display:flex;justify-content:space-between;margin-top:6px;font-size:12px;color:var(--mut)}
|
|
39
|
+
.f{display:grid;grid-template-rows:0fr;transition:grid-template-rows .28s cubic-bezier(.2,.9,.25,1)}
|
|
40
|
+
.f.on{grid-template-rows:1fr}
|
|
41
|
+
.f>div{overflow:hidden;min-height:0}
|
|
42
|
+
.fi{padding-top:12px}
|
|
43
|
+
textarea{display:block;width:100%;min-height:76px;max-height:180px;resize:vertical;padding:10px 12px;border:0;border-radius:10px;background:var(--opt);font:inherit;color:var(--fg);
|
|
44
|
+
box-shadow:inset 0 0 0 1px transparent;transition:box-shadow .15s,background .15s}
|
|
45
|
+
textarea:focus{background:var(--bg);box-shadow:inset 0 0 0 1.5px var(--a);outline:0}
|
|
46
|
+
textarea::placeholder,input::placeholder{color:var(--x)}
|
|
47
|
+
.r{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:10px}
|
|
48
|
+
.e{font-size:12px;color:#d1453b}
|
|
49
|
+
.b{margin-inline-start:auto;height:34px;padding:0 14px;border:0;border-radius:10px;background:var(--a);color:var(--on);font-weight:600;cursor:pointer;display:inline-flex;align-items:center;gap:8px;transition:opacity .15s,transform .12s}
|
|
50
|
+
.b:active{transform:scale(.97)}
|
|
51
|
+
.b[disabled]{opacity:.45;cursor:default}
|
|
52
|
+
.b[aria-busy=true]{opacity:.7}
|
|
53
|
+
.sp{width:14px;height:14px;border-radius:50%;border:2px solid currentColor;border-inline-end-color:transparent;animation:sp .7s linear infinite}
|
|
54
|
+
@keyframes sp{to{transform:rotate(1turn)}}
|
|
55
|
+
.k{display:flex;align-items:center;gap:12px;padding:6px 0;animation:in .3s cubic-bezier(.2,.9,.25,1) both}
|
|
56
|
+
.k svg{flex:none;width:28px;height:28px;color:var(--a)}
|
|
57
|
+
.k path{stroke-dasharray:24;stroke-dashoffset:24;animation:ck .4s .1s ease-out forwards}
|
|
58
|
+
@keyframes ck{to{stroke-dashoffset:0}}
|
|
59
|
+
.k strong{color:var(--fg);font-size:15px;font-weight:600}
|
|
60
|
+
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
61
|
+
@media (max-width:480px){.w:not(.p){bottom:max(12px,env(safe-area-inset-bottom));left:12px;right:12px;width:auto;max-width:none}
|
|
62
|
+
.o1{min-height:44px}.n .o1{min-height:40px}}
|
|
63
|
+
@media (prefers-reduced-motion:reduce){*,.c,.k{animation-duration:.01ms!important;transition-duration:.01ms!important}}
|
|
64
|
+
`,X="http://www.w3.org/2000/svg",K={x:"M4 4l8 8M12 4l-8 8",check:"M3.5 8.5l3 3 6-7",plus:"M8 3.5v9M3.5 8h9",up:"M7 10v10H4V10h3zm0 0l4-7c1.3 0 2.2 1.1 2 2.4L12.4 9H18a2 2 0 0 1 2 2.3l-1.2 6.9A2 2 0 0 1 16.8 20H7",down:"M17 14V4h3v10h-3zm0 0l-4 7c-1.3 0-2.2-1.1-2-2.4l.6-3.6H6a2 2 0 0 1-2-2.3l1.2-6.9A2 2 0 0 1 7.2 4H17"},q={};function R(s,e=16,l=1.6){let r=document.createElementNS(X,"svg");r.setAttribute("viewBox",`0 0 ${e} ${e}`),r.setAttribute("aria-hidden","true"),r.setAttribute("fill","none");let a=document.createElementNS(X,"path");return a.setAttribute("d",s),a.setAttribute("stroke","currentColor"),a.setAttribute("stroke-width",String(l)),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),r.append(a),r}function p(s,e,l){let r=document.createElement(s);if(e)r.className=e;if(l)r.textContent=l;return r}var V=null;function le(s){try{if(V??=new CSSStyleSheet,!V.cssRules.length)V.replaceSync(Q+(q.css??""));s.adoptedStyleSheets=[V]}catch{s.append(p("style",void 0,Q+(q.css??"")))}}var ne=(s)=>{let e=Number.parseInt(s.slice(1),16),[l,r,a]=[e>>16&255,e>>8&255,e&255].map((d)=>{let h=d/255;return h<=0.03928?h/12.92:((h+0.055)/1.055)**2.4});return 0.2126*l+0.7152*r+0.0722*a},de=(s)=>ne(s)>0.4?"#18181b":"#fff";function ce(s,e){let l=/^#[0-9a-f]{6}$/i.test(e.accent)?e.accent:"#1f1f1f";if((e.theme==="dark"||e.theme==="auto"&&typeof matchMedia==="function"&&matchMedia("(prefers-color-scheme: dark)").matches)&&ne(l)<0.05)l="#fafafa";if(s.style.setProperty("--a",l),s.style.setProperty("--on",de(l)),e.theme==="dark")s.classList.add("dk");if(e.theme==="auto")s.classList.add("au")}function pe(s,e,l,r){le(s);let a=Z[e.lang]??Z.en,d=r.edit,h=p("div",`w${l.position==="start"?" s":""}${r.preview||r.inline||d?" p":""}${d?" ed":""}`);h.dir=e.lang==="ar"?"rtl":"ltr",h.lang=e.lang,ce(h,l);let u=p("div",r.quiet||d?"c q":"c"),v=`datacub-fb-${Math.random().toString(36).slice(2,8)}`;u.setAttribute("role",r.preview||r.inline||d?"group":"dialog"),u.setAttribute("aria-labelledby",v);let C=p("p","sr");C.setAttribute("aria-live","polite");let b=p("button","x");if(b.type="button",b.setAttribute("aria-label",a.close),b.append(R(K.x)),d)b.tabIndex=-1,b.setAttribute("aria-hidden","true");let S;if(d)S=q.title(e,d,u);else S=p("p","t",e.type==="general"?a.general:e.title);S.id=v,u.append(b,S),h.append(u,C),s.append(h);let y=null,k=!1,A=!1,j=e.type==="general"?a.tell:e.followup,I=(i)=>!!e.followup&&(!e.followupOn||i!==null&&e.followupOn.includes(i)),L=e.type==="text"||e.type==="general",T=[],N=null,P=(i)=>{if(A)return;if(A=!0,N)visualViewport?.removeEventListener("resize",N);u.classList.add("o"),setTimeout(()=>h.remove(),200),r.done?.(i)},M=p("div",`f${L||d&&e.followup!=null?" on":""}`),D=p("div"),z=p("div","fi"),g=p("textarea");g.maxLength=1000,g.placeholder=e.type==="text"?a.type:j??a.type,g.setAttribute("aria-label",e.type==="text"?e.title:j??a.type);let O=p("div","r"),H=p("span","e");H.setAttribute("role","status");let t=p("button","b",a.send);if(t.type="button",O.append(H,t),d&&e.followup!=null&&e.type!=="text")z.append(q.followup(e,d)),g.placeholder=a.type;if(z.append(g,O),D.append(z),M.append(D),!L&&!j)M.hidden=!0;if(d)g.disabled=!0,t.disabled=!0,t.tabIndex=-1;let n=()=>{if(d)return;t.disabled=L?!g.value.trim():!y};g.addEventListener("input",n);let o=async()=>{if(k||t.disabled||d)return;k=!0,t.setAttribute("aria-busy","true"),t.textContent="",t.append(p("span","sp"),document.createTextNode(a.sending)),H.textContent="";try{await r.send(y,(I(y)||L)&&g.value.trim()?g.value.trim():null)}catch{k=!1,t.removeAttribute("aria-busy"),t.textContent=a.send,H.textContent=a.failed;return}let i=p("div","k");i.setAttribute("role","status"),i.append(R("M7 16.5l5.5 5.5L25 9.5",32,2.4),p("strong",void 0,a.thanks));let f=u.offsetHeight;if(u.replaceChildren(i),!matchMedia("(prefers-reduced-motion: reduce)").matches)u.animate?.([{height:`${f}px`},{height:`${u.offsetHeight}px`}],{duration:280,easing:"cubic-bezier(.2,.9,.25,1)"});if(!r.preview&&!r.inline)setTimeout(()=>P(!0),2400)};t.addEventListener("click",o),g.addEventListener("keydown",(i)=>{if(i.key==="Enter"&&(i.metaKey||i.ctrlKey))o()});let c=(i)=>{y=i;for(let x of T)x.setAttribute("aria-pressed",String(x.dataset.id===i));if(n(),!I(i))return void o();let f=!M.classList.contains("on");if(M.classList.add("on"),f&&!r.preview)setTimeout(()=>g.focus({preventScroll:!0}),120)},m=(i,f,x="o1",E)=>{let w=p("button",x);if(w.type="button",w.dataset.id=i,w.setAttribute("aria-pressed","false"),E)w.append(E),w.setAttribute("aria-label",f);else{let F=p("span","d");F.append(R(K.check,16,2.4)),w.append(F,p("span",void 0,f))}if(d)w.tabIndex=-1;else w.addEventListener("click",()=>!k&&c(i));return T.push(w),w};if(e.type==="choice"&&d)u.append(q.choices(e,d));else if(e.type==="choice"){let i=p("div","g");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v);for(let f of e.options??[])i.append(m(f.id,f.label));u.append(i)}else if(e.type==="thumbs"){let i=p("div","th");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v),i.append(m("up",a.yes,"o1",R(K.up,24)),m("down",a.no,"o1",R(K.down,24))),u.append(i)}else if(e.type==="nps"){let i=p("div","n");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v);for(let x=0;x<=10;x++)i.append(m(String(x),String(x),"o1",p("span",void 0,String(x))));let f=p("div","nl");f.append(p("span",void 0,a.low),p("span",void 0,a.high)),u.append(i,f)}u.append(M),n();let _=()=>{if(!y||k||L||d)return;k=!0,r.send(y,I(y)&&g.value.trim()?g.value.trim():null).catch(()=>{})};if(b.addEventListener("click",()=>{if(d)return;_(),P(!!y||k)}),addEventListener("pagehide",_),h.addEventListener("keydown",(i)=>{if(i.key==="Escape"&&!d)i.stopPropagation(),b.click()}),!r.preview&&!r.inline&&!d&&typeof visualViewport<"u"&&visualViewport){let i=visualViewport;N=()=>{let f=innerHeight-i.height-i.offsetTop;h.style.bottom=innerWidth<=480&&f>40?`${f+12}px`:""},i.addEventListener("resize",N)}if(!r.preview&&!d)C.textContent=e.type==="general"?a.general:e.title;if(r.focus)setTimeout(()=>(L?g:T[0])?.focus(),50);if(d?.focus)q.focus(d,u);return{close:()=>P(k)}}var ee=60000,te=!1;function ue(){let s=document.activeElement;return document.visibilityState!=="visible"||!!s?.closest?.("input,textarea,select,[contenteditable]:not([contenteditable=false])")||!!document.querySelector("dialog[open],[aria-modal=true]")}function ie(s){if(te||typeof window>"u"||!s?._fb)return;te=!0;let e=s._fb,l=[],r={accent:"#1f1f1f",position:"end"},a="",d=0,h=0,u=null,v=!1,C=!1,b=new Set,S=()=>{let[,t,n,o,c,m,_,i]=e();return t&&c?{key:n,base:o.replace(/batch$/,"feedback"),anon:c,user:m??null,sid:_||null,emit:i}:null},y=async(t,n)=>{let o=await fetch(t,{method:"POST",body:JSON.stringify(n),credentials:"omit",keepalive:!0});if(!o.ok)throw Error(String(o.status));return o.json()},k=()=>{let t=document.createElement("div");return t.setAttribute("data-datacub-feedback-widget",""),document.body.append(t),t};async function A(){let t=S();if(!t){j();return}let n=`${t.anon}|${t.user??""}`;if(n===a||Date.now()<h)return;a=n;try{let o=await y(t.base,{api_key:t.key,anon_id:t.anon,user_id:t.user});l=o.questions??[];let c=o.settings;r={accent:c.accent,position:c.position,theme:c.theme??"light"}}catch(o){a="",h=/^4/.test(o?.message)?Number.POSITIVE_INFINITY:Date.now()+Math.min(1000*2**++d,300000);return}d=0,D()}function j(){C=!0,u?.close(),C=!1;for(let t of b)clearTimeout(t);b.clear()}function I(){let t=S();if(!t||u)return;let n=document.activeElement,o=/^ar\b/i.test(document.documentElement.lang)?"ar":"en";L({lang:o,type:"general",title:""},null,t,n)}function L(t,n,o,c,m){let _=k();if(m)m.append(_);let i=_.attachShadow({mode:"open"}),f=crypto.randomUUID?.()??"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(E)=>(+E^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+E/4).toString(16)),x=n?{$question_id:n.id,$version:n.version}:{};u=pe(i,t,r,{focus:!n,inline:!!m,send:async(E,w)=>{let F={api_key:o.key,id:f,question:n?.id??null,version:n?.version??null,anon_id:o.anon,user_id:o.user,session_id:o.sid,choice:E,text:w,path:location.pathname.split("/").map(G).join("/")};for(let U=0;;U++)try{await y(`${o.base}/answer`,F);break}catch(Y){if(U>=2||/^4/.test(Y.message))throw Y;await new Promise((re)=>setTimeout(re,800*2**U))}o.emit("$feedback_answered",{...x,$response_id:f,$choice:E},{},!0)},done:(E)=>{if(u=null,_.remove(),c?.focus?.(),n&&!E&&!C)y(`${o.base}/seen`,{api_key:o.key,anon_id:o.anon,question:n.id,kind:"dismissed"}).catch(()=>{}),o.emit("$feedback_dismissed",x,{},!0)}})}async function T(t,n,o){let c=S();if(!c||u||v)return;if(!o&&t.q.delivery?.waitForIdle!==!1&&ue()){if(Date.now()<n)N(()=>T(t,n,o),2000);return}try{if(!(await y(`${c.base}/seen`,{api_key:c.key,anon_id:c.anon,question:t.id,kind:"shown",user_id:c.user})).ok||u||v)return}catch{return}v=!0,l=l.filter((m)=>m.id!==t.id),c.emit("$feedback_shown",{$question_id:t.id,$version:t.version},{},!0),L(t.q,t,c,null,o)}function N(t,n){let o=setTimeout(()=>{b.delete(o),t()},n);b.add(o)}let P=(t)=>N(()=>T(t,Date.now()+ee),(t.q.trigger.delay??0)*1000);function M(t,n){return n.endsWith("*")?t.startsWith(n.slice(0,-1)):t===n||t===`${n}/`}function D(){let t=location.pathname;for(let n of l)if(n.q.trigger.kind==="page"&&M(t,n.q.trigger.path??""))P(n);for(let n of document.querySelectorAll("[data-datacub-ask]")){let o=l.find((c)=>c.id===n.getAttribute("data-datacub-ask")&&c.q.trigger.kind==="manual");if(o&&!n.querySelector("[data-datacub-feedback-widget]"))T(o,Date.now(),n)}}let z=(t,n)=>{let o=s[t];s[t]=(...c)=>{o(...c);try{n(...c)}catch{}}};z("track",(t)=>{for(let n of l)if(n.q.trigger.kind==="event"&&n.q.trigger.event===String(t).trim())P(n)}),z("identify",()=>setTimeout(A,0)),z("reset",()=>setTimeout(A,0));let g=s.consent.grant;s.consent.grant=(...t)=>{g(...t),setTimeout(A,0)},s.ask=(t,n)=>{let o=l.find((m)=>m.id===t&&m.q.trigger.kind==="manual"),c=null;try{c=typeof n?.into==="string"?document.querySelector(n.into):n?.into??null}catch{}if(o)T(o,Date.now()+ee,c instanceof Element?c:null)},s.feedback=I,document.addEventListener("click",(t)=>{if(t.target?.closest?.("[data-datacub-feedback]"))I()});let O=location.pathname,H=()=>setTimeout(()=>{if(location.pathname===O)return;O=location.pathname,v=!1,D()},150);for(let t of["pushState","replaceState"]){let n=history[t];history[t]=function(...o){n.apply(this,o),H()}}addEventListener("popstate",H),setInterval(()=>{if(S())A();else if(a)a="",j()},1000),A()}var oe=(s=0)=>{let e=window.datacub;if(e?._fb)ie(e);else if(s<100)setTimeout(()=>oe(s+1),100)};oe();})();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var B={n:0},W=(s)=>s.replace(/[\u0660-\u0669\u06f0-\u06f9\uff10-\uff19]/g,(t)=>String(t.charCodeAt(0)&15));var oe=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|bearer\s+\S{16,}|AKIA[0-9A-Z]{16}|xox[abprs]-[\w-]+|PRIVATE KEY|[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}|eyJ[\w-]+\.[\w-]+\.[\w-]*|\d(?:[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]*\d){8,}|[\w+/=]{32,}/gi;function re(s){let t="",l=0;for(let r of W(s).matchAll(oe)){if(/^[0-9a-f]{8}-/i.test(r[0])&&r[0].length===36)continue;t+=`${s.slice(l,r.index)}[redacted]`,l=r.index+r[0].length,B.n++}return t+s.slice(l)}function G(s){let t=s;try{t=decodeURIComponent(s)}catch{}t=W(t);let l=B.n;if(re(t)!==t)return B.n=l+1,":redacted";if(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(t))return":uuid";if(/^[0-9a-f]{16,}$/i.test(t))return t.length===24?":id":":hash";if(/^[\w-]{20,}$/.test(t)&&/\d/.test(t)&&/[a-z]/.test(t)&&/[A-Z]/.test(t))return":token";let r=t.replace(/\D/g,"").length;return r&&(r===t.length||r>3&&r*2>=t.length)?":id":s}var Z={en:{close:"Close",send:"Send",sending:"Sending",thanks:"Thanks for sharing!",failed:"Could not send. Try again.",yes:"Yes",no:"No",low:"Not likely",high:"Very likely",type:"Type your answer",general:"What\u2019s on your mind?",tell:"Tell us anything"},ar:{close:"\u0625\u063a\u0644\u0627\u0642",send:"\u0625\u0631\u0633\u0627\u0644",sending:"\u062c\u0627\u0631\u064d \u0627\u0644\u0625\u0631\u0633\u0627\u0644",thanks:"\u0634\u0643\u0631\u064b\u0627 \u0639\u0644\u0649 \u0645\u0634\u0627\u0631\u0643\u062a\u0643!",failed:"\u062a\u0639\u0630\u0651\u0631 \u0627\u0644\u0625\u0631\u0633\u0627\u0644\u060c \u062d\u0627\u0648\u0644 \u0645\u0631\u0629 \u062b\u0627\u0646\u064a\u0629.",yes:"\u0646\u0639\u0645",no:"\u0644\u0627",low:"\u063a\u064a\u0631 \u0645\u062d\u062a\u0645\u0644",high:"\u0645\u062d\u062a\u0645\u0644 \u062c\u062f\u064b\u0627",type:"\u0627\u0643\u062a\u0628 \u0625\u062c\u0627\u0628\u062a\u0643",general:"\u0645\u0627 \u0627\u0644\u0630\u064a \u064a\u062f\u0648\u0631 \u0641\u064a \u0628\u0627\u0644\u0643\u061f",tell:"\u0627\u0643\u062a\u0628 \u0645\u0627 \u062a\u0631\u064a\u062f"}},J="--bg:#1c1c1f;--fg:#fafafa;--mut:#a1a1aa;--opt:#2a2a2e;--opt-h:#333338;--edge:rgba(255,255,255,.08);--x:#8b8b93;--line:#55555c",Q=`
|
|
2
|
+
:host{all:initial}
|
|
3
|
+
*{box-sizing:border-box;margin:0}
|
|
4
|
+
.w{--a:#1f1f1f;--on:#fff;--bg:#fff;--fg:#18181b;--mut:#71717a;--opt:#f4f4f5;--opt-h:#ebebee;--edge:rgba(24,24,27,.07);--x:#a1a1aa;--line:#d4d4d8;
|
|
5
|
+
position:fixed;z-index:2147483000;bottom:16px;right:16px;width:360px;max-width:calc(100vw - 24px);
|
|
6
|
+
font:14px/1.45 system-ui,-apple-system,"Segoe UI","SF Arabic","Noto Sans Arabic",Tahoma,sans-serif;color:var(--fg);-webkit-font-smoothing:antialiased;transition:bottom .2s}
|
|
7
|
+
.w.dk{${J}}
|
|
8
|
+
@media (prefers-color-scheme:dark){.w.au{${J}}}
|
|
9
|
+
.w.s{right:auto;left:16px}
|
|
10
|
+
.w.p{position:relative;inset:auto;bottom:auto;right:auto;left:auto;width:100%}
|
|
11
|
+
.c{position:relative;background:var(--bg);border-radius:16px;padding:16px;box-shadow:0 0 0 1px var(--edge),0 12px 32px -8px rgba(24,24,27,.22),0 2px 6px rgba(24,24,27,.06);
|
|
12
|
+
animation:in .32s cubic-bezier(.2,.9,.25,1) both;transform-origin:bottom}
|
|
13
|
+
.c.o{animation:out .18s ease-in both}
|
|
14
|
+
.c.q{animation:none}
|
|
15
|
+
@keyframes in{from{opacity:0;transform:translateY(10px) scale(.98)}}
|
|
16
|
+
@keyframes out{to{opacity:0;transform:translateY(6px) scale(.98)}}
|
|
17
|
+
.t{display:block;width:100%;font-family:inherit;font-weight:600;font-size:15px;line-height:1.35;padding:0;padding-inline-end:28px;color:var(--fg);overflow-wrap:anywhere;background:none;border:0;resize:none;min-height:0;max-height:none;box-shadow:none}
|
|
18
|
+
.x{position:absolute;top:10px;inset-inline-end:10px;width:28px;height:28px;border:0;border-radius:8px;background:transparent;color:var(--x);cursor:pointer;display:grid;place-items:center;transition:background .15s,color .15s}
|
|
19
|
+
.x:hover{background:var(--opt);color:var(--fg)}
|
|
20
|
+
button,input{font:inherit;color:inherit;-webkit-tap-highlight-color:transparent}
|
|
21
|
+
button:focus-visible,textarea:focus-visible{outline:2px solid var(--a);outline-offset:2px}
|
|
22
|
+
.g{display:flex;flex-direction:column;gap:6px;margin-top:12px}
|
|
23
|
+
.o1{position:relative;display:flex;align-items:center;gap:10px;min-height:40px;width:100%;padding:8px 12px;border:0;border-radius:10px;background:var(--opt);text-align:start;cursor:pointer;
|
|
24
|
+
transition:background .15s,box-shadow .15s,transform .12s}
|
|
25
|
+
.o1:hover{background:var(--opt-h)}
|
|
26
|
+
.o1:active{transform:scale(.985)}
|
|
27
|
+
.o1[aria-pressed=true]{background:var(--bg);box-shadow:inset 0 0 0 1.5px var(--a)}
|
|
28
|
+
.d{flex:none;width:16px;height:16px;border-radius:50%;box-shadow:inset 0 0 0 1.5px var(--line);display:grid;place-items:center;transition:box-shadow .15s,background .15s}
|
|
29
|
+
.o1[aria-pressed=true] .d{background:var(--a);box-shadow:none}
|
|
30
|
+
.d svg{width:10px;height:10px;color:var(--on);transform:scale(0);transition:transform .2s cubic-bezier(.3,1.6,.5,1)}
|
|
31
|
+
.o1[aria-pressed=true] .d svg{transform:scale(1)}
|
|
32
|
+
.th{display:flex;gap:8px;margin-top:12px}
|
|
33
|
+
.th .o1{justify-content:center;flex:1}
|
|
34
|
+
.th svg{width:20px;height:20px}
|
|
35
|
+
.n{display:grid;grid-template-columns:repeat(11,1fr);gap:4px;margin-top:12px;direction:ltr}
|
|
36
|
+
.n .o1{min-height:36px;padding:0;justify-content:center;font-variant-numeric:tabular-nums;font-size:13px}
|
|
37
|
+
.n .o1[aria-pressed=true]{background:var(--a);color:var(--on);box-shadow:none}
|
|
38
|
+
.nl{display:flex;justify-content:space-between;margin-top:6px;font-size:12px;color:var(--mut)}
|
|
39
|
+
.f{display:grid;grid-template-rows:0fr;transition:grid-template-rows .28s cubic-bezier(.2,.9,.25,1)}
|
|
40
|
+
.f.on{grid-template-rows:1fr}
|
|
41
|
+
.f>div{overflow:hidden;min-height:0}
|
|
42
|
+
.fi{padding-top:12px}
|
|
43
|
+
textarea{display:block;width:100%;min-height:76px;max-height:180px;resize:vertical;padding:10px 12px;border:0;border-radius:10px;background:var(--opt);font:inherit;color:var(--fg);
|
|
44
|
+
box-shadow:inset 0 0 0 1px transparent;transition:box-shadow .15s,background .15s}
|
|
45
|
+
textarea:focus{background:var(--bg);box-shadow:inset 0 0 0 1.5px var(--a);outline:0}
|
|
46
|
+
textarea::placeholder,input::placeholder{color:var(--x)}
|
|
47
|
+
.r{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:10px}
|
|
48
|
+
.e{font-size:12px;color:#d1453b}
|
|
49
|
+
.b{margin-inline-start:auto;height:34px;padding:0 14px;border:0;border-radius:10px;background:var(--a);color:var(--on);font-weight:600;cursor:pointer;display:inline-flex;align-items:center;gap:8px;transition:opacity .15s,transform .12s}
|
|
50
|
+
.b:active{transform:scale(.97)}
|
|
51
|
+
.b[disabled]{opacity:.45;cursor:default}
|
|
52
|
+
.b[aria-busy=true]{opacity:.7}
|
|
53
|
+
.sp{width:14px;height:14px;border-radius:50%;border:2px solid currentColor;border-inline-end-color:transparent;animation:sp .7s linear infinite}
|
|
54
|
+
@keyframes sp{to{transform:rotate(1turn)}}
|
|
55
|
+
.k{display:flex;align-items:center;gap:12px;padding:6px 0;animation:in .3s cubic-bezier(.2,.9,.25,1) both}
|
|
56
|
+
.k svg{flex:none;width:28px;height:28px;color:var(--a)}
|
|
57
|
+
.k path{stroke-dasharray:24;stroke-dashoffset:24;animation:ck .4s .1s ease-out forwards}
|
|
58
|
+
@keyframes ck{to{stroke-dashoffset:0}}
|
|
59
|
+
.k strong{color:var(--fg);font-size:15px;font-weight:600}
|
|
60
|
+
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
61
|
+
@media (max-width:480px){.w:not(.p){bottom:max(12px,env(safe-area-inset-bottom));left:12px;right:12px;width:auto;max-width:none}
|
|
62
|
+
.o1{min-height:44px}.n .o1{min-height:40px}}
|
|
63
|
+
@media (prefers-reduced-motion:reduce){*,.c,.k{animation-duration:.01ms!important;transition-duration:.01ms!important}}
|
|
64
|
+
`,X="http://www.w3.org/2000/svg",K={x:"M4 4l8 8M12 4l-8 8",check:"M3.5 8.5l3 3 6-7",plus:"M8 3.5v9M3.5 8h9",up:"M7 10v10H4V10h3zm0 0l4-7c1.3 0 2.2 1.1 2 2.4L12.4 9H18a2 2 0 0 1 2 2.3l-1.2 6.9A2 2 0 0 1 16.8 20H7",down:"M17 14V4h3v10h-3zm0 0l-4 7c-1.3 0-2.2-1.1-2-2.4l.6-3.6H6a2 2 0 0 1-2-2.3l1.2-6.9A2 2 0 0 1 7.2 4H17"},P={};function R(s,t=16,l=1.6){let r=document.createElementNS(X,"svg");r.setAttribute("viewBox",`0 0 ${t} ${t}`),r.setAttribute("aria-hidden","true"),r.setAttribute("fill","none");let a=document.createElementNS(X,"path");return a.setAttribute("d",s),a.setAttribute("stroke","currentColor"),a.setAttribute("stroke-width",String(l)),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),r.append(a),r}function p(s,t,l){let r=document.createElement(s);if(t)r.className=t;if(l)r.textContent=l;return r}var V=null;function se(s){try{if(V??=new CSSStyleSheet,!V.cssRules.length)V.replaceSync(Q+(P.css??""));s.adoptedStyleSheets=[V]}catch{s.append(p("style",void 0,Q+(P.css??"")))}}var ne=(s)=>{let t=Number.parseInt(s.slice(1),16),[l,r,a]=[t>>16&255,t>>8&255,t&255].map((d)=>{let h=d/255;return h<=0.03928?h/12.92:((h+0.055)/1.055)**2.4});return 0.2126*l+0.7152*r+0.0722*a},ae=(s)=>ne(s)>0.4?"#18181b":"#fff";function le(s,t){let l=/^#[0-9a-f]{6}$/i.test(t.accent)?t.accent:"#1f1f1f";if((t.theme==="dark"||t.theme==="auto"&&typeof matchMedia==="function"&&matchMedia("(prefers-color-scheme: dark)").matches)&&ne(l)<0.05)l="#fafafa";if(s.style.setProperty("--a",l),s.style.setProperty("--on",ae(l)),t.theme==="dark")s.classList.add("dk");if(t.theme==="auto")s.classList.add("au")}function de(s,t,l,r){se(s);let a=Z[t.lang]??Z.en,d=r.edit,h=p("div",`w${l.position==="start"?" s":""}${r.preview||r.inline||d?" p":""}${d?" ed":""}`);h.dir=t.lang==="ar"?"rtl":"ltr",h.lang=t.lang,le(h,l);let u=p("div",r.quiet||d?"c q":"c"),v=`datacub-fb-${Math.random().toString(36).slice(2,8)}`;u.setAttribute("role",r.preview||r.inline||d?"group":"dialog"),u.setAttribute("aria-labelledby",v);let C=p("p","sr");C.setAttribute("aria-live","polite");let b=p("button","x");if(b.type="button",b.setAttribute("aria-label",a.close),b.append(R(K.x)),d)b.tabIndex=-1,b.setAttribute("aria-hidden","true");let S;if(d)S=P.title(t,d,u);else S=p("p","t",t.type==="general"?a.general:t.title);S.id=v,u.append(b,S),h.append(u,C),s.append(h);let x=null,k=!1,A=!1,j=t.type==="general"?a.tell:t.followup,I=(i)=>!!t.followup&&(!t.followupOn||i!==null&&t.followupOn.includes(i)),L=t.type==="text"||t.type==="general",T=[],N=null,q=(i)=>{if(A)return;if(A=!0,N)visualViewport?.removeEventListener("resize",N);u.classList.add("o"),setTimeout(()=>h.remove(),200),r.done?.(i)},M=p("div",`f${L||d&&t.followup!=null?" on":""}`),D=p("div"),z=p("div","fi"),g=p("textarea");g.maxLength=1000,g.placeholder=t.type==="text"?a.type:j??a.type,g.setAttribute("aria-label",t.type==="text"?t.title:j??a.type);let O=p("div","r"),H=p("span","e");H.setAttribute("role","status");let e=p("button","b",a.send);if(e.type="button",O.append(H,e),d&&t.followup!=null&&t.type!=="text")z.append(P.followup(t,d)),g.placeholder=a.type;if(z.append(g,O),D.append(z),M.append(D),!L&&!j)M.hidden=!0;if(d)g.disabled=!0,e.disabled=!0,e.tabIndex=-1;let n=()=>{if(d)return;e.disabled=L?!g.value.trim():!x};g.addEventListener("input",n);let o=async()=>{if(k||e.disabled||d)return;k=!0,e.setAttribute("aria-busy","true"),e.textContent="",e.append(p("span","sp"),document.createTextNode(a.sending)),H.textContent="";try{await r.send(x,(I(x)||L)&&g.value.trim()?g.value.trim():null)}catch{k=!1,e.removeAttribute("aria-busy"),e.textContent=a.send,H.textContent=a.failed;return}let i=p("div","k");i.setAttribute("role","status"),i.append(R("M7 16.5l5.5 5.5L25 9.5",32,2.4),p("strong",void 0,a.thanks));let f=u.offsetHeight;if(u.replaceChildren(i),!matchMedia("(prefers-reduced-motion: reduce)").matches)u.animate?.([{height:`${f}px`},{height:`${u.offsetHeight}px`}],{duration:280,easing:"cubic-bezier(.2,.9,.25,1)"});if(!r.preview&&!r.inline)setTimeout(()=>q(!0),2400)};e.addEventListener("click",o),g.addEventListener("keydown",(i)=>{if(i.key==="Enter"&&(i.metaKey||i.ctrlKey))o()});let c=(i)=>{x=i;for(let y of T)y.setAttribute("aria-pressed",String(y.dataset.id===i));if(n(),!I(i))return void o();let f=!M.classList.contains("on");if(M.classList.add("on"),f&&!r.preview)setTimeout(()=>g.focus({preventScroll:!0}),120)},m=(i,f,y="o1",E)=>{let w=p("button",y);if(w.type="button",w.dataset.id=i,w.setAttribute("aria-pressed","false"),E)w.append(E),w.setAttribute("aria-label",f);else{let F=p("span","d");F.append(R(K.check,16,2.4)),w.append(F,p("span",void 0,f))}if(d)w.tabIndex=-1;else w.addEventListener("click",()=>!k&&c(i));return T.push(w),w};if(t.type==="choice"&&d)u.append(P.choices(t,d));else if(t.type==="choice"){let i=p("div","g");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v);for(let f of t.options??[])i.append(m(f.id,f.label));u.append(i)}else if(t.type==="thumbs"){let i=p("div","th");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v),i.append(m("up",a.yes,"o1",R(K.up,24)),m("down",a.no,"o1",R(K.down,24))),u.append(i)}else if(t.type==="nps"){let i=p("div","n");i.setAttribute("role","group"),i.setAttribute("aria-labelledby",v);for(let y=0;y<=10;y++)i.append(m(String(y),String(y),"o1",p("span",void 0,String(y))));let f=p("div","nl");f.append(p("span",void 0,a.low),p("span",void 0,a.high)),u.append(i,f)}u.append(M),n();let _=()=>{if(!x||k||L||d)return;k=!0,r.send(x,I(x)&&g.value.trim()?g.value.trim():null).catch(()=>{})};if(b.addEventListener("click",()=>{if(d)return;_(),q(!!x||k)}),addEventListener("pagehide",_),h.addEventListener("keydown",(i)=>{if(i.key==="Escape"&&!d)i.stopPropagation(),b.click()}),!r.preview&&!r.inline&&!d&&typeof visualViewport<"u"&&visualViewport){let i=visualViewport;N=()=>{let f=innerHeight-i.height-i.offsetTop;h.style.bottom=innerWidth<=480&&f>40?`${f+12}px`:""},i.addEventListener("resize",N)}if(!r.preview&&!d)C.textContent=t.type==="general"?a.general:t.title;if(r.focus)setTimeout(()=>(L?g:T[0])?.focus(),50);if(d?.focus)P.focus(d,u);return{close:()=>q(k)}}var ee=60000,te=!1;function ce(){let s=document.activeElement;return document.visibilityState!=="visible"||!!s?.closest?.("input,textarea,select,[contenteditable]:not([contenteditable=false])")||!!document.querySelector("dialog[open],[aria-modal=true]")}function fe(s){if(te||typeof window>"u"||!s?._fb)return;te=!0;let t=s._fb,l=[],r={accent:"#1f1f1f",position:"end"},a="",d=0,h=0,u=null,v=!1,C=!1,b=new Set,S=()=>{let[,e,n,o,c,m,_,i]=t();return e&&c?{key:n,base:o.replace(/batch$/,"feedback"),anon:c,user:m??null,sid:_||null,emit:i}:null},x=async(e,n)=>{let o=await fetch(e,{method:"POST",body:JSON.stringify(n),credentials:"omit",keepalive:!0});if(!o.ok)throw Error(String(o.status));return o.json()},k=()=>{let e=document.createElement("div");return e.setAttribute("data-datacub-feedback-widget",""),document.body.append(e),e};async function A(){let e=S();if(!e){j();return}let n=`${e.anon}|${e.user??""}`;if(n===a||Date.now()<h)return;a=n;try{let o=await x(e.base,{api_key:e.key,anon_id:e.anon,user_id:e.user});l=o.questions??[];let c=o.settings;r={accent:c.accent,position:c.position,theme:c.theme??"light"}}catch(o){a="",h=/^4/.test(o?.message)?Number.POSITIVE_INFINITY:Date.now()+Math.min(1000*2**++d,300000);return}d=0,D()}function j(){C=!0,u?.close(),C=!1;for(let e of b)clearTimeout(e);b.clear()}function I(){let e=S();if(!e||u)return;let n=document.activeElement,o=/^ar\b/i.test(document.documentElement.lang)?"ar":"en";L({lang:o,type:"general",title:""},null,e,n)}function L(e,n,o,c,m){let _=k();if(m)m.append(_);let i=_.attachShadow({mode:"open"}),f=crypto.randomUUID?.()??"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(E)=>(+E^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+E/4).toString(16)),y=n?{$question_id:n.id,$version:n.version}:{};u=de(i,e,r,{focus:!n,inline:!!m,send:async(E,w)=>{let F={api_key:o.key,id:f,question:n?.id??null,version:n?.version??null,anon_id:o.anon,user_id:o.user,session_id:o.sid,choice:E,text:w,path:location.pathname.split("/").map(G).join("/")};for(let U=0;;U++)try{await x(`${o.base}/answer`,F);break}catch(Y){if(U>=2||/^4/.test(Y.message))throw Y;await new Promise((ie)=>setTimeout(ie,800*2**U))}o.emit("$feedback_answered",{...y,$response_id:f,$choice:E},{},!0)},done:(E)=>{if(u=null,_.remove(),c?.focus?.(),n&&!E&&!C)x(`${o.base}/seen`,{api_key:o.key,anon_id:o.anon,question:n.id,kind:"dismissed"}).catch(()=>{}),o.emit("$feedback_dismissed",y,{},!0)}})}async function T(e,n,o){let c=S();if(!c||u||v)return;if(!o&&e.q.delivery?.waitForIdle!==!1&&ce()){if(Date.now()<n)N(()=>T(e,n,o),2000);return}try{if(!(await x(`${c.base}/seen`,{api_key:c.key,anon_id:c.anon,question:e.id,kind:"shown",user_id:c.user})).ok||u||v)return}catch{return}v=!0,l=l.filter((m)=>m.id!==e.id),c.emit("$feedback_shown",{$question_id:e.id,$version:e.version},{},!0),L(e.q,e,c,null,o)}function N(e,n){let o=setTimeout(()=>{b.delete(o),e()},n);b.add(o)}let q=(e)=>N(()=>T(e,Date.now()+ee),(e.q.trigger.delay??0)*1000);function M(e,n){return n.endsWith("*")?e.startsWith(n.slice(0,-1)):e===n||e===`${n}/`}function D(){let e=location.pathname;for(let n of l)if(n.q.trigger.kind==="page"&&M(e,n.q.trigger.path??""))q(n);for(let n of document.querySelectorAll("[data-datacub-ask]")){let o=l.find((c)=>c.id===n.getAttribute("data-datacub-ask")&&c.q.trigger.kind==="manual");if(o&&!n.querySelector("[data-datacub-feedback-widget]"))T(o,Date.now(),n)}}let z=(e,n)=>{let o=s[e];s[e]=(...c)=>{o(...c);try{n(...c)}catch{}}};z("track",(e)=>{for(let n of l)if(n.q.trigger.kind==="event"&&n.q.trigger.event===String(e).trim())q(n)}),z("identify",()=>setTimeout(A,0)),z("reset",()=>setTimeout(A,0));let g=s.consent.grant;s.consent.grant=(...e)=>{g(...e),setTimeout(A,0)},s.ask=(e,n)=>{let o=l.find((m)=>m.id===e&&m.q.trigger.kind==="manual"),c=null;try{c=typeof n?.into==="string"?document.querySelector(n.into):n?.into??null}catch{}if(o)T(o,Date.now()+ee,c instanceof Element?c:null)},s.feedback=I,document.addEventListener("click",(e)=>{if(e.target?.closest?.("[data-datacub-feedback]"))I()});let O=location.pathname,H=()=>setTimeout(()=>{if(location.pathname===O)return;O=location.pathname,v=!1,D()},150);for(let e of["pushState","replaceState"]){let n=history[e];history[e]=function(...o){n.apply(this,o),H()}}addEventListener("popstate",H),setInterval(()=>{if(S())A();else if(a)a="",j()},1000),A()}export{K as ICONS,p as el,R as icon,de as mount,P as parts,fe as start};
|
package/dist/flags.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{function k(t,r){let s=`${t}:${r}`,e=2166136261;for(let c=0;c<s.length;c++)e^=s.charCodeAt(c),e=Math.imul(e,16777619);return e^=e>>>16,e=Math.imul(e,2246822507),e^=e>>>13,e=Math.imul(e,3266489909),e^=e>>>16,(e>>>0)%1e4}var _=(t,r,s)=>r>=100||r>0&&k(`f1:${t}`,s)<r*100,h=(t,r)=>k(`e1:${t}`,r)<5000?"A":"B";var j=30000,R=1e4,v=2000;function A(t){let r=null,s=0,e=null,c=0,b=new Set,d=()=>{let n=t();return typeof n?._fb==="function"?n._fb():null};async function p(){for(let n=0;n<v;n+=50){let i=d();if(i?.[2])return i;await new Promise((o)=>setTimeout(o,50))}return null}async function P(){let n=await p();if(!n)return;let i=new AbortController,o=setTimeout(()=>i.abort(),v);try{let u=`${n[3].replace(/batch$/,"flags")}?api_key=${n[2]}`,f=await fetch(u,{credentials:"omit",signal:i.signal});if(!f.ok)c=Date.now();else{let a=await f.json();r={flags:a.flags&&typeof a.flags==="object"?a.flags:{},experiments:a.experiments&&typeof a.experiments==="object"?a.experiments:{}},s=Date.now()}}catch{c=Date.now()}clearTimeout(o)}async function y(){if(typeof window>"u")return null;if(!r&&Date.now()-c<R)return null;if(!r||Date.now()-s>j){if(e??=P().finally(()=>{e=null}),!r)await e}return r}let w=(n)=>n?.[1]&&typeof n[4]==="string"&&n[4]?n[4]:null;async function H(n){try{if(typeof window>"u"||!(await p())?.[4])return!1;let i=(await y())?.flags[n];if(typeof i!=="number")return!1;if(i>=100)return!0;let o=w(d());return!!o&&_(n,i,o)}catch{return!1}}async function T(n){try{if(typeof window>"u"||!w(await p()))return"A";let o=(await y())?.experiments[n],u=d(),f=w(u);if(typeof o!=="string"||!f||!u)return"A";let a=h(o,f),x=`${o}:${f}`;if(!b.has(x))u[7]("$experiment_exposure",{$experiment_id:o,$variant:a}),b.add(x);return a}catch{return"A"}}return{flag:H,experiment:T}}var l=window,C=A(()=>l.datacub),m=(t)=>{if(t&&typeof t==="object"&&!t.flag)t.flag=C.flag,t.experiment=C.experiment},g=l.datacub??[];m(g);try{Object.defineProperty(window,"datacub",{configurable:!0,enumerable:!0,get:()=>g,set(t){g=t,m(t)}})}catch{l.datacub=g;let t=0,r=setInterval(()=>{if(m(l.datacub),l.datacub?._fb||++t>300)clearInterval(r)},100)}})();
|
package/dist/flags.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import T from"@datacub/web";function y(a,e){let s=`${a}:${e}`,t=2166136261;for(let f=0;f<s.length;f++)t^=s.charCodeAt(f),t=Math.imul(t,16777619);return t^=t>>>16,t=Math.imul(t,2246822507),t^=t>>>13,t=Math.imul(t,3266489909),t^=t>>>16,(t>>>0)%1e4}var x=(a,e,s)=>e>=100||e>0&&y(`f1:${a}`,s)<e*100,b=(a,e)=>y(`e1:${a}`,e)<5000?"A":"B";var v=30000,P=1e4,h=2000;function _(a){let e=null,s=0,t=null,f=0,p=new Set,u=()=>{let n=a();return typeof n?._fb==="function"?n._fb():null};async function g(){for(let n=0;n<h;n+=50){let i=u();if(i?.[2])return i;await new Promise((r)=>setTimeout(r,50))}return null}async function k(){let n=await g();if(!n)return;let i=new AbortController,r=setTimeout(()=>i.abort(),h);try{let l=`${n[3].replace(/batch$/,"flags")}?api_key=${n[2]}`,c=await fetch(l,{credentials:"omit",signal:i.signal});if(!c.ok)f=Date.now();else{let o=await c.json();e={flags:o.flags&&typeof o.flags==="object"?o.flags:{},experiments:o.experiments&&typeof o.experiments==="object"?o.experiments:{}},s=Date.now()}}catch{f=Date.now()}clearTimeout(r)}async function d(){if(typeof window>"u")return null;if(!e&&Date.now()-f<P)return null;if(!e||Date.now()-s>v){if(t??=k().finally(()=>{t=null}),!e)await t}return e}let m=(n)=>n?.[1]&&typeof n[4]==="string"&&n[4]?n[4]:null;async function A(n){try{if(typeof window>"u"||!(await g())?.[4])return!1;let i=(await d())?.flags[n];if(typeof i!=="number")return!1;if(i>=100)return!0;let r=m(u());return!!r&&x(n,i,r)}catch{return!1}}async function C(n){try{if(typeof window>"u"||!m(await g()))return"A";let r=(await d())?.experiments[n],l=u(),c=m(l);if(typeof r!=="string"||!c||!l)return"A";let o=b(r,c),w=`${r}:${c}`;if(!p.has(w))l[7]("$experiment_exposure",{$experiment_id:r,$variant:o}),p.add(w);return o}catch{return"A"}}return{flag:A,experiment:C}}var{flag:E,experiment:M}=_(()=>T);export{M as experiment,E as flag};
|
package/dist/insights.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{var G=window,d=G.__datacub,k=()=>performance.now(),a=Math.round;if(d&&!d.l)try{let _=PerformanceObserver.supportedEntryTypes||[],L=[],u=(t,e,s)=>{if(_.includes(t)){let o=new PerformanceObserver((n)=>n.getEntries().forEach(e));return o.observe({type:t,buffered:!0,...s}),L.push([o,e]),1}},T=1,M=0,m=0,l=0,S=0,O=0,p=0,H=0,f=[],g=0,b=0,h=0,y=0,F=document.currentScript?.src||"",B=F.slice(0,F.lastIndexOf("/v1/")+4)||" ";u("largest-contentful-paint",(t)=>{M=t.startTime});let j=u("layout-shift",(t)=>{if(t.hadRecentInput)return;let e=t.startTime;if(l&&e-O<1000&&e-S<5000)l+=t.value;else l=t.value,S=e;if(O=e,l>m)m=l}),N=(t)=>{let e=t.interactionId;if(!e)return;if(e>H)H=e,p++;let s=f.find((o)=>o[0]===e);if(s){if(t.duration>s[1])s[1]=t.duration}else f.push([e,t.duration,t.target?.localName||""]);f=f.sort((o,n)=>n[1]-o[1]).slice(0,10)};u("event",N,{durationThreshold:40}),u("first-input",N);let q=(t)=>{g++,b+=t.duration},z=u("long-animation-frame",q)||u("longtask",q);u("resource",(t)=>{if(!t.name.startsWith(B))h++,y+=t.transferSize||0});let A=new WeakMap,E=new Set,v=new WeakMap,x=".datacub-no-capture,[data-datacub-no-capture]",C=(t,e)=>{if(v.get(t)==="submit"||v.get(t)===e||t.closest(x))return;v.set(t,e),E.delete(t);let s=k(),o=[],n=new Map;for(let r of t.querySelectorAll("input,select,textarea")){let c=r.type;if(o.length>49||/^(hidden|submit|button|reset|image)$/.test(c)||r.closest(x))continue;let i=A.get(r)||[0,0,"",0,0,0],I=(r.getAttribute("autocomplete")||"").toLowerCase(),P=r.getAttribute("name")||r.id||"";if(/^(?:radio|checkbox)$/.test(c)){let R=r.getAttribute("name")||"",V=c+R,w=n.get(V);if(w){if(c==="radio")w[4]|=i[4];w[7]||=i[2];continue}let W=[c,R.slice(0,64),"",+r.required,c==="radio"?i[4]:0,0,0,i[2]];n.set(V,W),o.push(W);continue}o.push([c,c==="password"||/cc-|one-time-code/.test(I)||/@|\d{5}|[\da-f]{16}/i.test(P)?"":P.slice(0,64),I.trim().split(/\s+/).pop()?.slice(0,32),+r.required,i[4],a(i[0]+(i[3]&&s-i[3])),i[1],i[2]])}d.e("$form_fields",{...d.f(t),$ff:o,$fo:e})},D=(t)=>{try{let{target:e,type:s}=t;if(s==="submit")return C(e,"submit");let o=e.form;if(!o)return;let n=A.get(e)||[0,0,"",0,0,0];if(A.set(e,n),s==="focusin")n[3]=k(),n[4]=1,n[5]=0;else if(s==="focusout"){if(n[3])n[0]+=k()-n[3];n[3]=0}else if(s==="input"){if(!n[5])n[1]++;n[4]=n[5]=1,E.add(o)}else for(let r in e.validity)if(e.validity[r]){n[2]=r;break}}catch{}};for(let t of["focusin","focusout","input","invalid","submit"])document.addEventListener(t,D,{capture:!0,passive:!0});d.l=()=>{let t={};try{for(let[e,s]of L)e.takeRecords().forEach(s);if(T){T=0;let e=performance.getEntriesByType("navigation")[0],s=(o,n)=>{if(n>0)t[o]=a(n)};if(s("$lcp",M),s("$fcp",performance.getEntriesByName("first-contentful-paint")[0]?.startTime||0),e)s("$ttfb",e.responseStart),t.$dns=a(e.domainLookupEnd-e.domainLookupStart),t.$tcp=a(e.connectEnd-e.connectStart),s("$dcl",e.domContentLoadedEventEnd),s("$load",e.loadEventEnd)}if(p){let e=f[Math.min(p/50,9)|0];if(t.$inp=a(e[1]),e[2])t.$ie=e[2]}if(j)t.$cls=a(m*1e4)/1e4;if(z)t.$lt=g,t.$ltm=a(b);t.$rc=h,t.$rkb=a(y/1024),m=l=p=g=b=h=y=0,f=[];for(let e of E)C(e,"abandon")}catch{}return t},navigator.userAgentData?.getHighEntropyValues(["model","platformVersion"]).then((t)=>{d.h=[t.model||"",t.platformVersion||""]},()=>{})}catch{}})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datacub/web",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"description": "datacub product analytics for websites. One line to install, private by default.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"analytics",
|
|
7
|
+
"product-analytics",
|
|
8
|
+
"web-analytics",
|
|
9
|
+
"datacub",
|
|
10
|
+
"arabic"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://docs.datacub.to",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/datacub/sdk.git",
|
|
16
|
+
"directory": "packages/web"
|
|
17
|
+
},
|
|
18
|
+
"bugs": "https://github.com/datacub/sdk/issues",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./types/index.d.ts",
|
|
25
|
+
"default": "./dist/datacub.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./flags": {
|
|
28
|
+
"types": "./types/flags-npm.d.ts",
|
|
29
|
+
"default": "./dist/flags.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./feedback": {
|
|
32
|
+
"types": "./types/feedback.d.ts",
|
|
33
|
+
"default": "./dist/feedback.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist/*.js",
|
|
39
|
+
"dist/*.mjs",
|
|
40
|
+
"types",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE",
|
|
43
|
+
"CHANGELOG.md"
|
|
44
|
+
],
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public",
|
|
47
|
+
"provenance": true
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "bun scripts/build.ts",
|
|
51
|
+
"typecheck": "tsc -p .",
|
|
52
|
+
"test": "bun test",
|
|
53
|
+
"test:browser": "playwright test",
|
|
54
|
+
"pack:check": "bun scripts/pack-check.ts"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@playwright/test": "1.65.1",
|
|
58
|
+
"@tanstack/react-router": "1.170.46",
|
|
59
|
+
"@types/react": "19.3.0",
|
|
60
|
+
"@types/react-dom": "19.3.0",
|
|
61
|
+
"react": "19.3.1",
|
|
62
|
+
"react-dom": "19.3.1",
|
|
63
|
+
"vue": "3.5.45",
|
|
64
|
+
"vue-router": "5.5.1"
|
|
65
|
+
},
|
|
66
|
+
"author": "datacub (https://datacub.to)"
|
|
67
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function bucket(seed: string, id: string): number;
|
|
2
|
+
/** Is a flag on for this visitor? rollout is a whole percentage. Raising it only adds visitors. */
|
|
3
|
+
export declare const flagOn: (key: string, rollout: number, id: string) => boolean;
|
|
4
|
+
/** An experiment's version for this visitor: 50/50, seeded by the experiment's id, so a new
|
|
5
|
+
* experiment under an old key starts a fresh split. */
|
|
6
|
+
export declare const variantOf: (experimentId: string, id: string) => 'A' | 'B';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// datacub web SDK 0.4.2, for the script tag. Save as datacub.d.ts in your project: `datacub` is then typed.
|
|
2
|
+
export declare const VERSION = "0.4.2";
|
|
3
|
+
export type Property = string | number | boolean | null | Date | Property[] | {
|
|
4
|
+
[key: string]: Property;
|
|
5
|
+
};
|
|
6
|
+
export type Properties = Record<string, Property>;
|
|
7
|
+
export interface InitOptions {
|
|
8
|
+
/** Ingestion origin or first-party proxy path. Default https://in.datacub.to */
|
|
9
|
+
apiHost?: string;
|
|
10
|
+
/** Treat `#/route` fragments as routes. Default false. */
|
|
11
|
+
hashRouting?: boolean;
|
|
12
|
+
/** Clicks and form submits. Default true. Pageviews and page leaves are always on. */
|
|
13
|
+
autocapture?: boolean;
|
|
14
|
+
/** Rage clicks: 3 quick clicks in a row (the browser's own click count). Default true; needs autocapture. */
|
|
15
|
+
rageClicks?: boolean;
|
|
16
|
+
/** Your app version or deployment ID, sent as context.release. */
|
|
17
|
+
release?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Store and send nothing until datacub.consent.grant(). Default false: tracking starts at once.
|
|
20
|
+
* Turn it on with "Ask for consent first" in the project's settings, which makes datacub refuse events
|
|
21
|
+
* sent without a grant.
|
|
22
|
+
*/
|
|
23
|
+
requireConsent?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The insights module (Web Vitals, long tasks, resource totals, form field details, device
|
|
26
|
+
* model), loaded after tracking starts from apiHost. Default true.
|
|
27
|
+
*/
|
|
28
|
+
insights?: boolean;
|
|
29
|
+
/** Turn kinds of capture off on this site. The project's settings in datacub can turn them off too. */
|
|
30
|
+
capture?: Capture;
|
|
31
|
+
}
|
|
32
|
+
export interface Capture {
|
|
33
|
+
/** Text of clicked buttons and links. */
|
|
34
|
+
text?: boolean;
|
|
35
|
+
/** Page titles. */
|
|
36
|
+
title?: boolean;
|
|
37
|
+
/** URL query values. */
|
|
38
|
+
query?: boolean;
|
|
39
|
+
/** JavaScript errors and failed resources. */
|
|
40
|
+
errors?: boolean;
|
|
41
|
+
/** Failed and slow fetch and XMLHttpRequest calls. */
|
|
42
|
+
network?: boolean;
|
|
43
|
+
/** Form start, invalid submit and field details. */
|
|
44
|
+
forms?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Who the user is, beyond the ID. email, name and phone are shown on their profile and are
|
|
48
|
+
* searchable; they never link two people. Any other key is a user property and passes the same
|
|
49
|
+
* privacy rules as track() properties.
|
|
50
|
+
*/
|
|
51
|
+
export interface IdentifyOptions {
|
|
52
|
+
/** Opaque workspace or organisation ID. Never a name or email. */
|
|
53
|
+
account?: string | number;
|
|
54
|
+
email?: string;
|
|
55
|
+
name?: string;
|
|
56
|
+
phone?: string;
|
|
57
|
+
[trait: string]: Property | undefined;
|
|
58
|
+
}
|
|
59
|
+
export interface GrantOptions {
|
|
60
|
+
method?: 'banner' | 'settings' | 'api' | 'cmp';
|
|
61
|
+
/** The customer's privacy notice version, at most 64 characters. */
|
|
62
|
+
policyVersion?: string;
|
|
63
|
+
/** Only from an explicit user action: lets a grant override Global Privacy Control. */
|
|
64
|
+
overrideGPC?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface DatacubClient {
|
|
67
|
+
init(publicKey: string, options?: InitOptions): void;
|
|
68
|
+
track(event: string, properties?: Properties): void;
|
|
69
|
+
identify(userId: string | number, options?: IdentifyOptions): void;
|
|
70
|
+
/** The same with the id inside: identify({ id: 'u_42', email, plan: 'pro' }). */
|
|
71
|
+
identify(profile: IdentifyOptions & {
|
|
72
|
+
id?: string | number;
|
|
73
|
+
userId?: string | number;
|
|
74
|
+
user_id?: string | number;
|
|
75
|
+
}): void;
|
|
76
|
+
reset(): void;
|
|
77
|
+
consent: {
|
|
78
|
+
grant(options?: GrantOptions): void;
|
|
79
|
+
revoke(): void;
|
|
80
|
+
};
|
|
81
|
+
/** Added by the feedback widget (start() from @datacub/web/feedback, or /v1/feedback.js): show one question now. */
|
|
82
|
+
ask?(questionId: string, options?: {
|
|
83
|
+
into?: Element | string;
|
|
84
|
+
}): void;
|
|
85
|
+
/** Added by the feedback module: open the "Send feedback" card. */
|
|
86
|
+
feedback?(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Added by the script-tag flags module (/v1/flags.js; with npm, import flag from @datacub/web/flags): is this feature flag on for this
|
|
89
|
+
* visitor? false when it is off, unknown, or cannot be decided (before consent, offline).
|
|
90
|
+
*/
|
|
91
|
+
flag?(key: string): Promise<boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* Added by the flags module: this visitor's version of an experiment, 'A' (the original) or 'B'.
|
|
94
|
+
* Records that they saw it. 'A' when it is not running or cannot be decided.
|
|
95
|
+
*/
|
|
96
|
+
experiment?(key: string): Promise<'A' | 'B'>;
|
|
97
|
+
/** @internal the feedback and flags modules' way in */
|
|
98
|
+
_fb(): unknown[];
|
|
99
|
+
}
|
|
100
|
+
declare global {
|
|
101
|
+
var datacub: DatacubClient;
|
|
102
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
type Lang = 'ar' | 'en';
|
|
2
|
+
export type CardType = 'choice' | 'thumbs' | 'text' | 'nps' | 'general';
|
|
3
|
+
export interface Card {
|
|
4
|
+
lang: Lang;
|
|
5
|
+
type: CardType;
|
|
6
|
+
title: string;
|
|
7
|
+
options?: {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
}[];
|
|
11
|
+
followup?: string | null;
|
|
12
|
+
followupOn?: string[] | null;
|
|
13
|
+
}
|
|
14
|
+
export interface Look {
|
|
15
|
+
accent: string;
|
|
16
|
+
position: 'end' | 'start';
|
|
17
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
18
|
+
}
|
|
19
|
+
/** An editor edits the card itself: the same card, with its words as fields. */
|
|
20
|
+
export interface Edit {
|
|
21
|
+
title(v: string): void;
|
|
22
|
+
option(id: string, v: string): void;
|
|
23
|
+
add(id: string): void;
|
|
24
|
+
remove(id: string): void;
|
|
25
|
+
followup(v: string): void;
|
|
26
|
+
focus?: string | null;
|
|
27
|
+
ph: {
|
|
28
|
+
title: string;
|
|
29
|
+
option: (n: number) => string;
|
|
30
|
+
add: string;
|
|
31
|
+
remove: string;
|
|
32
|
+
followup: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
interface Client {
|
|
36
|
+
track: (...a: unknown[]) => void;
|
|
37
|
+
identify: (...a: unknown[]) => void;
|
|
38
|
+
reset: (...a: unknown[]) => void;
|
|
39
|
+
consent: {
|
|
40
|
+
grant: (...a: unknown[]) => void;
|
|
41
|
+
};
|
|
42
|
+
ask?: (id: string, o?: {
|
|
43
|
+
into?: Element | string;
|
|
44
|
+
}) => void;
|
|
45
|
+
feedback?: () => void;
|
|
46
|
+
_fb?: () => unknown[];
|
|
47
|
+
}
|
|
48
|
+
export declare const ICONS: {
|
|
49
|
+
x: string;
|
|
50
|
+
check: string;
|
|
51
|
+
plus: string;
|
|
52
|
+
up: string;
|
|
53
|
+
down: string;
|
|
54
|
+
};
|
|
55
|
+
export interface Parts {
|
|
56
|
+
css: string;
|
|
57
|
+
title(card: Card, ed: Edit, c: HTMLElement): HTMLElement;
|
|
58
|
+
followup(card: Card, ed: Edit): HTMLElement;
|
|
59
|
+
choices(card: Card, ed: Edit): HTMLElement;
|
|
60
|
+
focus(ed: Edit, c: HTMLElement): void;
|
|
61
|
+
}
|
|
62
|
+
export declare const parts: Partial<Parts>;
|
|
63
|
+
export declare function icon(d: string, box?: number, width?: number): SVGSVGElement;
|
|
64
|
+
export declare function el<K extends keyof HTMLElementTagNameMap>(tag: K, cls?: string, text?: string): HTMLElementTagNameMap[K];
|
|
65
|
+
export interface Mounted {
|
|
66
|
+
close(): void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* One question card inside `root`. `send` stores the answer (it rejects to show a retry); `done`
|
|
70
|
+
* runs once when the card goes away, with whether an answer was sent. With `edit`, the same card
|
|
71
|
+
* is the composer's editor: its words are fields and nothing is sent.
|
|
72
|
+
*/
|
|
73
|
+
export declare function mount(root: ShadowRoot, card: Card, look: Look, o: {
|
|
74
|
+
send: (choice: string | null, text: string | null) => Promise<void>;
|
|
75
|
+
done?: (answered: boolean) => void;
|
|
76
|
+
preview?: boolean;
|
|
77
|
+
inline?: boolean;
|
|
78
|
+
quiet?: boolean;
|
|
79
|
+
focus?: boolean;
|
|
80
|
+
edit?: Edit;
|
|
81
|
+
}): Mounted;
|
|
82
|
+
/** Start the widget for this SDK client; the script build calls it with window.datacub. */
|
|
83
|
+
export declare function start(datacub: Client): void;
|
|
84
|
+
export {};
|
package/types/flags.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type Client = {
|
|
2
|
+
_fb?: () => unknown[];
|
|
3
|
+
} | unknown[] | undefined;
|
|
4
|
+
export type Variant = 'A' | 'B';
|
|
5
|
+
export declare function makeFlags(client: () => Client): {
|
|
6
|
+
flag: (key: string) => Promise<boolean>;
|
|
7
|
+
experiment: (key: string) => Promise<Variant>;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export declare const VERSION = "0.4.2";
|
|
2
|
+
export type Property = string | number | boolean | null | Date | Property[] | {
|
|
3
|
+
[key: string]: Property;
|
|
4
|
+
};
|
|
5
|
+
export type Properties = Record<string, Property>;
|
|
6
|
+
export interface InitOptions {
|
|
7
|
+
/** Ingestion origin or first-party proxy path. Default https://in.datacub.to */
|
|
8
|
+
apiHost?: string;
|
|
9
|
+
/** Treat `#/route` fragments as routes. Default false. */
|
|
10
|
+
hashRouting?: boolean;
|
|
11
|
+
/** Clicks and form submits. Default true. Pageviews and page leaves are always on. */
|
|
12
|
+
autocapture?: boolean;
|
|
13
|
+
/** Rage clicks: 3 quick clicks in a row (the browser's own click count). Default true; needs autocapture. */
|
|
14
|
+
rageClicks?: boolean;
|
|
15
|
+
/** Your app version or deployment ID, sent as context.release. */
|
|
16
|
+
release?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Store and send nothing until datacub.consent.grant(). Default false: tracking starts at once.
|
|
19
|
+
* Turn it on with "Ask for consent first" in the project's settings, which makes datacub refuse events
|
|
20
|
+
* sent without a grant.
|
|
21
|
+
*/
|
|
22
|
+
requireConsent?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The insights module (Web Vitals, long tasks, resource totals, form field details, device
|
|
25
|
+
* model), loaded after tracking starts from apiHost. Default true.
|
|
26
|
+
*/
|
|
27
|
+
insights?: boolean;
|
|
28
|
+
/** Turn kinds of capture off on this site. The project's settings in datacub can turn them off too. */
|
|
29
|
+
capture?: Capture;
|
|
30
|
+
}
|
|
31
|
+
export interface Capture {
|
|
32
|
+
/** Text of clicked buttons and links. */
|
|
33
|
+
text?: boolean;
|
|
34
|
+
/** Page titles. */
|
|
35
|
+
title?: boolean;
|
|
36
|
+
/** URL query values. */
|
|
37
|
+
query?: boolean;
|
|
38
|
+
/** JavaScript errors and failed resources. */
|
|
39
|
+
errors?: boolean;
|
|
40
|
+
/** Failed and slow fetch and XMLHttpRequest calls. */
|
|
41
|
+
network?: boolean;
|
|
42
|
+
/** Form start, invalid submit and field details. */
|
|
43
|
+
forms?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Who the user is, beyond the ID. email, name and phone are shown on their profile and are
|
|
47
|
+
* searchable; they never link two people. Any other key is a user property and passes the same
|
|
48
|
+
* privacy rules as track() properties.
|
|
49
|
+
*/
|
|
50
|
+
export interface IdentifyOptions {
|
|
51
|
+
/** Opaque workspace or organisation ID. Never a name or email. */
|
|
52
|
+
account?: string | number;
|
|
53
|
+
email?: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
phone?: string;
|
|
56
|
+
[trait: string]: Property | undefined;
|
|
57
|
+
}
|
|
58
|
+
export interface GrantOptions {
|
|
59
|
+
method?: 'banner' | 'settings' | 'api' | 'cmp';
|
|
60
|
+
/** The customer's privacy notice version, at most 64 characters. */
|
|
61
|
+
policyVersion?: string;
|
|
62
|
+
/** Only from an explicit user action: lets a grant override Global Privacy Control. */
|
|
63
|
+
overrideGPC?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface DatacubClient {
|
|
66
|
+
init(publicKey: string, options?: InitOptions): void;
|
|
67
|
+
track(event: string, properties?: Properties): void;
|
|
68
|
+
identify(userId: string | number, options?: IdentifyOptions): void;
|
|
69
|
+
/** The same with the id inside: identify({ id: 'u_42', email, plan: 'pro' }). */
|
|
70
|
+
identify(profile: IdentifyOptions & {
|
|
71
|
+
id?: string | number;
|
|
72
|
+
userId?: string | number;
|
|
73
|
+
user_id?: string | number;
|
|
74
|
+
}): void;
|
|
75
|
+
reset(): void;
|
|
76
|
+
consent: {
|
|
77
|
+
grant(options?: GrantOptions): void;
|
|
78
|
+
revoke(): void;
|
|
79
|
+
};
|
|
80
|
+
/** Added by the feedback widget (start() from @datacub/web/feedback, or /v1/feedback.js): show one question now. */
|
|
81
|
+
ask?(questionId: string, options?: {
|
|
82
|
+
into?: Element | string;
|
|
83
|
+
}): void;
|
|
84
|
+
/** Added by the feedback module: open the "Send feedback" card. */
|
|
85
|
+
feedback?(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Added by the script-tag flags module (/v1/flags.js; with npm, import flag from @datacub/web/flags): is this feature flag on for this
|
|
88
|
+
* visitor? false when it is off, unknown, or cannot be decided (before consent, offline).
|
|
89
|
+
*/
|
|
90
|
+
flag?(key: string): Promise<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* Added by the flags module: this visitor's version of an experiment, 'A' (the original) or 'B'.
|
|
93
|
+
* Records that they saw it. 'A' when it is not running or cannot be decided.
|
|
94
|
+
*/
|
|
95
|
+
experiment?(key: string): Promise<'A' | 'B'>;
|
|
96
|
+
/** @internal the feedback and flags modules' way in */
|
|
97
|
+
_fb(): unknown[];
|
|
98
|
+
}
|
|
99
|
+
declare const datacub: DatacubClient;
|
|
100
|
+
export default datacub;
|
package/types/scrub.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Redactions and drops since the last event; sent as $dropped_count, never with the values. */
|
|
2
|
+
export declare const tally: {
|
|
3
|
+
n: number;
|
|
4
|
+
};
|
|
5
|
+
export declare const toAscii: (s: string) => string;
|
|
6
|
+
export declare const digitsOnly: (s: string) => string;
|
|
7
|
+
export declare function scrub(s: string): string;
|
|
8
|
+
export declare function text(v: string, max?: number): string;
|
|
9
|
+
export declare const badText: (s: string) => boolean;
|
|
10
|
+
export declare function badKey(k: string, top: boolean): boolean;
|
|
11
|
+
export declare function clean(v: unknown, depth?: number): unknown;
|
|
12
|
+
export declare function segment(seg: string): string;
|
|
13
|
+
export interface Url {
|
|
14
|
+
url: string;
|
|
15
|
+
path: string;
|
|
16
|
+
utm?: Record<string, string>;
|
|
17
|
+
click_id_type?: string;
|
|
18
|
+
q?: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
export declare const code: (v: string) => boolean;
|
|
21
|
+
export declare const label: (v: string, max: number) => string;
|
|
22
|
+
export declare function cleanUrl(href: string, hashRouting?: boolean, query?: boolean): Url | null;
|
|
23
|
+
export declare function eventName(name: string): string | null;
|
|
24
|
+
export declare function validId(v: unknown, own: string[]): string | null;
|