@datacub/react-native 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +32 -2
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +64 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.mjs +1 -0
- package/dist/navigation.cjs +1 -0
- package/dist/navigation.d.cts +12 -0
- package/dist/navigation.d.ts +12 -0
- package/dist/navigation.mjs +1 -0
- package/navigation/package.json +5 -0
- package/package.json +92 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0-beta.1
|
|
4
|
+
|
|
5
|
+
First public beta, on the `next` dist-tag.
|
|
6
|
+
- `init`, `screen`, `track`, `identify`, `reset`, `flush` and `consent.grant()` / `consent.revoke()`, with an offline queue that survives restarts when you pass a storage adapter such as AsyncStorage.
|
|
7
|
+
- `trackNavigation(ref)` from `@datacub/react-native/navigation` sends a screen view on every React Navigation (and Expo Router) route change.
|
|
8
|
+
- Supports React Native 0.75 and later and Expo SDK 52 and later, on iOS and Android. Tested on Hermes and through Metro bundles; testing on physical devices is in progress.
|
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,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @datacub/react-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
datacub product analytics for React Native and Expo. Pure JavaScript, no device identifiers.
|
|
4
|
+
|
|
5
|
+
**Beta**, on the `next` tag. Not yet tested on physical devices.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx expo install @datacub/react-native@next @react-native-async-storage/async-storage expo-application
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
13
|
+
import * as Application from 'expo-application'
|
|
14
|
+
import datacub from '@datacub/react-native'
|
|
15
|
+
|
|
16
|
+
datacub.init('pk_live_YOUR_KEY', { storage: AsyncStorage, app: Application })
|
|
17
|
+
|
|
18
|
+
datacub.screen('Home') // a screen view
|
|
19
|
+
datacub.track('signup_completed', { plan: 'pro' }) // a custom event
|
|
20
|
+
datacub.identify(user.id, { email, name }) // after login
|
|
21
|
+
datacub.reset() // at logout
|
|
22
|
+
await datacub.flush() // send now
|
|
23
|
+
|
|
24
|
+
// only when the project asks for consent first: init(key, { ..., requireConsent: true })
|
|
25
|
+
datacub.consent.grant()
|
|
26
|
+
datacub.consent.revoke()
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
React Navigation: `onReady={() => trackNavigation(ref)}`, with `trackNavigation` from `@datacub/react-native/navigation`.
|
|
30
|
+
|
|
31
|
+
Add your app's bundle ID or package name under **Settings → General** in datacub.
|
|
32
|
+
|
|
33
|
+
Install with an AI agent, Expo Router, options and what gets sent: [docs.datacub.to](https://docs.datacub.to/install-mobile). Source: [datacub/sdk](https://github.com/datacub/sdk).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var{defineProperty:B,getOwnPropertyNames:It,getOwnPropertyDescriptor:Et}=Object,Ot=Object.prototype.hasOwnProperty;function St(t){return this[t]}var Nt=(t)=>{var e=(ct??=new WeakMap).get(t),n;if(e)return e;if(e=B({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function"){for(var i of It(t))if(!Ot.call(e,i))B(e,i,{get:St.bind(t,i),enumerable:!(n=Et(t,i))||n.enumerable})}return ct.set(t,e),e},ct;var Tt=(t)=>t;function Pt(t,e){this[t]=Tt.bind(null,e)}var Dt=(t,e)=>{for(var n in e)B(t,n,{get:e[n],enumerable:!0,configurable:!0,set:Pt.bind(e,n)})};var se={};Dt(se,{VERSION:()=>ht,default:()=>oe});module.exports=Nt(se);var l=require("react-native");var p={n:0},G=(t)=>t.replace(/[٠-٩۰-۹0-9]/g,(e)=>String(e.charCodeAt(0)&15)),qt=/[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]/g,ut=(t)=>G(t).replace(qt,""),Rt=/\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./()ـ٫٬‐-―----]*\d){8,}|[\w+/=]{32,}/gi;function K(t){let e="",n=0;for(let i of G(t).matchAll(Rt)){if(/^[0-9a-f]{8}-/i.test(i[0])&&i[0].length===36)continue;e+=`${t.slice(n,i.index)}[redacted]`,n=i.index+i[0].length,p.n++}return e+t.slice(n)}function z(t,e=1024){if(t=t.normalize("NFC"),t.length>256||t.trim().split(/\s+/).length>11)return p.n++,"[redacted]";return K(t).slice(0,e).replace(/[\uD800-\uDBFF]$/,"")}var A=(t)=>/[\u0000-\u001f\u007f-\u009f--]/.test(t),jt=/(?: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|كلمهالمرور|كلمهالسر|الرمزالسري|الرقمالسري|رمزالتحقق|رقمالهويه|الهويهالوطنيه|الاقامه|البطاقه|الايبان)$/;function Ct(t,e){let n=t.normalize("NFKD").replace(/[\p{M}\u0640]/gu,"").replace(/ة/g,"ه").replace(/ى/g,"ي").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)||A(t)||/^(?:__proto__|constructor|prototype)$/.test(t)||e&&/^(?:\$|(?:distinct_id|person_id|project_id|timestamp|uuid|ip|api_key)$)/.test(t)||jt.test(n.join(""))&&!/^(?:japan|span|timespan|lifespan|wingspan|saucepan|spin|chopin|android)$/.test(n[n.length-1])||n.some((i)=>/^(?:password|passwd|pwd|passcode|otp|pin|secret|iqama|ssn|cvv|cvc|iban)$/.test(i))}function C(t,e=0){if(typeof t==="string")return z(t);if(typeof t==="number")return Number.isFinite(t)?Number.isInteger(t)&&K(`${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((r)=>C(r,e+1)).filter((r)=>r!==void 0);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n)return;let i={};for(let[r,s]of Object.entries(t).slice(0,200)){let o=r.trim();if(Ct(o,!e))p.n++;else{let x=C(s,e+1);if(x!==void 0)i[o]=x}}return i}function dt(t){let e=t;try{e=decodeURIComponent(t)}catch{}e=G(e);let n=p.n;if(K(e)!==e)return p.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 i=e.replace(/\D/g,"").length;return i&&(i===e.length||i>3&&i*2>=e.length)?":id":t}function ft(t){let e=t.trim().normalize("NFC");return!e||[...e].length>100||e[0]==="$"||A(e)||/[0-9a-f]{8}-[0-9a-f]{4}-|[0-9a-f]{16}|@/i.test(e)||/\d{6}/.test(ut(e))?null:e}function D(t,e){if(typeof t==="number"&&Number.isFinite(t))t=`${t}`;if(typeof t!=="string")return null;let n=t.trim().normalize("NFC"),i=ut(n),r=0;for(let s=0;s<i.length;s++){let o=+i[i.length-1-s];r+=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)||A(n)||/@|^eyJ/.test(n)||/^(?:[12]\d{9}|(?:\+?966|00966|0)5\d{8}|\+\d{8,15})$/.test(i)||/^[2-6]\d{14,15}$/.test(i)&&r%10===0||e.includes(n)?null:n}var ht="0.1.0-beta.1",zt=1800000,yt=86400000,Vt=29*yt,et="datacub_state",pt=/^[0-9a-f]{8}-[0-9a-f]{4}-[47][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,gt=!1,nt=!1,bt=Promise.resolve(),wt="",_t="",V=null,T,F=!1,W={},u="pending",m=()=>u==="granted"||u==="not_required",L=!1,Y=!1,q=null,f="",g=null,P=null,O=null,h="",M=0,S=0,w=null,U=!1,kt={},_=!0,Ft=0,a=[],y=[],b=0,N=0,E=!1,d,X,H=null,mt=new WeakMap,Q=[],it=()=>Date.now(),Ut=()=>typeof __DEV__<"u"&&!!__DEV__;function c(t,e){if(e||Ut())console.warn(`[datacub] ${t}`)}var k=(t)=>(...e)=>{try{t(...e)}catch{}};function j(t){let e=new Uint8Array(16),n=globalThis.crypto;if(n?.getRandomValues)n.getRandomValues(e);else for(let r=0;r<16;r++)e[r]=Math.random()*256|0;for(let r=5,s=t;t&&r>=0;r--,s=Math.floor(s/256))e[r]=s&255;e[6]=e[6]&15|(t?112:64),e[8]=e[8]&63|128;let i=Array.from(e,(r)=>(r+256).toString(16).slice(1)).join("");return`${i.slice(0,8)}-${i.slice(8,12)}-${i.slice(12,16)}-${i.slice(16,20)}-${i.slice(20)}`}function Lt(t){let e=t.length;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);if(i>127)e+=i>2047&&(i<55296||i>57343)?2:1}return e}var rt=(t)=>{let e=mt.get(t);if(e===void 0)e=Lt(JSON.stringify(t)),mt.set(t,e);return e};function Mt(t){let e=l.Dimensions.get("screen"),n="";try{n=Intl.DateTimeFormat().resolvedOptions().locale}catch{}let i=(r)=>typeof r==="string"&&r&&!A(r)?r.slice(0,64):null;return{locale:n.slice(0,35),platform:l.Platform.OS,os_version:String((l.Platform.OS==="android"?l.Platform.constants?.Release:l.Platform.Version)??"").slice(0,32),device_class:Math.min(e.width,e.height)>=600?"tablet":"mobile",app_version:i(t?.nativeApplicationVersion),app_build:i(t?.nativeBuildVersion)}}async function Jt(){if(!T){c("no storage: ids and queued events last only until the app closes. Pass init(key, { storage })",!0);return}let t;try{t=await T.getItem(et),F=!0}catch{c("storage read failed: running in memory",!0);return}let e={};try{let n=typeof t==="string"?JSON.parse(t):null;if(n&&typeof n==="object"&&!Array.isArray(n))e=n}catch{}if(typeof e.a==="string"&&pt.test(e.a)){if(f=e.a,g=D(e.u,[]),P=D(e.c,[]),typeof e.s==="string"&&pt.test(e.s)&&Number.isFinite(e.ss)&&Number.isFinite(e.sl))h=e.s,M=e.ss,S=e.sl}if(L=e.o===1,q=typeof e.g==="string"?e.g:null,Array.isArray(e.q))for(let n of e.q)if(n&&typeof n==="object"&&typeof n.uuid==="string"&&typeof n.event==="string"&&typeof n.ts==="string"&&typeof n.anon_id==="string")a.push(n);else b++;at()}function v(t){if(t)tt();else X||=setTimeout(k(tt),100)}async function tt(){if(clearTimeout(X),X=void 0,!T||!F||!m())return;try{await T.setItem(et,JSON.stringify({a:f,u:g,c:P,s:h,ss:M,sl:S,g:q,q:y.concat(a)}))}catch{F=!1,c("storage write failed: ids and queued events now last only until the app closes",!0)}}async function $t(){try{await T?.setItem(et,'{"o":1}')}catch{}}var vt=(t)=>!h||t-S>zt||t-M>yt;function Zt(t){if(vt(t))h=j(t),M=S=t;else if(t>S)S=t}function J(t,e){if(!m()||E)return;let n=it();if(Zt(n),p.n)e.$dropped_count=p.n;p.n=0;let i={uuid:j(n),event:t,ts:new Date(n).toISOString(),anon_id:f,user_id:g,account_id:P,session_id:h,page_id:null,seq:Ft++,consent_state:u,persistence:F?"storage":"memory",context:w?{...W,screen:w}:W,properties:e};if(rt(i)>32768){b++;return}a.push(i),at(),v(),Z()}var st=(t)=>t&&typeof t==="object"&&!Array.isArray(t)?C(t):{};function Bt(t,e){if(typeof t!=="string")return;let n=ft(t);if(!n)return c(`track: invalid event name "${t.slice(0,40)}"`);J(n,st(e))}function Gt(t,e){if(typeof t!=="string")return;let n=t.trim().normalize("NFC");if(!n||n.length>200||A(n))return c("screen: invalid name");let i=z(n.split("/").map((s)=>s&&dt(s)).join("/"),200);if(i===w)return;let r=w;w=i,ot(st(e),r)}function ot(t,e){if(U=!_,e)t.$prev_screen=e;if(U)kt=t;else J("$screen",t)}function at(){let t=it(),e=0;for(let n=a.length-1;n>=0;n--){let i=a[n];if(e+=rt(i),a.length-n>1000||e>1048576||t-Date.parse(i.ts)>Vt){b+=n+1,a.splice(0,n+1);break}}}function Z(){if(!_||E||N||!a.length)return;if(a.length>19)clearTimeout(d),d=setTimeout(k(R),0);else d||=setTimeout(k(R),1e4)}function Kt(){let t=0,e=200;while(t<a.length&&t<50){if(e+=rt(a[t])+1,e>30720)break;t++}return a.splice(0,t||1)}function R(){return clearTimeout(d),d=void 0,H??=Yt().then((t)=>{if(H=null,t)Z();return t}),H}async function Yt(){if(E||!m()||!a.length)return!1;y=Kt();let t=b;b=0;let e=0;try{let i=new AbortController,r=setTimeout(()=>i.abort(),1e4);try{let s=await fetch(_t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({api_key:wt,sent_at:new Date().toISOString(),lib:{name:"@datacub/react-native",version:ht},...V?{app_id:V}:{},events:y,...t?{dropped:t}:{}}),signal:i.signal}),o=s.status;if(o===401||o===403)E=!0,c(`ingestion refused this app (${o}); sending stopped`);else if(o===408||o===429||o>499)e=Math.min(+(s.headers.get("Retry-After")||0),3600)*1000||-1;else if(N=0,o>299)b+=y.length+t;else if((await s.json().catch(()=>0)).directives?.includes("rotate_anon_id"))lt()}finally{clearTimeout(r)}}catch{e=-1}let n=y;if(y=[],e&&m()&&!E){if(a=n.concat(a),b+=t,at(),++N<10&&_)d=setTimeout(k(R),e>0?e:Math.random()*Math.min(1000*2**N,300000))}if(m())v();else if(u==="denied")$t();return!e&&!E}async function Ht(){await bt,N=0;while(a.length&&await R());await tt()}function Wt(t){if(t==="active"){if(_)return;if(_=!0,N=0,w&&m()&&(U||vt(it())))ot(U?kt:{$resumed:!0});if(a.length)Z()}else if(t==="background"||t==="inactive"){if(_=!1,clearTimeout(d),d=void 0,nt){if(v(!0),a.length&&m())R()}}}function Xt(){u="not_required",f||=j(),v()}function Qt(t={}){if(u==="granted")return;if(u="granted",L=!1,!f)f=j();let e=typeof t.policyVersion==="string"?z(t.policyVersion,64):null;if(q!==(e??""))q=e??"",J("$consent",{$state:"granted",$method:/^(?:banner|settings|api|cmp)$/.test(`${t.method}`)?t.method:"api",$policy_version:e,$purposes:["analytics"]});if(O)xt(...O);if(O=null,w)ot({});v(),Z()}function te(){u="denied",L=!0,clearTimeout(d),d=void 0,a=[],y=[],f=h="",g=P=O=q=null,$t()}function xt(t,e,n){if(g&&g!==t)lt();if(P=e,g!==t)g=t,n.$anon_id=f;for(let i in n)return J(n.$anon_id?"$identify":"$set",n);v()}function ee(t,e){let n=[f,h],i=D(t,n),r=e?.account==null?null:D(e.account,n);if(!i||e?.account!=null&&!r)return c("identify: ID refused (personal data shape or placeholder)");let s=st(e);delete s.account;for(let o of["email","name","phone"])if(o in s){let x=e[o];if(typeof x==="string"&&x.length<=256)s[`$${o}`]=x;delete s[o]}if(m())xt(i,r,s);else if(u==="pending")O=[i,r,s]}function lt(){if(O=null,!m())return;f=j(),g=P=null,h="",v()}function ne(t,e={}){if(gt||typeof t!=="string")return;if(/^sk_/.test(t))return console.error("[datacub] refused a secret key. Use a pk_ key.");let n=(e.apiHost||"https://in.datacub.to").replace(/\/+$/,"");if(!/^pk_(?:live|test)_[A-Za-z0-9]{24,48}$/.test(t)||/^[a-z]+:\/\/[^/]*@/i.test(n)||!/^https:\/\/|^http:\/\/(?:localhost|127\.\d+\.\d+\.\d+|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(?:1[6-9]|2\d|3[01])\.\d+\.\d+)[:/]/.test(`${n}/`))return c("init: expected a pk_live_ or pk_test_ key and an https apiHost");if(l.Platform.OS!=="ios"&&l.Platform.OS!=="android")return c(`init: ${l.Platform.OS} is not supported; on the web use @datacub/web`);gt=!0,wt=t,_t=`${n}/v1/batch`,T=e.storage,Y=e.requireConsent===!0;let i=e.app?.applicationId;if(V=typeof i==="string"&&/^[A-Za-z0-9_.-]{1,155}$/.test(i)?i:null,!V)c("init: no app id. Pass app: Application from expo-application, or { applicationId }");W=Mt(e.app);let r=l.AppState.currentState;_=r!=="background"&&r!=="inactive",l.AppState.addEventListener("change",k(Wt)),bt=Jt().catch(()=>{}).then(()=>{if(nt=!0,L)u="denied";else if(!Y)Xt();for(let[s,o]of Q.splice(0))At(s,o);if(u==="pending"&&Y)c("consent pending: nothing is stored or sent until datacub.consent.grant()")})}var ie={track:Bt,screen:Gt,identify:ee,reset:lt,grant:Qt,revoke:te};function At(t,e){try{ie[t]?.(...e)}catch{}}var I=(t)=>k((...e)=>{if(nt)At(t,e);else if(Q.length<100||t==="grant"||t==="revoke"||t==="reset")Q.push([t,e])}),re={init:k(ne),track:I("track"),screen:I("screen"),identify:I("identify"),reset:I("reset"),flush:()=>Ht().catch(()=>{}),consent:{grant:I("grant"),revoke:I("revoke")}},oe=re;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export declare const VERSION: string;
|
|
2
|
+
export type Property = string | number | boolean | null | Date | Property[] | {
|
|
3
|
+
[key: string]: Property;
|
|
4
|
+
};
|
|
5
|
+
export type Properties = Record<string, Property>;
|
|
6
|
+
/** AsyncStorage's shape. Sync or async both work, so an MMKV wrapper fits too. */
|
|
7
|
+
export interface Storage {
|
|
8
|
+
getItem(key: string): string | null | undefined | Promise<string | null | undefined>;
|
|
9
|
+
setItem(key: string, value: string): unknown;
|
|
10
|
+
removeItem(key: string): unknown;
|
|
11
|
+
}
|
|
12
|
+
/** expo-application's shape: pass `import * as Application from 'expo-application'`, or your own values. */
|
|
13
|
+
export interface AppInfo {
|
|
14
|
+
applicationId: string | null;
|
|
15
|
+
nativeApplicationVersion?: string | null;
|
|
16
|
+
nativeBuildVersion?: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface InitOptions {
|
|
19
|
+
/** Ingestion origin or your proxy. Default https://in.datacub.to */
|
|
20
|
+
apiHost?: string;
|
|
21
|
+
/** Where ids and unsent events live between launches. Without it nothing survives a restart. */
|
|
22
|
+
storage?: Storage;
|
|
23
|
+
/** Your app id (bundle id or package name), version and build. */
|
|
24
|
+
app?: AppInfo;
|
|
25
|
+
/**
|
|
26
|
+
* Store and send nothing until datacub.consent.grant(). Default false: tracking starts at once.
|
|
27
|
+
* Turn it on with "Ask for consent first" in the project's settings, which makes datacub refuse events
|
|
28
|
+
* sent without a grant.
|
|
29
|
+
*/
|
|
30
|
+
requireConsent?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Who the user is, beyond the ID. email, name and phone are shown on their profile and are
|
|
34
|
+
* searchable; they never link two people. Any other key is a user property and passes the same
|
|
35
|
+
* privacy rules as track() properties.
|
|
36
|
+
*/
|
|
37
|
+
export interface IdentifyOptions {
|
|
38
|
+
/** Opaque workspace or organisation ID. Never a name or email. */
|
|
39
|
+
account?: string | number;
|
|
40
|
+
email?: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
phone?: string;
|
|
43
|
+
[trait: string]: Property | undefined;
|
|
44
|
+
}
|
|
45
|
+
export interface GrantOptions {
|
|
46
|
+
method?: 'banner' | 'settings' | 'api' | 'cmp';
|
|
47
|
+
/** Your privacy notice version, at most 64 characters. */
|
|
48
|
+
policyVersion?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface DatacubClient {
|
|
51
|
+
init(publicKey: string, options?: InitOptions): void;
|
|
52
|
+
track(event: string, properties?: Properties): void;
|
|
53
|
+
screen(name: string, properties?: Properties): void;
|
|
54
|
+
identify(userId: string | number, options?: IdentifyOptions): void;
|
|
55
|
+
reset(): void;
|
|
56
|
+
/** Sends what is queued. Resolves when done or when sending failed; never rejects. */
|
|
57
|
+
flush(): Promise<void>;
|
|
58
|
+
consent: {
|
|
59
|
+
grant(options?: GrantOptions): void;
|
|
60
|
+
revoke(): void;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
declare const datacub: DatacubClient;
|
|
64
|
+
export default datacub;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export declare const VERSION: string;
|
|
2
|
+
export type Property = string | number | boolean | null | Date | Property[] | {
|
|
3
|
+
[key: string]: Property;
|
|
4
|
+
};
|
|
5
|
+
export type Properties = Record<string, Property>;
|
|
6
|
+
/** AsyncStorage's shape. Sync or async both work, so an MMKV wrapper fits too. */
|
|
7
|
+
export interface Storage {
|
|
8
|
+
getItem(key: string): string | null | undefined | Promise<string | null | undefined>;
|
|
9
|
+
setItem(key: string, value: string): unknown;
|
|
10
|
+
removeItem(key: string): unknown;
|
|
11
|
+
}
|
|
12
|
+
/** expo-application's shape: pass `import * as Application from 'expo-application'`, or your own values. */
|
|
13
|
+
export interface AppInfo {
|
|
14
|
+
applicationId: string | null;
|
|
15
|
+
nativeApplicationVersion?: string | null;
|
|
16
|
+
nativeBuildVersion?: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface InitOptions {
|
|
19
|
+
/** Ingestion origin or your proxy. Default https://in.datacub.to */
|
|
20
|
+
apiHost?: string;
|
|
21
|
+
/** Where ids and unsent events live between launches. Without it nothing survives a restart. */
|
|
22
|
+
storage?: Storage;
|
|
23
|
+
/** Your app id (bundle id or package name), version and build. */
|
|
24
|
+
app?: AppInfo;
|
|
25
|
+
/**
|
|
26
|
+
* Store and send nothing until datacub.consent.grant(). Default false: tracking starts at once.
|
|
27
|
+
* Turn it on with "Ask for consent first" in the project's settings, which makes datacub refuse events
|
|
28
|
+
* sent without a grant.
|
|
29
|
+
*/
|
|
30
|
+
requireConsent?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Who the user is, beyond the ID. email, name and phone are shown on their profile and are
|
|
34
|
+
* searchable; they never link two people. Any other key is a user property and passes the same
|
|
35
|
+
* privacy rules as track() properties.
|
|
36
|
+
*/
|
|
37
|
+
export interface IdentifyOptions {
|
|
38
|
+
/** Opaque workspace or organisation ID. Never a name or email. */
|
|
39
|
+
account?: string | number;
|
|
40
|
+
email?: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
phone?: string;
|
|
43
|
+
[trait: string]: Property | undefined;
|
|
44
|
+
}
|
|
45
|
+
export interface GrantOptions {
|
|
46
|
+
method?: 'banner' | 'settings' | 'api' | 'cmp';
|
|
47
|
+
/** Your privacy notice version, at most 64 characters. */
|
|
48
|
+
policyVersion?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface DatacubClient {
|
|
51
|
+
init(publicKey: string, options?: InitOptions): void;
|
|
52
|
+
track(event: string, properties?: Properties): void;
|
|
53
|
+
screen(name: string, properties?: Properties): void;
|
|
54
|
+
identify(userId: string | number, options?: IdentifyOptions): void;
|
|
55
|
+
reset(): void;
|
|
56
|
+
/** Sends what is queued. Resolves when done or when sending failed; never rejects. */
|
|
57
|
+
flush(): Promise<void>;
|
|
58
|
+
consent: {
|
|
59
|
+
grant(options?: GrantOptions): void;
|
|
60
|
+
revoke(): void;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
declare const datacub: DatacubClient;
|
|
64
|
+
export default datacub;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{AppState as dt,Dimensions as Ot,Platform as y}from"react-native";var f={n:0},B=(t)=>t.replace(/[٠-٩۰-۹0-9]/g,(e)=>String(e.charCodeAt(0)&15)),xt=/[\s./()\u0640\u066b\u066c\u2010-\u2015\u200b-\u200f\u061c\u202a-\u202e\u2066-\u2069\ufeff-]/g,lt=(t)=>B(t).replace(xt,""),At=/\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./()ـ٫٬‐-―----]*\d){8,}|[\w+/=]{32,}/gi;function G(t){let e="",n=0;for(let i of B(t).matchAll(At)){if(/^[0-9a-f]{8}-/i.test(i[0])&&i[0].length===36)continue;e+=`${t.slice(n,i.index)}[redacted]`,n=i.index+i[0].length,f.n++}return e+t.slice(n)}function z(t,e=1024){if(t=t.normalize("NFC"),t.length>256||t.trim().split(/\s+/).length>11)return f.n++,"[redacted]";return G(t).slice(0,e).replace(/[\uD800-\uDBFF]$/,"")}var A=(t)=>/[\u0000-\u001f\u007f-\u009f--]/.test(t),It=/(?: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|كلمهالمرور|كلمهالسر|الرمزالسري|الرقمالسري|رمزالتحقق|رقمالهويه|الهويهالوطنيه|الاقامه|البطاقه|الايبان)$/;function Et(t,e){let n=t.normalize("NFKD").replace(/[\p{M}\u0640]/gu,"").replace(/ة/g,"ه").replace(/ى/g,"ي").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)||A(t)||/^(?:__proto__|constructor|prototype)$/.test(t)||e&&/^(?:\$|(?:distinct_id|person_id|project_id|timestamp|uuid|ip|api_key)$)/.test(t)||It.test(n.join(""))&&!/^(?:japan|span|timespan|lifespan|wingspan|saucepan|spin|chopin|android)$/.test(n[n.length-1])||n.some((i)=>/^(?:password|passwd|pwd|passcode|otp|pin|secret|iqama|ssn|cvv|cvc|iban)$/.test(i))}function C(t,e=0){if(typeof t==="string")return z(t);if(typeof t==="number")return Number.isFinite(t)?Number.isInteger(t)&&G(`${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((r)=>C(r,e+1)).filter((r)=>r!==void 0);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n)return;let i={};for(let[r,s]of Object.entries(t).slice(0,200)){let o=r.trim();if(Et(o,!e))f.n++;else{let x=C(s,e+1);if(x!==void 0)i[o]=x}}return i}function ct(t){let e=t;try{e=decodeURIComponent(t)}catch{}e=B(e);let n=f.n;if(G(e)!==e)return f.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 i=e.replace(/\D/g,"").length;return i&&(i===e.length||i>3&&i*2>=e.length)?":id":t}function ut(t){let e=t.trim().normalize("NFC");return!e||[...e].length>100||e[0]==="$"||A(e)||/[0-9a-f]{8}-[0-9a-f]{4}-|[0-9a-f]{16}|@/i.test(e)||/\d{6}/.test(lt(e))?null:e}function D(t,e){if(typeof t==="number"&&Number.isFinite(t))t=`${t}`;if(typeof t!=="string")return null;let n=t.trim().normalize("NFC"),i=lt(n),r=0;for(let s=0;s<i.length;s++){let o=+i[i.length-1-s];r+=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)||A(n)||/@|^eyJ/.test(n)||/^(?:[12]\d{9}|(?:\+?966|00966|0)5\d{8}|\+\d{8,15})$/.test(i)||/^[2-6]\d{14,15}$/.test(i)&&r%10===0||e.includes(n)?null:n}var St="0.1.0-beta.1",Nt=1800000,mt=86400000,Tt=29*mt,tt="datacub_state",ft=/^[0-9a-f]{8}-[0-9a-f]{4}-[47][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,pt=!1,et=!1,ht=Promise.resolve(),yt="",bt="",V=null,T,F=!1,H={},c="pending",g=()=>c==="granted"||c==="not_required",L=!1,K=!1,q=null,d="",p=null,P=null,O=null,m="",M=0,S=0,w=null,U=!1,wt={},_=!0,Pt=0,a=[],h=[],b=0,N=0,E=!1,u,W,Y=null,gt=new WeakMap,X=[],nt=()=>Date.now(),Dt=()=>typeof __DEV__<"u"&&!!__DEV__;function l(t,e){if(e||Dt())console.warn(`[datacub] ${t}`)}var k=(t)=>(...e)=>{try{t(...e)}catch{}};function j(t){let e=new Uint8Array(16),n=globalThis.crypto;if(n?.getRandomValues)n.getRandomValues(e);else for(let r=0;r<16;r++)e[r]=Math.random()*256|0;for(let r=5,s=t;t&&r>=0;r--,s=Math.floor(s/256))e[r]=s&255;e[6]=e[6]&15|(t?112:64),e[8]=e[8]&63|128;let i=Array.from(e,(r)=>(r+256).toString(16).slice(1)).join("");return`${i.slice(0,8)}-${i.slice(8,12)}-${i.slice(12,16)}-${i.slice(16,20)}-${i.slice(20)}`}function qt(t){let e=t.length;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);if(i>127)e+=i>2047&&(i<55296||i>57343)?2:1}return e}var it=(t)=>{let e=gt.get(t);if(e===void 0)e=qt(JSON.stringify(t)),gt.set(t,e);return e};function Rt(t){let e=Ot.get("screen"),n="";try{n=Intl.DateTimeFormat().resolvedOptions().locale}catch{}let i=(r)=>typeof r==="string"&&r&&!A(r)?r.slice(0,64):null;return{locale:n.slice(0,35),platform:y.OS,os_version:String((y.OS==="android"?y.constants?.Release:y.Version)??"").slice(0,32),device_class:Math.min(e.width,e.height)>=600?"tablet":"mobile",app_version:i(t?.nativeApplicationVersion),app_build:i(t?.nativeBuildVersion)}}async function jt(){if(!T){l("no storage: ids and queued events last only until the app closes. Pass init(key, { storage })",!0);return}let t;try{t=await T.getItem(tt),F=!0}catch{l("storage read failed: running in memory",!0);return}let e={};try{let n=typeof t==="string"?JSON.parse(t):null;if(n&&typeof n==="object"&&!Array.isArray(n))e=n}catch{}if(typeof e.a==="string"&&ft.test(e.a)){if(d=e.a,p=D(e.u,[]),P=D(e.c,[]),typeof e.s==="string"&&ft.test(e.s)&&Number.isFinite(e.ss)&&Number.isFinite(e.sl))m=e.s,M=e.ss,S=e.sl}if(L=e.o===1,q=typeof e.g==="string"?e.g:null,Array.isArray(e.q))for(let n of e.q)if(n&&typeof n==="object"&&typeof n.uuid==="string"&&typeof n.event==="string"&&typeof n.ts==="string"&&typeof n.anon_id==="string")a.push(n);else b++;ot()}function v(t){if(t)Q();else W||=setTimeout(k(Q),100)}async function Q(){if(clearTimeout(W),W=void 0,!T||!F||!g())return;try{await T.setItem(tt,JSON.stringify({a:d,u:p,c:P,s:m,ss:M,sl:S,g:q,q:h.concat(a)}))}catch{F=!1,l("storage write failed: ids and queued events now last only until the app closes",!0)}}async function _t(){try{await T?.setItem(tt,'{"o":1}')}catch{}}var kt=(t)=>!m||t-S>Nt||t-M>mt;function Ct(t){if(kt(t))m=j(t),M=S=t;else if(t>S)S=t}function J(t,e){if(!g()||E)return;let n=nt();if(Ct(n),f.n)e.$dropped_count=f.n;f.n=0;let i={uuid:j(n),event:t,ts:new Date(n).toISOString(),anon_id:d,user_id:p,account_id:P,session_id:m,page_id:null,seq:Pt++,consent_state:c,persistence:F?"storage":"memory",context:w?{...H,screen:w}:H,properties:e};if(it(i)>32768){b++;return}a.push(i),ot(),v(),Z()}var rt=(t)=>t&&typeof t==="object"&&!Array.isArray(t)?C(t):{};function zt(t,e){if(typeof t!=="string")return;let n=ut(t);if(!n)return l(`track: invalid event name "${t.slice(0,40)}"`);J(n,rt(e))}function Vt(t,e){if(typeof t!=="string")return;let n=t.trim().normalize("NFC");if(!n||n.length>200||A(n))return l("screen: invalid name");let i=z(n.split("/").map((s)=>s&&ct(s)).join("/"),200);if(i===w)return;let r=w;w=i,st(rt(e),r)}function st(t,e){if(U=!_,e)t.$prev_screen=e;if(U)wt=t;else J("$screen",t)}function ot(){let t=nt(),e=0;for(let n=a.length-1;n>=0;n--){let i=a[n];if(e+=it(i),a.length-n>1000||e>1048576||t-Date.parse(i.ts)>Tt){b+=n+1,a.splice(0,n+1);break}}}function Z(){if(!_||E||N||!a.length)return;if(a.length>19)clearTimeout(u),u=setTimeout(k(R),0);else u||=setTimeout(k(R),1e4)}function Ft(){let t=0,e=200;while(t<a.length&&t<50){if(e+=it(a[t])+1,e>30720)break;t++}return a.splice(0,t||1)}function R(){return clearTimeout(u),u=void 0,Y??=Ut().then((t)=>{if(Y=null,t)Z();return t}),Y}async function Ut(){if(E||!g()||!a.length)return!1;h=Ft();let t=b;b=0;let e=0;try{let i=new AbortController,r=setTimeout(()=>i.abort(),1e4);try{let s=await fetch(bt,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({api_key:yt,sent_at:new Date().toISOString(),lib:{name:"@datacub/react-native",version:St},...V?{app_id:V}:{},events:h,...t?{dropped:t}:{}}),signal:i.signal}),o=s.status;if(o===401||o===403)E=!0,l(`ingestion refused this app (${o}); sending stopped`);else if(o===408||o===429||o>499)e=Math.min(+(s.headers.get("Retry-After")||0),3600)*1000||-1;else if(N=0,o>299)b+=h.length+t;else if((await s.json().catch(()=>0)).directives?.includes("rotate_anon_id"))at()}finally{clearTimeout(r)}}catch{e=-1}let n=h;if(h=[],e&&g()&&!E){if(a=n.concat(a),b+=t,ot(),++N<10&&_)u=setTimeout(k(R),e>0?e:Math.random()*Math.min(1000*2**N,300000))}if(g())v();else if(c==="denied")_t();return!e&&!E}async function Lt(){await ht,N=0;while(a.length&&await R());await Q()}function Mt(t){if(t==="active"){if(_)return;if(_=!0,N=0,w&&g()&&(U||kt(nt())))st(U?wt:{$resumed:!0});if(a.length)Z()}else if(t==="background"||t==="inactive"){if(_=!1,clearTimeout(u),u=void 0,et){if(v(!0),a.length&&g())R()}}}function Jt(){c="not_required",d||=j(),v()}function Zt(t={}){if(c==="granted")return;if(c="granted",L=!1,!d)d=j();let e=typeof t.policyVersion==="string"?z(t.policyVersion,64):null;if(q!==(e??""))q=e??"",J("$consent",{$state:"granted",$method:/^(?:banner|settings|api|cmp)$/.test(`${t.method}`)?t.method:"api",$policy_version:e,$purposes:["analytics"]});if(O)$t(...O);if(O=null,w)st({});v(),Z()}function Bt(){c="denied",L=!0,clearTimeout(u),u=void 0,a=[],h=[],d=m="",p=P=O=q=null,_t()}function $t(t,e,n){if(p&&p!==t)at();if(P=e,p!==t)p=t,n.$anon_id=d;for(let i in n)return J(n.$anon_id?"$identify":"$set",n);v()}function Gt(t,e){let n=[d,m],i=D(t,n),r=e?.account==null?null:D(e.account,n);if(!i||e?.account!=null&&!r)return l("identify: ID refused (personal data shape or placeholder)");let s=rt(e);delete s.account;for(let o of["email","name","phone"])if(o in s){let x=e[o];if(typeof x==="string"&&x.length<=256)s[`$${o}`]=x;delete s[o]}if(g())$t(i,r,s);else if(c==="pending")O=[i,r,s]}function at(){if(O=null,!g())return;d=j(),p=P=null,m="",v()}function Kt(t,e={}){if(pt||typeof t!=="string")return;if(/^sk_/.test(t))return console.error("[datacub] refused a secret key. Use a pk_ key.");let n=(e.apiHost||"https://in.datacub.to").replace(/\/+$/,"");if(!/^pk_(?:live|test)_[A-Za-z0-9]{24,48}$/.test(t)||/^[a-z]+:\/\/[^/]*@/i.test(n)||!/^https:\/\/|^http:\/\/(?:localhost|127\.\d+\.\d+\.\d+|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(?:1[6-9]|2\d|3[01])\.\d+\.\d+)[:/]/.test(`${n}/`))return l("init: expected a pk_live_ or pk_test_ key and an https apiHost");if(y.OS!=="ios"&&y.OS!=="android")return l(`init: ${y.OS} is not supported; on the web use @datacub/web`);pt=!0,yt=t,bt=`${n}/v1/batch`,T=e.storage,K=e.requireConsent===!0;let i=e.app?.applicationId;if(V=typeof i==="string"&&/^[A-Za-z0-9_.-]{1,155}$/.test(i)?i:null,!V)l("init: no app id. Pass app: Application from expo-application, or { applicationId }");H=Rt(e.app);let r=dt.currentState;_=r!=="background"&&r!=="inactive",dt.addEventListener("change",k(Mt)),ht=jt().catch(()=>{}).then(()=>{if(et=!0,L)c="denied";else if(!K)Jt();for(let[s,o]of X.splice(0))vt(s,o);if(c==="pending"&&K)l("consent pending: nothing is stored or sent until datacub.consent.grant()")})}var Yt={track:zt,screen:Vt,identify:Gt,reset:at,grant:Zt,revoke:Bt};function vt(t,e){try{Yt[t]?.(...e)}catch{}}var I=(t)=>k((...e)=>{if(et)vt(t,e);else if(X.length<100||t==="grant"||t==="revoke"||t==="reset")X.push([t,e])}),Ht={init:k(Kt),track:I("track"),screen:I("screen"),identify:I("identify"),reset:I("reset"),flush:()=>Lt().catch(()=>{}),consent:{grant:I("grant"),revoke:I("revoke")}},ee=Ht;export{St as VERSION,ee as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var{defineProperty:i,getOwnPropertyNames:c,getOwnPropertyDescriptor:u}=Object,s=Object.prototype.hasOwnProperty;function f(e){return this[e]}var g=(e)=>{var t=(o??=new WeakMap).get(e),a;if(t)return t;if(t=i({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of c(e))if(!s.call(t,n))i(t,n,{get:f.bind(e,n),enumerable:!(a=u(e,n))||a.enumerable})}return o.set(e,t),t},o;var l=(e)=>e;function v(e,t){this[e]=l.bind(null,t)}var R=(e,t)=>{for(var a in t)i(e,a,{get:t[a],enumerable:!0,configurable:!0,set:v.bind(t,a)})};var p={};R(p,{trackNavigation:()=>m});module.exports=g(p);var r=require("./index.cjs"),d=r&&r.__esModule?r.default:r;function m(e){let t=()=>{try{let a=e.isReady()?e.getCurrentRoute():void 0;if(a)d.screen(a.name)}catch{}};t();try{return e.addListener("state",t)}catch{return()=>{}}}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface NavigationRef {
|
|
2
|
+
isReady(): boolean;
|
|
3
|
+
getCurrentRoute(): {
|
|
4
|
+
name: string;
|
|
5
|
+
} | undefined;
|
|
6
|
+
addListener(event: 'state', callback: () => void): () => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Sends a screen view for each route change; call it from the container's onReady so the first
|
|
10
|
+
* screen counts. Returns the unsubscribe function.
|
|
11
|
+
*/
|
|
12
|
+
export declare function trackNavigation(ref: NavigationRef): () => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface NavigationRef {
|
|
2
|
+
isReady(): boolean;
|
|
3
|
+
getCurrentRoute(): {
|
|
4
|
+
name: string;
|
|
5
|
+
} | undefined;
|
|
6
|
+
addListener(event: 'state', callback: () => void): () => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Sends a screen view for each route change; call it from the container's onReady so the first
|
|
10
|
+
* screen counts. Returns the unsubscribe function.
|
|
11
|
+
*/
|
|
12
|
+
export declare function trackNavigation(ref: NavigationRef): () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import a from"./index.mjs";function r(t){let e=()=>{try{let n=t.isReady()?t.getCurrentRoute():void 0;if(n)a.screen(n.name)}catch{}};e();try{return t.addListener("state",e)}catch{return()=>{}}}export{r as trackNavigation};
|
package/package.json
CHANGED
|
@@ -1,6 +1,94 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datacub/react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "datacub product analytics for React Native and Expo. Pure JavaScript, no device identifiers. Beta.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"analytics",
|
|
7
|
+
"product-analytics",
|
|
8
|
+
"react-native",
|
|
9
|
+
"expo",
|
|
10
|
+
"datacub",
|
|
11
|
+
"arabic"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://docs.datacub.to",
|
|
14
|
+
"bugs": "https://github.com/datacub/sdk/issues",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/datacub/sdk.git",
|
|
18
|
+
"directory": "packages/react-native"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
|
+
"module": "./dist/index.mjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"react-native": {
|
|
29
|
+
"types": "./dist/index.d.cts",
|
|
30
|
+
"default": "./dist/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.mjs"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/index.d.cts",
|
|
38
|
+
"default": "./dist/index.cjs"
|
|
39
|
+
},
|
|
40
|
+
"default": "./dist/index.cjs"
|
|
41
|
+
},
|
|
42
|
+
"./navigation": {
|
|
43
|
+
"react-native": {
|
|
44
|
+
"types": "./dist/navigation.d.cts",
|
|
45
|
+
"default": "./dist/navigation.cjs"
|
|
46
|
+
},
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/navigation.d.ts",
|
|
49
|
+
"default": "./dist/navigation.mjs"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./dist/navigation.d.cts",
|
|
53
|
+
"default": "./dist/navigation.cjs"
|
|
54
|
+
},
|
|
55
|
+
"default": "./dist/navigation.cjs"
|
|
56
|
+
},
|
|
57
|
+
"./package.json": "./package.json"
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"dist",
|
|
61
|
+
"navigation",
|
|
62
|
+
"README.md",
|
|
63
|
+
"LICENSE",
|
|
64
|
+
"CHANGELOG.md"
|
|
65
|
+
],
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "bun scripts/build.ts",
|
|
68
|
+
"typecheck": "tsc -p .",
|
|
69
|
+
"test": "bun run build && bun test",
|
|
70
|
+
"test:hermes": "bun run build && bun test/hermes/run.ts",
|
|
71
|
+
"test:bundle": "bun run build && node test/metro/bundle.mjs && bun test/metro/hermes.ts",
|
|
72
|
+
"pack:check": "bun scripts/pack-check.ts"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"react-native": ">=0.75.0"
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@babel/core": "8.1.2",
|
|
79
|
+
"@babel/runtime": "8.1.2",
|
|
80
|
+
"@react-native/babel-preset": "0.88.1",
|
|
81
|
+
"@react-native/metro-config": "0.88.1",
|
|
82
|
+
"hermes-compiler": "260318099.0.8",
|
|
83
|
+
"metro": "0.88.0",
|
|
84
|
+
"react": "19.3.1",
|
|
85
|
+
"react-native": "0.88.1",
|
|
86
|
+
"zod": "4.6.7"
|
|
87
|
+
},
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"access": "public",
|
|
90
|
+
"provenance": true,
|
|
91
|
+
"tag": "next"
|
|
92
|
+
},
|
|
93
|
+
"author": "datacub (https://datacub.to)"
|
|
94
|
+
}
|