sdk-sample 0.0.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/dist/components/trackedButton/index.d.ts +1 -0
- package/dist/components/trackedButton/tracked-button.d.ts +13 -0
- package/dist/components/trackedForm/index.d.ts +1 -0
- package/dist/components/trackedForm/tracked-form.d.ts +11 -0
- package/dist/components/trackedPage/index.d.ts +1 -0
- package/dist/components/trackedPage/tracked-page.d.ts +10 -0
- package/dist/index.d.ts +11 -0
- package/dist/sdk/event-manager.d.ts +11 -0
- package/dist/sdk/queue-manager.d.ts +21 -0
- package/dist/sdk/react-hooks.d.ts +36 -0
- package/dist/sdk/schema-manager.d.ts +33 -0
- package/dist/sdk/strategy-manager.d.ts +14 -0
- package/dist/sdk/tracker.d.ts +41 -0
- package/dist/sdk-sample.js +1060 -0
- package/dist/sdk-sample.umd.cjs +30 -0
- package/dist/types/index.d.ts +74 -0
- package/package.json +41 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
(function(p,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],g):(p=typeof globalThis<"u"?globalThis:p||self,g(p.SDK={},p.React))})(this,function(p,g){"use strict";var jr=Object.defineProperty;var xr=(p,g,j)=>g in p?jr(p,g,{enumerable:!0,configurable:!0,writable:!0,value:j}):p[g]=j;var _=(p,g,j)=>xr(p,typeof g!="symbol"?g+"":g,j);class j{getBaseInfo(){return{timestamp:Date.now(),url:window.location.href,userAgent:navigator.userAgent}}createEvent(t,a){return{eventName:t,...this.getBaseInfo(),...a}}}class ne{constructor(t,a=5,o=2e3){_(this,"queue",[]);_(this,"strategyManager");_(this,"batchSize");_(this,"timer",null);_(this,"interval");this.strategyManager=t,this.batchSize=a,this.interval=o}addEvent(t,a=!1){if(a){this.strategyManager.send([t],"xhr");return}this.queue.push(t),this.queue.length>=this.batchSize?this.flush():this.timer||(this.timer=window.setTimeout(()=>{this.flush()},this.interval))}flush(){if(this.queue.length===0)return;const t=[...this.queue];this.queue=[],this.timer&&(clearTimeout(this.timer),this.timer=null),this.strategyManager.send(t,"xhr")}flushOnUnload(){this.queue.length!==0&&(this.strategyManager.send(this.queue,"beacon"),this.queue=[])}}class ae{constructor(t){_(this,"endpoint");this.endpoint=t}send(t,a="xhr"){const o=JSON.stringify(t);switch(a){case"beacon":this.sendBeacon(o);break;case"img":this.sendImg(t);break;case"xhr":default:this.sendXHR(o);break}}sendBeacon(t){if(navigator.sendBeacon){const a=new Blob([t],{type:"application/json"});navigator.sendBeacon(this.endpoint,a)}else this.sendXHR(t)}sendXHR(t){const a=new XMLHttpRequest;a.open("POST",this.endpoint,!0),a.setRequestHeader("Content-Type","application/json"),a.send(t)}sendImg(t){const a=new URLSearchParams(t).toString(),o=new Image;o.src=`${this.endpoint}?${a}`}}const Ue={version:"1.0.0",events:{pageView:{priority:"low",params:{pageTitle:{type:"string"},referrer:{type:"string"}}},pageStay:{priority:"low",params:{duration:{type:"number"},scrollDepth:{type:"number"}}},exposure:{priority:"low",params:{componentId:{type:"string"},componentName:{type:"string"},duration:{type:"number"}}},buttonClick:{priority:"medium",params:{buttonId:{type:"string"},buttonText:{type:"string"},pageUrl:{type:"string"},extra:{type:"object"}}},formSubmit:{priority:"medium",params:{formId:{type:"string"},formData:{type:"object"}}},purchase:{priority:"high",params:{orderId:{type:"string"},amount:{type:"number"},currency:{type:"string"},items:{type:"array"}}},performance:{priority:"low",params:{fcp:{type:"number"},lcp:{type:"number"},ttfb:{type:"number"}}},error:{priority:"high",params:{message:{type:"string"},stack:{type:"string"},filename:{type:"string"},lineno:{type:"number"},colno:{type:"number"}}}}};class ie{constructor(t){_(this,"schema",Ue);t&&this.loadConfig(t)}loadConfig(t){console.log(`[SchemaManager] Loading config version ${t.version}`),this.schema={version:t.version,events:{...this.schema.events,...t.events}}}validate(t,a={}){const o=this.schema.events[t];if(!o)return{valid:!1,errors:[`Event '${t}' is not defined in the schema.`]};const f=[];for(const[b,m]of Object.entries(o.params)){const v=a[b];if(m.required&&v==null){f.push(`Missing required parameter: '${b}'`);continue}if(v!==void 0){const h=this.getType(v);h!==m.type&&m.type!=="object"&&f.push(`Parameter '${b}' expected type '${m.type}' but got '${h}'`)}}return{valid:f.length===0,errors:f}}getEventPriority(t){var a;return((a=this.schema.events[t])==null?void 0:a.priority)||"low"}getType(t){return Array.isArray(t)?"array":typeof t}}class oe{constructor(t){_(this,"eventManager");_(this,"queueManager");_(this,"strategyManager");_(this,"schemaManager");_(this,"isInitialized",!1);_(this,"debug",!1);this.eventManager=new j,this.strategyManager=new ae(t.endpoint),this.queueManager=new ne(this.strategyManager),this.schemaManager=new ie,this.debug=!!t.debug,t.autoTrack&&this.initAutoTracking(),this.setupUnload(),this.isInitialized=!0}safeRun(t){try{t()}catch(a){if(this.debug)throw console.error("[Tracker SDK Error]",a),a;console.warn("[Tracker SDK] Suppressed Error:",a)}}loadSchema(t){this.schemaManager.loadConfig(t)}trackEvent(t,a,o){this.safeRun(()=>{if(!this.isInitialized){this.debug&&console.warn("Tracker not initialized");return}const f=this.schemaManager.validate(t,a);if(!f.valid){const v=`[Validation Fail] Event '${t}': ${f.errors.join("; ")}`;if(this.debug)throw new Error(v);console.warn(v);return}const b=this.eventManager.createEvent(t,a);let m=o;m===void 0&&(m=this.schemaManager.getEventPriority(t)==="high"),this.queueManager.addEvent(b,m)})}initAutoTracking(){this.safeRun(()=>{this.trackPageView(),this.trackClicks(),this.trackErrors(),this.trackPerformance()})}trackPageView(){this.trackEvent("pageView",{pageTitle:document.title,referrer:document.referrer})}trackClicks(){window.addEventListener("click",t=>{this.safeRun(()=>{const o=t.target.closest("[data-event]");if(o){const f=o.getAttribute("id")||o.getAttribute("data-event")||"unknown",b=o.innerText||"";this.trackEvent("buttonClick",{buttonId:f,buttonText:b,pageUrl:window.location.href})}})},!0)}trackErrors(){window.addEventListener("error",t=>{this.safeRun(()=>{this.trackEvent("error",{message:t.message,filename:t.filename,lineno:t.lineno,colno:t.colno})})}),window.addEventListener("unhandledrejection",t=>{this.safeRun(()=>{this.trackEvent("error",{message:`Unhandled Promise Rejection: ${t.reason}`})})})}trackPerformance(){"PerformanceObserver"in window&&(new PerformanceObserver(o=>{for(const f of o.getEntries())f.name}).observe({type:"paint",buffered:!0}),new PerformanceObserver(o=>{o.getEntries().length>0}).observe({type:"largest-contentful-paint",buffered:!0})),window.addEventListener("load",()=>{this.safeRun(()=>{const t=performance.getEntriesByType("navigation")[0];t&&this.trackEvent("performance",{fcp:0,lcp:0,ttfb:t.responseStart-t.requestStart})})})}setupUnload(){window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.queueManager.flushOnUnload()})}}var J={exports:{}},L={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var se;function Le(){if(se)return L;se=1;var l=g,t=Symbol.for("react.element"),a=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,f=l.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,b={key:!0,ref:!0,__self:!0,__source:!0};function m(v,h,S){var w,O={},x=null,q=null;S!==void 0&&(x=""+S),h.key!==void 0&&(x=""+h.key),h.ref!==void 0&&(q=h.ref);for(w in h)o.call(h,w)&&!b.hasOwnProperty(w)&&(O[w]=h[w]);if(v&&v.defaultProps)for(w in h=v.defaultProps,h)O[w]===void 0&&(O[w]=h[w]);return{$$typeof:t,type:v,key:x,ref:q,props:O,_owner:f.current}}return L.Fragment=a,L.jsx=m,L.jsxs=m,L}var V={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var ue;function Ve(){return ue||(ue=1,process.env.NODE_ENV!=="production"&&function(){var l=g,t=Symbol.for("react.element"),a=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),f=Symbol.for("react.strict_mode"),b=Symbol.for("react.profiler"),m=Symbol.for("react.provider"),v=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),w=Symbol.for("react.suspense_list"),O=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),q=Symbol.for("react.offscreen"),fe=Symbol.iterator,Ke="@@iterator";function Je(e){if(e===null||typeof e!="object")return null;var r=fe&&e[fe]||e[Ke];return typeof r=="function"?r:null}var A=l.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function R(e){{for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];Ne("error",e,n)}}function Ne(e,r,n){{var i=A.ReactDebugCurrentFrame,c=i.getStackAddendum();c!==""&&(r+="%s",n=n.concat([c]));var d=n.map(function(u){return String(u)});d.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,d)}}var Xe=!1,Ge=!1,Qe=!1,Ze=!1,er=!1,de;de=Symbol.for("react.module.reference");function rr(e){return!!(typeof e=="string"||typeof e=="function"||e===o||e===b||er||e===f||e===S||e===w||Ze||e===q||Xe||Ge||Qe||typeof e=="object"&&e!==null&&(e.$$typeof===x||e.$$typeof===O||e.$$typeof===m||e.$$typeof===v||e.$$typeof===h||e.$$typeof===de||e.getModuleId!==void 0))}function tr(e,r,n){var i=e.displayName;if(i)return i;var c=r.displayName||r.name||"";return c!==""?n+"("+c+")":n}function pe(e){return e.displayName||"Context"}function C(e){if(e==null)return null;if(typeof e.tag=="number"&&R("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case o:return"Fragment";case a:return"Portal";case b:return"Profiler";case f:return"StrictMode";case S:return"Suspense";case w:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case v:var r=e;return pe(r)+".Consumer";case m:var n=e;return pe(n._context)+".Provider";case h:return tr(e,e.render,"ForwardRef");case O:var i=e.displayName||null;return i!==null?i:C(e.type)||"Memo";case x:{var c=e,d=c._payload,u=c._init;try{return C(u(d))}catch{return null}}}return null}var D=Object.assign,W=0,ve,he,ge,me,ye,be,Ee;function we(){}we.__reactDisabledLog=!0;function nr(){{if(W===0){ve=console.log,he=console.info,ge=console.warn,me=console.error,ye=console.group,be=console.groupCollapsed,Ee=console.groupEnd;var e={configurable:!0,enumerable:!0,value:we,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}W++}}function ar(){{if(W--,W===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:ve}),info:D({},e,{value:he}),warn:D({},e,{value:ge}),error:D({},e,{value:me}),group:D({},e,{value:ye}),groupCollapsed:D({},e,{value:be}),groupEnd:D({},e,{value:Ee})})}W<0&&R("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var N=A.ReactCurrentDispatcher,X;function $(e,r,n){{if(X===void 0)try{throw Error()}catch(c){var i=c.stack.trim().match(/\n( *(at )?)/);X=i&&i[1]||""}return`
|
|
18
|
+
`+X+e}}var G=!1,z;{var ir=typeof WeakMap=="function"?WeakMap:Map;z=new ir}function Re(e,r){if(!e||G)return"";{var n=z.get(e);if(n!==void 0)return n}var i;G=!0;var c=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var d;d=N.current,N.current=null,nr();try{if(r){var u=function(){throw Error()};if(Object.defineProperty(u.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(u,[])}catch(k){i=k}Reflect.construct(e,[],u)}else{try{u.call()}catch(k){i=k}e.call(u.prototype)}}else{try{throw Error()}catch(k){i=k}e()}}catch(k){if(k&&i&&typeof k.stack=="string"){for(var s=k.stack.split(`
|
|
19
|
+
`),T=i.stack.split(`
|
|
20
|
+
`),y=s.length-1,E=T.length-1;y>=1&&E>=0&&s[y]!==T[E];)E--;for(;y>=1&&E>=0;y--,E--)if(s[y]!==T[E]){if(y!==1||E!==1)do if(y--,E--,E<0||s[y]!==T[E]){var P=`
|
|
21
|
+
`+s[y].replace(" at new "," at ");return e.displayName&&P.includes("<anonymous>")&&(P=P.replace("<anonymous>",e.displayName)),typeof e=="function"&&z.set(e,P),P}while(y>=1&&E>=0);break}}}finally{G=!1,N.current=d,ar(),Error.prepareStackTrace=c}var U=e?e.displayName||e.name:"",M=U?$(U):"";return typeof e=="function"&&z.set(e,M),M}function or(e,r,n){return Re(e,!1)}function sr(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function H(e,r,n){if(e==null)return"";if(typeof e=="function")return Re(e,sr(e));if(typeof e=="string")return $(e);switch(e){case S:return $("Suspense");case w:return $("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case h:return or(e.render);case O:return H(e.type,r,n);case x:{var i=e,c=i._payload,d=i._init;try{return H(d(c),r,n)}catch{}}}return""}var B=Object.prototype.hasOwnProperty,Te={},ke=A.ReactDebugCurrentFrame;function K(e){if(e){var r=e._owner,n=H(e.type,e._source,r?r.type:null);ke.setExtraStackFrame(n)}else ke.setExtraStackFrame(null)}function ur(e,r,n,i,c){{var d=Function.call.bind(B);for(var u in e)if(d(e,u)){var s=void 0;try{if(typeof e[u]!="function"){var T=Error((i||"React class")+": "+n+" type `"+u+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[u]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw T.name="Invariant Violation",T}s=e[u](r,u,i,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(y){s=y}s&&!(s instanceof Error)&&(K(c),R("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",i||"React class",n,u,typeof s),K(null)),s instanceof Error&&!(s.message in Te)&&(Te[s.message]=!0,K(c),R("Failed %s type: %s",n,s.message),K(null))}}}var cr=Array.isArray;function Q(e){return cr(e)}function lr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,n=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n}}function fr(e){try{return _e(e),!1}catch{return!0}}function _e(e){return""+e}function Se(e){if(fr(e))return R("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",lr(e)),_e(e)}var Pe=A.ReactCurrentOwner,dr={key:!0,ref:!0,__self:!0,__source:!0},Oe,Ce;function pr(e){if(B.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function vr(e){if(B.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function hr(e,r){typeof e.ref=="string"&&Pe.current}function gr(e,r){{var n=function(){Oe||(Oe=!0,R("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}}function mr(e,r){{var n=function(){Ce||(Ce=!0,R("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}}var yr=function(e,r,n,i,c,d,u){var s={$$typeof:t,type:e,key:r,ref:n,props:u,_owner:d};return s._store={},Object.defineProperty(s._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(s,"_self",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.defineProperty(s,"_source",{configurable:!1,enumerable:!1,writable:!1,value:c}),Object.freeze&&(Object.freeze(s.props),Object.freeze(s)),s};function br(e,r,n,i,c){{var d,u={},s=null,T=null;n!==void 0&&(Se(n),s=""+n),vr(r)&&(Se(r.key),s=""+r.key),pr(r)&&(T=r.ref,hr(r,c));for(d in r)B.call(r,d)&&!dr.hasOwnProperty(d)&&(u[d]=r[d]);if(e&&e.defaultProps){var y=e.defaultProps;for(d in y)u[d]===void 0&&(u[d]=y[d])}if(s||T){var E=typeof e=="function"?e.displayName||e.name||"Unknown":e;s&&gr(u,E),T&&mr(u,E)}return yr(e,s,T,c,i,Pe.current,u)}}var Z=A.ReactCurrentOwner,je=A.ReactDebugCurrentFrame;function F(e){if(e){var r=e._owner,n=H(e.type,e._source,r?r.type:null);je.setExtraStackFrame(n)}else je.setExtraStackFrame(null)}var ee;ee=!1;function re(e){return typeof e=="object"&&e!==null&&e.$$typeof===t}function xe(){{if(Z.current){var e=C(Z.current.type);if(e)return`
|
|
22
|
+
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function Er(e){return""}var De={};function wr(e){{var r=xe();if(!r){var n=typeof e=="string"?e:e.displayName||e.name;n&&(r=`
|
|
24
|
+
|
|
25
|
+
Check the top-level render call using <`+n+">.")}return r}}function Me(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var n=wr(r);if(De[n])return;De[n]=!0;var i="";e&&e._owner&&e._owner!==Z.current&&(i=" It was passed a child from "+C(e._owner.type)+"."),F(e),R('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,i),F(null)}}function Ie(e,r){{if(typeof e!="object")return;if(Q(e))for(var n=0;n<e.length;n++){var i=e[n];re(i)&&Me(i,r)}else if(re(e))e._store&&(e._store.validated=!0);else if(e){var c=Je(e);if(typeof c=="function"&&c!==e.entries)for(var d=c.call(e),u;!(u=d.next()).done;)re(u.value)&&Me(u.value,r)}}}function Rr(e){{var r=e.type;if(r==null||typeof r=="string")return;var n;if(typeof r=="function")n=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===h||r.$$typeof===O))n=r.propTypes;else return;if(n){var i=C(r);ur(n,e.props,"prop",i,e)}else if(r.PropTypes!==void 0&&!ee){ee=!0;var c=C(r);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",c||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&R("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Tr(e){{for(var r=Object.keys(e.props),n=0;n<r.length;n++){var i=r[n];if(i!=="children"&&i!=="key"){F(e),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",i),F(null);break}}e.ref!==null&&(F(e),R("Invalid attribute `ref` supplied to `React.Fragment`."),F(null))}}var Ae={};function Fe(e,r,n,i,c,d){{var u=rr(e);if(!u){var s="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(s+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var T=Er();T?s+=T:s+=xe();var y;e===null?y="null":Q(e)?y="array":e!==void 0&&e.$$typeof===t?(y="<"+(C(e.type)||"Unknown")+" />",s=" Did you accidentally export a JSX literal instead of a component?"):y=typeof e,R("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",y,s)}var E=br(e,r,n,c,d);if(E==null)return E;if(u){var P=r.children;if(P!==void 0)if(i)if(Q(P)){for(var U=0;U<P.length;U++)Ie(P[U],e);Object.freeze&&Object.freeze(P)}else R("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ie(P,e)}if(B.call(r,"key")){var M=C(e),k=Object.keys(r).filter(function(Cr){return Cr!=="key"}),te=k.length>0?"{key: someKey, "+k.join(": ..., ")+": ...}":"{key: someKey}";if(!Ae[M+te]){var Or=k.length>0?"{"+k.join(": ..., ")+": ...}":"{}";R(`A props object containing a "key" prop is being spread into JSX:
|
|
26
|
+
let props = %s;
|
|
27
|
+
<%s {...props} />
|
|
28
|
+
React keys must be passed directly to JSX without using spread:
|
|
29
|
+
let props = %s;
|
|
30
|
+
<%s key={someKey} {...props} />`,te,M,Or,M),Ae[M+te]=!0}}return e===o?Tr(E):Rr(E),E}}function kr(e,r,n){return Fe(e,r,n,!0)}function _r(e,r,n){return Fe(e,r,n,!1)}var Sr=_r,Pr=kr;V.Fragment=o,V.jsx=Sr,V.jsxs=Pr}()),V}process.env.NODE_ENV==="production"?J.exports=Le():J.exports=Ve();var Y=J.exports;const ce=g.createContext(null),Ye=({config:l,children:t})=>{const a=g.useRef(null);return a.current||(a.current=new oe(l)),Y.jsx(ce.Provider,{value:a.current,children:t})},I=()=>{const l=g.useContext(ce);if(!l)throw new Error("useTracker must be used within a TrackerProvider");return l},le=l=>{const t=I();g.useEffect(()=>{t.trackEvent("pageView",{pageTitle:l||document.title,referrer:document.referrer})},[t,l])},We=()=>{const l=I(),t=g.useRef(Date.now());g.useEffect(()=>(t.current=Date.now(),()=>{const a=Date.now()-t.current,o=Math.round((window.scrollY+window.innerHeight)/document.body.scrollHeight*100);l.trackEvent("pageStay",{duration:a,scrollDepth:o})}),[l])},Be=(l,t)=>{const a=I(),o=g.useRef(null),f=g.useRef(null);return g.useEffect(()=>{const b=o.current;if(!b)return;const m=new IntersectionObserver(v=>{v.forEach(h=>{if(h.isIntersecting)f.current=Date.now();else if(f.current){const S=Date.now()-f.current;a.trackEvent("exposure",{componentId:l,componentName:t,duration:S}),f.current=null}})},{threshold:.5});return m.observe(b),()=>{if(m.disconnect(),f.current){const v=Date.now()-f.current;a.trackEvent("exposure",{componentId:l,componentName:t,duration:v})}}},[a,l,t]),o},qe=({eventId:l,buttonName:t,extraParams:a,children:o,onClick:f,...b})=>{const m=I(),v=h=>{m.trackEvent("buttonClick",{buttonId:l||b.id||"unknown-btn",buttonText:t,pageUrl:window.location.href,extra:a}),f&&f(h)};return Y.jsx("button",{onClick:v,...b,children:o})},$e=({pageTitle:l,children:t})=>(le(l),Y.jsx(Y.Fragment,{children:t})),ze=({formId:l,children:t,onSubmit:a,transformData:o,...f})=>{const b=I(),m=v=>{v.preventDefault();const h=new FormData(v.currentTarget),S={};o?Object.assign(S,o(h)):h.forEach((w,O)=>{S[O]=w.toString()}),b.trackEvent("formSubmit",{formId:l,formData:S}),a&&a(v)};return Y.jsx("form",{onSubmit:m,...f,children:t})},He={pageView:{priority:"low",params:["pageTitle","referrer"]},pageStay:{priority:"low",params:["duration","scrollDepth"]},exposure:{priority:"low",params:["componentId","componentName","duration"]},buttonClick:{priority:"medium",params:["buttonId","buttonText","pageUrl","extra"]},formSubmit:{priority:"medium",params:["formId","formData"]},purchase:{priority:"high",params:["orderId","amount","currency","items"]},performance:{priority:"low",params:["fcp","lcp","ttfb"]},error:{priority:"high",params:["message","stack","filename","lineno","colno"]}};p.EventManager=j,p.EventSchema=He,p.QueueManager=ne,p.SchemaManager=ie,p.StrategyManager=ae,p.TrackedButton=qe,p.TrackedForm=ze,p.TrackedPage=$e,p.Tracker=oe,p.TrackerProvider=Ye,p.useExposure=Be,p.usePageStay=We,p.usePageView=le,p.useTracker=I,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export declare const EventSchema: {
|
|
2
|
+
readonly pageView: {
|
|
3
|
+
readonly priority: "low";
|
|
4
|
+
readonly params: readonly ["pageTitle", "referrer"];
|
|
5
|
+
};
|
|
6
|
+
readonly pageStay: {
|
|
7
|
+
readonly priority: "low";
|
|
8
|
+
readonly params: readonly ["duration", "scrollDepth"];
|
|
9
|
+
};
|
|
10
|
+
readonly exposure: {
|
|
11
|
+
readonly priority: "low";
|
|
12
|
+
readonly params: readonly ["componentId", "componentName", "duration"];
|
|
13
|
+
};
|
|
14
|
+
readonly buttonClick: {
|
|
15
|
+
readonly priority: "medium";
|
|
16
|
+
readonly params: readonly ["buttonId", "buttonText", "pageUrl", "extra"];
|
|
17
|
+
};
|
|
18
|
+
readonly formSubmit: {
|
|
19
|
+
readonly priority: "medium";
|
|
20
|
+
readonly params: readonly ["formId", "formData"];
|
|
21
|
+
};
|
|
22
|
+
readonly purchase: {
|
|
23
|
+
readonly priority: "high";
|
|
24
|
+
readonly params: readonly ["orderId", "amount", "currency", "items"];
|
|
25
|
+
};
|
|
26
|
+
readonly performance: {
|
|
27
|
+
readonly priority: "low";
|
|
28
|
+
readonly params: readonly ["fcp", "lcp", "ttfb"];
|
|
29
|
+
};
|
|
30
|
+
readonly error: {
|
|
31
|
+
readonly priority: "high";
|
|
32
|
+
readonly params: readonly ["message", "stack", "filename", "lineno", "colno"];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export interface ParamTypeMap {
|
|
36
|
+
pageTitle: string;
|
|
37
|
+
referrer: string;
|
|
38
|
+
duration: number;
|
|
39
|
+
scrollDepth: number;
|
|
40
|
+
componentId: string;
|
|
41
|
+
componentName: string;
|
|
42
|
+
buttonId?: string;
|
|
43
|
+
buttonText?: string;
|
|
44
|
+
extra?: Record<string, any>;
|
|
45
|
+
formId?: string;
|
|
46
|
+
formData?: Record<string, any>;
|
|
47
|
+
pageUrl: string;
|
|
48
|
+
orderId: string;
|
|
49
|
+
amount: number;
|
|
50
|
+
currency: string;
|
|
51
|
+
items: string[];
|
|
52
|
+
fcp: number;
|
|
53
|
+
lcp: number;
|
|
54
|
+
ttfb: number;
|
|
55
|
+
message: string;
|
|
56
|
+
stack?: string;
|
|
57
|
+
filename?: string;
|
|
58
|
+
lineno?: number;
|
|
59
|
+
colno?: number;
|
|
60
|
+
}
|
|
61
|
+
export type EventNames = keyof typeof EventSchema;
|
|
62
|
+
export type EventMap = {
|
|
63
|
+
[K in EventNames]: {
|
|
64
|
+
[P in typeof EventSchema[K]['params'][number]]: P extends keyof ParamTypeMap ? ParamTypeMap[P] : unknown;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export interface BaseEvent {
|
|
68
|
+
eventName: string;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
url: string;
|
|
71
|
+
userAgent: string;
|
|
72
|
+
[key: string]: unknown;
|
|
73
|
+
}
|
|
74
|
+
export type ReportStrategy = 'beacon' | 'xhr' | 'img';
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sdk-sample",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/sdk-sample.umd.cjs",
|
|
10
|
+
"module": "./dist/sdk-sample.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/sdk-sample.js",
|
|
15
|
+
"require": "./dist/sdk-sample.umd.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "vite",
|
|
20
|
+
"build": "vite build && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
21
|
+
"test": "vitest",
|
|
22
|
+
"preview": "vite preview"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": "^18.2.0",
|
|
26
|
+
"react-dom": "^18.2.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"react": "^18.2.0",
|
|
30
|
+
"react-dom": "^18.2.0",
|
|
31
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
32
|
+
"@testing-library/react": "^16.3.1",
|
|
33
|
+
"@types/react": "^18.2.66",
|
|
34
|
+
"@types/react-dom": "^18.2.22",
|
|
35
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
36
|
+
"jsdom": "^27.3.0",
|
|
37
|
+
"typescript": "^5.2.2",
|
|
38
|
+
"vite": "^5.2.0",
|
|
39
|
+
"vitest": "^4.0.16"
|
|
40
|
+
}
|
|
41
|
+
}
|