@eventvisor/react 0.4.0

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 ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [0.4.0](https://github.com/eventvisor/eventvisor/compare/v0.3.0...v0.4.0) (2025-10-02)
7
+
8
+
9
+ ### Features
10
+
11
+ * React SDK ([#6](https://github.com/eventvisor/eventvisor/issues/6)) ([886d2e9](https://github.com/eventvisor/eventvisor/commit/886d2e9d2626e9b7323d097bb005811743af611c))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Fahad Heylaal (https://fahad19.com)
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
13
+ all 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
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @eventvisor/react <!-- omit in toc -->
2
+
3
+ React components and hooks for Eventvisor.
4
+
5
+ Visit [https://eventvisor.org/docs/sdks/react/](https://eventvisor.org/docs/sdks/react/) for more information
6
+
7
+ ## License <!-- omit in toc -->
8
+
9
+ MIT © [Fahad Heylaal](https://fahad19.com)
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.EventvisorReactSDK=e(require("react")):t.EventvisorReactSDK=e(t.react)}(this,t=>(()=>{"use strict";var e={155:e=>{e.exports=t},882:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.EventvisorContext=void 0,e.EventvisorProvider=function(t){return n.createElement(e.EventvisorContext.Provider,{value:t.instance},t.children)},e.useInstance=o,e.isReady=function(){var t=o(),e=n.useState(t.isReady()),r=e[0],i=e[1];return n.useEffect(function(){t.onReady().then(function(){!1===r&&i(!0)})},[]),r},e.useEventvisor=function(){var t=o();return{instance:t,track:function(e,r){return t.track(e,r)},setAttribute:function(e,r){return t.setAttribute(e,r)},getAttributeValue:function(e){return t.getAttributeValue(e)},isAttributeSet:function(e){return t.isAttributeSet(e)},removeAttribute:function(e){return t.removeAttribute(e)}}};var n=r(155);function o(){return n.useContext(e.EventvisorContext)}e.EventvisorContext=n.createContext(void 0)}},r={};return function t(n){var o=r[n];if(void 0!==o)return o.exports;var i=r[n]={exports:{}};return e[n](i,i.exports,t),i.exports}(882)})());
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,UACR,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,CAAC,SAAUJ,GACQ,iBAAZC,QACdA,QAA4B,mBAAID,EAAQG,QAAQ,UAEhDJ,EAAyB,mBAAIC,EAAQD,EAAY,MAClD,CATD,CASGO,KAAOC,G,kCCTVL,EAAOD,QAAUM,C,4FCiBjB,8BAAmCC,GACjC,OACE,gBAAC,EAAAC,kBAAkBC,SAAQ,CAACC,MAAOH,EAAMI,UAAWJ,EAAMK,SAE9D,EAKA,gBAMA,qBACE,IAAMD,EAAWE,IACX,EAA4CC,EAAMC,SAASJ,EAASK,WAAnEC,EAAiB,KAAEC,EAAoB,KAU9C,OARAJ,EAAMK,UAAU,WACdR,EAASS,UAAUC,KAAK,YACI,IAAtBJ,GACFC,GAAqB,EAEzB,EACF,EAAG,IAEID,CACT,EAWA,2BACE,IAAMN,EAAWE,IAEjB,MAAO,CACLF,SAAQ,EACRW,MAAO,SAACC,EAAWb,GAAU,OAAAC,EAASW,MAAMC,EAAWb,EAA1B,EAC7Bc,aAAc,SAACC,EAAMf,GAAU,OAAAC,EAASa,aAAaC,EAAMf,EAA5B,EAC/BgB,kBAAmB,SAACD,GAAS,OAAAd,EAASe,kBAAkBD,EAA3B,EAC7BE,eAAgB,SAACF,GAAS,OAAAd,EAASgB,eAAeF,EAAxB,EAC1BG,gBAAiB,SAACH,GAAS,OAAAd,EAASiB,gBAAgBH,EAAzB,EAE/B,EAnEA,aA0BA,SAAgBZ,IAGd,OAFiBC,EAAMe,WAAW,EAAArB,kBAGpC,CAvBa,EAAAA,kBAAoBM,EAAMgB,mBAAsCC,E,GCNzEC,EAA2B,CAAC,E,OAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBH,IAAjBI,EACH,OAAOA,EAAanC,QAGrB,IAAIC,EAAS+B,EAAyBE,GAAY,CAGjDlC,QAAS,CAAC,GAOX,OAHAoC,EAAoBF,GAAUjC,EAAQA,EAAOD,QAASiC,GAG/ChC,EAAOD,OACf,CCnB0BiC,CAAoB,I","sources":["webpack://EventvisorReactSDK/webpack/universalModuleDefinition","webpack://EventvisorReactSDK/external umd \"react\"","webpack://EventvisorReactSDK/./src/index.tsx","webpack://EventvisorReactSDK/webpack/bootstrap","webpack://EventvisorReactSDK/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"react\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"react\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"EventvisorReactSDK\"] = factory(require(\"react\"));\n\telse\n\t\troot[\"EventvisorReactSDK\"] = factory(root[\"react\"]);\n})(this, (__WEBPACK_EXTERNAL_MODULE__155__) => {\nreturn ","module.exports = __WEBPACK_EXTERNAL_MODULE__155__;","import * as React from \"react\";\nimport { Eventvisor } from \"@eventvisor/sdk\";\nimport { EventName, AttributeName, Value } from \"@eventvisor/types\";\n\n/**\n * Context\n */\nexport const EventvisorContext = React.createContext<Eventvisor | undefined>(undefined);\n\n/**\n * Provider\n */\nexport interface EventvisorProviderProps {\n instance: Eventvisor;\n children?: React.ReactNode;\n}\n\nexport function EventvisorProvider(props: EventvisorProviderProps) {\n return (\n <EventvisorContext.Provider value={props.instance}>{props.children}</EventvisorContext.Provider>\n );\n}\n\n/**\n * Hooks\n */\nexport function useInstance(): Eventvisor {\n const instance = React.useContext(EventvisorContext);\n\n return instance;\n}\n\nexport function isReady(): boolean {\n const instance = useInstance();\n const [isEventvisorReady, setIsEventvisorReady] = React.useState(instance.isReady());\n\n React.useEffect(() => {\n instance.onReady().then(() => {\n if (isEventvisorReady === false) {\n setIsEventvisorReady(true);\n }\n });\n }, []);\n\n return isEventvisorReady;\n}\n\nexport interface UseEventvisor {\n instance: Eventvisor;\n track: (eventName: EventName, value: Value) => void;\n setAttribute: (name: AttributeName, value: Value) => void;\n getAttributeValue: (name: AttributeName) => Value | null;\n isAttributeSet: (name: AttributeName) => boolean;\n removeAttribute: (name: AttributeName) => void;\n}\n\nexport function useEventvisor(): UseEventvisor {\n const instance = useInstance();\n\n return {\n instance,\n track: (eventName, value) => instance.track(eventName, value),\n setAttribute: (name, value) => instance.setAttribute(name, value),\n getAttributeValue: (name) => instance.getAttributeValue(name),\n isAttributeSet: (name) => instance.isAttributeSet(name),\n removeAttribute: (name) => instance.removeAttribute(name),\n };\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(882);\n"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE__155__","props","EventvisorContext","Provider","value","instance","children","useInstance","React","useState","isReady","isEventvisorReady","setIsEventvisorReady","useEffect","onReady","then","track","eventName","setAttribute","name","getAttributeValue","isAttributeSet","removeAttribute","useContext","createContext","undefined","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import*as t from"react";var e={649:(e,r,n)=>{var o,s;e.exports=(o={createContext:()=>t.createContext,createElement:()=>t.createElement,useContext:()=>t.useContext,useEffect:()=>t.useEffect,useState:()=>t.useState},s={},n.d(s,o),s)}},r={};function n(t){var o=r[t];if(void 0!==o)return o.exports;var s=r[t]={exports:{}};return e[t](s,s.exports,n),s.exports}n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var o={};n.d(o,{F3:()=>u,Nj:()=>i,i_:()=>c,nb:()=>a,pL:()=>v});var s=n(649);const a=s.createContext(void 0);function u(t){return s.createElement(a.Provider,{value:t.instance},t.children)}function i(){return s.useContext(a)}function c(){const t=i(),[e,r]=s.useState(t.isReady());return s.useEffect(()=>{t.onReady().then(()=>{!1===e&&r(!0)})},[]),e}function v(){const t=i();return{instance:t,track:(e,r)=>t.track(e,r),setAttribute:(e,r)=>t.setAttribute(e,r),getAttributeValue:e=>t.getAttributeValue(e),isAttributeSet:e=>t.isAttributeSet(e),removeAttribute:e=>t.removeAttribute(e)}}const f=o.nb,b=o.F3,p=o.i_,x=o.pL,d=o.Nj;export{f as EventvisorContext,b as EventvisorProvider,p as isReady,x as useEventvisor,d as useInstance};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","mappings":"6CAAQ,IAACA,EACJC,EAGLC,EAAOC,SAJEH,EAIU,CAAE,cAAmB,IAAOI,EAA+C,cAAG,cAAmB,IAAOA,EAA+C,cAAG,WAAgB,IAAOA,EAA4C,WAAG,UAAe,IAAOA,EAA2C,UAAG,SAAc,IAAOA,EAA0C,UAHjXH,EAAI,CAAC,EAAGI,EAAoBC,EAAEL,EAAGD,GAAWC,E,GCA7CM,EAA2B,CAAC,EAGhC,SAASF,EAAoBG,GAE5B,IAAIC,EAAeF,EAAyBC,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaN,QAGrB,IAAID,EAASK,EAAyBC,GAAY,CAGjDL,QAAS,CAAC,GAOX,OAHAQ,EAAoBH,GAAUN,EAAQA,EAAOC,QAASE,GAG/CH,EAAOC,OACf,CCrBAE,EAAoBC,EAAI,CAACH,EAASS,KACjC,IAAI,IAAIC,KAAOD,EACXP,EAAoBS,EAAEF,EAAYC,KAASR,EAAoBS,EAAEX,EAASU,IAC5EE,OAAOC,eAAeb,EAASU,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3ER,EAAoBS,EAAI,CAACK,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,G,4ECO3E,MAAMI,EAAoB,qBAA4Cd,GAUtE,SAASe,EAAmBC,GACjC,OACE,gBAACF,EAAkBG,SAAQ,CAACC,MAAOF,EAAMG,UAAWH,EAAMI,SAE9D,CAKO,SAASC,IAGd,OAFiB,aAAiBP,EAGpC,CAEO,SAASQ,IACd,MAAMH,EAAWE,KACVE,EAAmBC,GAAwB,WAAeL,EAASG,WAU1E,OARA,YAAgB,KACdH,EAASM,UAAUC,KAAK,MACI,IAAtBH,GACFC,GAAqB,MAGxB,IAEID,CACT,CAWO,SAASI,IACd,MAAMR,EAAWE,IAEjB,MAAO,CACLF,WACAS,MAAO,CAACC,EAAWX,IAAUC,EAASS,MAAMC,EAAWX,GACvDY,aAAc,CAACC,EAAMb,IAAUC,EAASW,aAAaC,EAAMb,GAC3Dc,kBAAoBD,GAASZ,EAASa,kBAAkBD,GACxDE,eAAiBF,GAASZ,EAASc,eAAeF,GAClDG,gBAAkBH,GAASZ,EAASe,gBAAgBH,GAExD,C","sources":["webpack://@eventvisor/react/external module \"react\"","webpack://@eventvisor/react/webpack/bootstrap","webpack://@eventvisor/react/webpack/runtime/define property getters","webpack://@eventvisor/react/webpack/runtime/hasOwnProperty shorthand","webpack://@eventvisor/react/./src/index.tsx"],"sourcesContent":["var x = (y) => {\n\tvar x = {}; __webpack_require__.d(x, y); return x\n} \nvar y = (x) => (() => (x))\nmodule.exports = x({ [\"createContext\"]: () => (__WEBPACK_EXTERNAL_MODULE_react__.createContext), [\"createElement\"]: () => (__WEBPACK_EXTERNAL_MODULE_react__.createElement), [\"useContext\"]: () => (__WEBPACK_EXTERNAL_MODULE_react__.useContext), [\"useEffect\"]: () => (__WEBPACK_EXTERNAL_MODULE_react__.useEffect), [\"useState\"]: () => (__WEBPACK_EXTERNAL_MODULE_react__.useState) });","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import * as React from \"react\";\nimport { Eventvisor } from \"@eventvisor/sdk\";\nimport { EventName, AttributeName, Value } from \"@eventvisor/types\";\n\n/**\n * Context\n */\nexport const EventvisorContext = React.createContext<Eventvisor | undefined>(undefined);\n\n/**\n * Provider\n */\nexport interface EventvisorProviderProps {\n instance: Eventvisor;\n children?: React.ReactNode;\n}\n\nexport function EventvisorProvider(props: EventvisorProviderProps) {\n return (\n <EventvisorContext.Provider value={props.instance}>{props.children}</EventvisorContext.Provider>\n );\n}\n\n/**\n * Hooks\n */\nexport function useInstance(): Eventvisor {\n const instance = React.useContext(EventvisorContext);\n\n return instance;\n}\n\nexport function isReady(): boolean {\n const instance = useInstance();\n const [isEventvisorReady, setIsEventvisorReady] = React.useState(instance.isReady());\n\n React.useEffect(() => {\n instance.onReady().then(() => {\n if (isEventvisorReady === false) {\n setIsEventvisorReady(true);\n }\n });\n }, []);\n\n return isEventvisorReady;\n}\n\nexport interface UseEventvisor {\n instance: Eventvisor;\n track: (eventName: EventName, value: Value) => void;\n setAttribute: (name: AttributeName, value: Value) => void;\n getAttributeValue: (name: AttributeName) => Value | null;\n isAttributeSet: (name: AttributeName) => boolean;\n removeAttribute: (name: AttributeName) => void;\n}\n\nexport function useEventvisor(): UseEventvisor {\n const instance = useInstance();\n\n return {\n instance,\n track: (eventName, value) => instance.track(eventName, value),\n setAttribute: (name, value) => instance.setAttribute(name, value),\n getAttributeValue: (name) => instance.getAttributeValue(name),\n isAttributeSet: (name) => instance.isAttributeSet(name),\n removeAttribute: (name) => instance.removeAttribute(name),\n };\n}\n"],"names":["y","x","module","exports","__WEBPACK_EXTERNAL_MODULE_react__","__webpack_require__","d","__webpack_module_cache__","moduleId","cachedModule","undefined","__webpack_modules__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","EventvisorContext","EventvisorProvider","props","Provider","value","instance","children","useInstance","isReady","isEventvisorReady","setIsEventvisorReady","onReady","then","useEventvisor","track","eventName","setAttribute","name","getAttributeValue","isAttributeSet","removeAttribute"],"sourceRoot":""}
package/jest.config.js ADDED
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ preset: "ts-jest",
3
+ bail: true,
4
+
5
+ // for react testing library
6
+ testEnvironment: "jsdom",
7
+ setupFilesAfterEnv: [
8
+ // "@testing-library/jest-dom/extend-expect",
9
+ "./jest.setup.js",
10
+ ],
11
+ };
package/jest.setup.js ADDED
@@ -0,0 +1,4 @@
1
+ const { TextEncoder, TextDecoder } = require("util");
2
+
3
+ global.TextEncoder = TextEncoder;
4
+ global.TextDecoder = TextDecoder;
package/lib/index.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import * as React from "react";
2
+ import { Eventvisor } from "@eventvisor/sdk";
3
+ import { EventName, AttributeName, Value } from "@eventvisor/types";
4
+ /**
5
+ * Context
6
+ */
7
+ export declare const EventvisorContext: any;
8
+ /**
9
+ * Provider
10
+ */
11
+ export interface EventvisorProviderProps {
12
+ instance: Eventvisor;
13
+ children?: React.ReactNode;
14
+ }
15
+ export declare function EventvisorProvider(props: EventvisorProviderProps): any;
16
+ /**
17
+ * Hooks
18
+ */
19
+ export declare function useInstance(): Eventvisor;
20
+ export declare function isReady(): boolean;
21
+ export interface UseEventvisor {
22
+ instance: Eventvisor;
23
+ track: (eventName: EventName, value: Value) => void;
24
+ setAttribute: (name: AttributeName, value: Value) => void;
25
+ getAttributeValue: (name: AttributeName) => Value | null;
26
+ isAttributeSet: (name: AttributeName) => boolean;
27
+ removeAttribute: (name: AttributeName) => void;
28
+ }
29
+ export declare function useEventvisor(): UseEventvisor;
package/lib/index.js ADDED
@@ -0,0 +1,39 @@
1
+ import * as React from "react";
2
+ /**
3
+ * Context
4
+ */
5
+ export const EventvisorContext = React.createContext(undefined);
6
+ export function EventvisorProvider(props) {
7
+ return (React.createElement(EventvisorContext.Provider, { value: props.instance }, props.children));
8
+ }
9
+ /**
10
+ * Hooks
11
+ */
12
+ export function useInstance() {
13
+ const instance = React.useContext(EventvisorContext);
14
+ return instance;
15
+ }
16
+ export function isReady() {
17
+ const instance = useInstance();
18
+ const [isEventvisorReady, setIsEventvisorReady] = React.useState(instance.isReady());
19
+ React.useEffect(() => {
20
+ instance.onReady().then(() => {
21
+ if (isEventvisorReady === false) {
22
+ setIsEventvisorReady(true);
23
+ }
24
+ });
25
+ }, []);
26
+ return isEventvisorReady;
27
+ }
28
+ export function useEventvisor() {
29
+ const instance = useInstance();
30
+ return {
31
+ instance,
32
+ track: (eventName, value) => instance.track(eventName, value),
33
+ setAttribute: (name, value) => instance.setAttribute(name, value),
34
+ getAttributeValue: (name) => instance.getAttributeValue(name),
35
+ isAttributeSet: (name) => instance.isAttributeSet(name),
36
+ removeAttribute: (name) => instance.removeAttribute(name),
37
+ };
38
+ }
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC,aAAa,CAAyB,SAAS,CAAC,CAAC;AAUxF,MAAM,UAAU,kBAAkB,CAAC,KAA8B;IAC/D,OAAO,CACL,oBAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,IAAG,KAAK,CAAC,QAAQ,CAA8B,CACjG,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAErD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,OAAO;IACrB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IAErF,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YAC3B,IAAI,iBAAiB,KAAK,KAAK,EAAE,CAAC;gBAChC,oBAAoB,CAAC,IAAI,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAWD,MAAM,UAAU,aAAa;IAC3B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAE/B,OAAO;QACL,QAAQ;QACR,KAAK,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC;QAC7D,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC;QACjE,iBAAiB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC;QAC7D,cAAc,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC;QACvD,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC;KAC1D,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@eventvisor/react",
3
+ "version": "0.4.0",
4
+ "description": "React package for Eventvisor",
5
+ "main": "dist/index.js",
6
+ "module": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "scripts": {
9
+ "transpile": "rimraf lib && tsc --project tsconfig.esm.json",
10
+ "dist": "webpack --config ./webpack.config.js",
11
+ "build": "npm run transpile && npm run dist",
12
+ "test": "jest --config jest.config.js"
13
+ },
14
+ "author": {
15
+ "name": "Fahad Heylaal",
16
+ "url": "https://fahad19.com"
17
+ },
18
+ "homepage": "https://eventvisor.org",
19
+ "keywords": [],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/eventvisor/eventvisor.git"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "registry": "https://registry.npmjs.org/"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/eventvisor/eventvisor/issues"
30
+ },
31
+ "devDependencies": {
32
+ "@eventvisor/sdk": "0.4.0",
33
+ "@eventvisor/types": "0.4.0",
34
+ "@testing-library/jest-dom": "^6.9.1",
35
+ "@testing-library/react": "^16.3.0",
36
+ "jest-environment-jsdom": "^29.5.0",
37
+ "react": "^19.1.1"
38
+ },
39
+ "license": "MIT",
40
+ "gitHead": "b344241542b17d6ba180f03d78f92349df7afea8"
41
+ }
@@ -0,0 +1,135 @@
1
+ import * as React from "react";
2
+ import { render, screen, act } from "@testing-library/react";
3
+
4
+ import { createInstance } from "@eventvisor/sdk";
5
+
6
+ import { EventvisorProvider, isReady, useEventvisor } from "./index";
7
+
8
+ async function waitFor(ms: number) {
9
+ return new Promise((resolve) => setTimeout(resolve, ms));
10
+ }
11
+
12
+ describe("react :: index", function () {
13
+ it("should be a function", function () {
14
+ expect(EventvisorProvider).toBeDefined();
15
+ });
16
+ });
17
+
18
+ describe("react :: index", function () {
19
+ const transportedEvents: Record<string, any>[] = [];
20
+
21
+ const eventvisor = createInstance({
22
+ datafile: {
23
+ schemaVersion: "1",
24
+ revision: "0",
25
+ attributes: {
26
+ userId: {
27
+ type: "string",
28
+ },
29
+ deviceId: {
30
+ type: "string",
31
+ },
32
+ },
33
+ events: {
34
+ page_view: {
35
+ type: "object",
36
+ properties: {
37
+ url: { type: "string" },
38
+ },
39
+ required: ["url"],
40
+ },
41
+ button_click: {
42
+ type: "object",
43
+ properties: {
44
+ buttonId: { type: "string" },
45
+ },
46
+ required: ["buttonId"],
47
+ },
48
+ },
49
+ destinations: {
50
+ test: {
51
+ transport: "test",
52
+ },
53
+ },
54
+ effects: {},
55
+ },
56
+ modules: [
57
+ {
58
+ name: "test",
59
+
60
+ transport: async ({ destinationName, eventName, payload }) => {
61
+ transportedEvents.push({ destinationName, eventName, payload });
62
+ },
63
+ },
64
+ ],
65
+ logLevel: "error",
66
+ });
67
+
68
+ it("should run tests", async function () {
69
+ function TestComponent() {
70
+ const ready = isReady();
71
+ const { track, setAttribute } = useEventvisor();
72
+
73
+ // Track page_view when component mounts
74
+ React.useEffect(() => {
75
+ setAttribute("userId", "user-123");
76
+ setAttribute("deviceId", "device-234");
77
+
78
+ track("page_view", { url: "https://www.example.com" });
79
+ }, []);
80
+
81
+ if (!ready) {
82
+ return <div>Loading...</div>;
83
+ }
84
+
85
+ return (
86
+ <div>
87
+ <button id="my-button" onClick={() => track("button_click", { buttonId: "my-button" })}>
88
+ Button
89
+ </button>
90
+ </div>
91
+ );
92
+ }
93
+
94
+ render(
95
+ <EventvisorProvider instance={eventvisor}>
96
+ <TestComponent />
97
+ </EventvisorProvider>,
98
+ );
99
+
100
+ // expect to be not found
101
+ try {
102
+ screen.getByText("Loading...");
103
+
104
+ throw new Error("Loading element should not be found");
105
+
106
+ // eslint-disable-next-line
107
+ } catch (error) {
108
+ // pass
109
+ }
110
+
111
+ // expect to be found
112
+ try {
113
+ const button = screen.getByText("Button");
114
+
115
+ await waitFor(100);
116
+
117
+ expect(transportedEvents.length).toEqual(1);
118
+
119
+ await act(async () => {
120
+ button.click();
121
+ });
122
+
123
+ await waitFor(100);
124
+
125
+ expect(transportedEvents.length).toEqual(2);
126
+ expect(transportedEvents[0].eventName).toEqual("page_view");
127
+ expect(transportedEvents[1].eventName).toEqual("button_click");
128
+
129
+ expect(eventvisor.getAttributeValue("userId")).toEqual("user-123");
130
+ expect(eventvisor.getAttributeValue("deviceId")).toEqual("device-234");
131
+ } catch (error) {
132
+ throw error;
133
+ }
134
+ });
135
+ });
package/src/index.tsx ADDED
@@ -0,0 +1,68 @@
1
+ import * as React from "react";
2
+ import { Eventvisor } from "@eventvisor/sdk";
3
+ import { EventName, AttributeName, Value } from "@eventvisor/types";
4
+
5
+ /**
6
+ * Context
7
+ */
8
+ export const EventvisorContext = React.createContext<Eventvisor | undefined>(undefined);
9
+
10
+ /**
11
+ * Provider
12
+ */
13
+ export interface EventvisorProviderProps {
14
+ instance: Eventvisor;
15
+ children?: React.ReactNode;
16
+ }
17
+
18
+ export function EventvisorProvider(props: EventvisorProviderProps) {
19
+ return (
20
+ <EventvisorContext.Provider value={props.instance}>{props.children}</EventvisorContext.Provider>
21
+ );
22
+ }
23
+
24
+ /**
25
+ * Hooks
26
+ */
27
+ export function useInstance(): Eventvisor {
28
+ const instance = React.useContext(EventvisorContext);
29
+
30
+ return instance;
31
+ }
32
+
33
+ export function isReady(): boolean {
34
+ const instance = useInstance();
35
+ const [isEventvisorReady, setIsEventvisorReady] = React.useState(instance.isReady());
36
+
37
+ React.useEffect(() => {
38
+ instance.onReady().then(() => {
39
+ if (isEventvisorReady === false) {
40
+ setIsEventvisorReady(true);
41
+ }
42
+ });
43
+ }, []);
44
+
45
+ return isEventvisorReady;
46
+ }
47
+
48
+ export interface UseEventvisor {
49
+ instance: Eventvisor;
50
+ track: (eventName: EventName, value: Value) => void;
51
+ setAttribute: (name: AttributeName, value: Value) => void;
52
+ getAttributeValue: (name: AttributeName) => Value | null;
53
+ isAttributeSet: (name: AttributeName) => boolean;
54
+ removeAttribute: (name: AttributeName) => void;
55
+ }
56
+
57
+ export function useEventvisor(): UseEventvisor {
58
+ const instance = useInstance();
59
+
60
+ return {
61
+ instance,
62
+ track: (eventName, value) => instance.track(eventName, value),
63
+ setAttribute: (name, value) => instance.setAttribute(name, value),
64
+ getAttributeValue: (name) => instance.getAttributeValue(name),
65
+ isAttributeSet: (name) => instance.isAttributeSet(name),
66
+ removeAttribute: (name) => instance.removeAttribute(name),
67
+ };
68
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.cjs.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib"
5
+ },
6
+ "include": ["./src/**/*.ts", "./src/**/*.tsx"]
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.esm.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib"
5
+ },
6
+ "include": ["./src/**/*.ts", "./src/**/*.tsx"]
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.esm.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib"
5
+ },
6
+ "include": ["./src/**/*.ts", "./src/**/*.tsx"]
7
+ }
@@ -0,0 +1,90 @@
1
+ const path = require("path");
2
+
3
+ const externals = {
4
+ react: "react",
5
+ };
6
+
7
+ module.exports = [
8
+ // cjs
9
+ {
10
+ entry: {
11
+ "index.cjs": path.join(__dirname, "src", "index.tsx"),
12
+ },
13
+ output: {
14
+ path: path.join(__dirname, "dist"),
15
+ filename: "index.js",
16
+ library: "EventvisorReactSDK",
17
+ libraryTarget: "umd",
18
+ globalObject: "this",
19
+ },
20
+ mode: "production",
21
+ devtool: "source-map",
22
+ resolve: {
23
+ extensions: [".ts", ".tsx", ".js"],
24
+ },
25
+ externals,
26
+ module: {
27
+ rules: [
28
+ {
29
+ test: /\.(ts|tsx)$/,
30
+ exclude: /(node_modules)/,
31
+ use: [
32
+ {
33
+ loader: "ts-loader",
34
+ options: {
35
+ configFile: path.join(__dirname, "tsconfig.cjs.json"),
36
+ transpileOnly: true,
37
+ },
38
+ },
39
+ ],
40
+ },
41
+ ],
42
+ },
43
+ performance: {
44
+ hints: false,
45
+ },
46
+ optimization: {
47
+ minimize: true,
48
+ concatenateModules: false,
49
+ },
50
+ },
51
+
52
+ // esm
53
+ {
54
+ entry: path.join(__dirname, "src", "index.tsx"),
55
+ output: {
56
+ path: path.join(__dirname, "dist"),
57
+ filename: "index.mjs",
58
+ library: {
59
+ type: "module",
60
+ },
61
+ },
62
+ experiments: {
63
+ outputModule: true,
64
+ },
65
+ mode: "production",
66
+ devtool: "source-map",
67
+ resolve: {
68
+ extensions: [".ts", ".tsx", ".js"],
69
+ },
70
+ externals,
71
+ module: {
72
+ rules: [
73
+ {
74
+ test: /\.(ts|tsx)$/,
75
+ exclude: /(node_modules)/,
76
+ loader: "ts-loader",
77
+ options: {
78
+ configFile: path.join(__dirname, "tsconfig.esm.json"),
79
+ },
80
+ },
81
+ ],
82
+ },
83
+ performance: {
84
+ hints: false,
85
+ },
86
+ optimization: {
87
+ concatenateModules: false,
88
+ },
89
+ },
90
+ ];