diff --git a/next.config.js b/next.config.js index fbe00b59b..d4efc0a1c 100644 --- a/next.config.js +++ b/next.config.js @@ -38,10 +38,6 @@ const nextConfig = { ]; }, rewrites: async () => [ - { - source: '/api/segment', - destination: 'https://api.segment.io/v1/batch', - }, { source: '/api/analytics/:path*', destination: 'https://near.dataplane.rudderstack.com/:path*', diff --git a/package.json b/package.json index 66fa6b543..3679d6022 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "@web3-onboard/ledger": "^2.4.6", "@web3-onboard/react": "^2.8.7", "@web3-onboard/walletconnect": "^2.3.9", - "analytics-node": "^6.2.0", "big.js": "^6.1.1", "bn.js": "^5.1.1", "bootstrap": "^5.2.1", @@ -73,7 +72,6 @@ "zustand": "^4.3.7" }, "devDependencies": { - "@types/analytics-node": "^3.1.11", "@types/big.js": "^6.1.6", "@types/lodash": "^4.14.194", "@types/styled-components": "^5.1.26", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a7a462b1c..97bac2905 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,10 +6,10 @@ dependencies: version: 6.0.0 '@keypom/selector': specifier: 1.2.3 - version: 1.2.3(@near-js/accounts@0.1.3)(@near-js/crypto@0.0.4)(@near-js/keystores-browser@0.0.4)(@near-js/keystores-node@0.0.4)(@near-js/keystores@0.0.4)(@near-js/transactions@0.2.0)(@near-js/types@0.0.4)(@near-js/utils@0.0.4)(@near-js/wallet-account@0.0.6)(@near-wallet-selector/core@8.1.1)(@types/react@18.2.0)(near-api-js@2.1.3)(react-dom@18.2.0)(react@18.2.0) + version: 1.2.3(@near-wallet-selector/core@8.1.1)(@types/react@18.2.0)(near-api-js@2.1.3)(react-dom@18.2.0)(react@18.2.0) '@monaco-editor/react': specifier: ^4.4.6 - version: 4.5.1(monaco-editor@0.40.0)(react-dom@18.2.0)(react@18.2.0) + version: 4.5.1(react-dom@18.2.0)(react@18.2.0) '@near-js/biometric-ed25519': specifier: 0.3.0 version: 0.3.0 @@ -18,7 +18,7 @@ dependencies: version: 8.1.1(near-api-js@2.1.3) '@near-wallet-selector/here-wallet': specifier: 8.1.1 - version: 8.1.1(borsh@0.7.0)(near-api-js@2.1.3) + version: 8.1.1(near-api-js@2.1.3) '@near-wallet-selector/meteor-wallet': specifier: 8.1.1 version: 8.1.1(near-api-js@2.1.3) @@ -85,9 +85,6 @@ dependencies: '@web3-onboard/walletconnect': specifier: ^2.3.9 version: 2.3.9(react@18.2.0) - analytics-node: - specifier: ^6.2.0 - version: 6.2.0 big.js: specifier: ^6.1.1 version: 6.2.1 @@ -96,7 +93,7 @@ dependencies: version: 5.2.1 bootstrap: specifier: ^5.2.1 - version: 5.2.3(@popperjs/core@2.11.7) + version: 5.2.3 bootstrap-icons: specifier: ^1.9.0 version: 1.10.5 @@ -114,7 +111,7 @@ dependencies: version: 9.21.0 iframe-resizer-react: specifier: ^1.1.0 - version: 1.1.0(prop-types@15.8.1)(react-dom@18.2.0)(react@18.2.0) + version: 1.1.0(react-dom@18.2.0)(react@18.2.0) local-storage: specifier: ^2.0.0 version: 2.0.0 @@ -126,7 +123,7 @@ dependencies: version: 2.1.3 near-social-vm: specifier: github:NearSocial/VM#2.2.3 - version: github.com/NearSocial/VM/381ddbdc8ef5bde7975bebe8f640c1a5f9d85b94(@popperjs/core@2.11.7)(@types/react@18.2.0)(near-api-js@2.1.3)(prop-types@15.8.1)(react-dom@18.2.0)(react-is@17.0.2)(react@18.2.0) + version: github.com/NearSocial/VM/381ddbdc8ef5bde7975bebe8f640c1a5f9d85b94(@types/react@18.2.0)(near-api-js@2.1.3)(react-dom@18.2.0)(react@18.2.0) next: specifier: 13.3.4 version: 13.3.4(react-dom@18.2.0)(react@18.2.0) @@ -162,7 +159,7 @@ dependencies: version: 5.0.1 styled-components: specifier: ^5.3.6 - version: 5.3.10(react-dom@18.2.0)(react-is@17.0.2)(react@18.2.0) + version: 5.3.10(react-dom@18.2.0)(react@18.2.0) typescript: specifier: 5.0.4 version: 5.0.4 @@ -171,9 +168,6 @@ dependencies: version: 4.3.8(react@18.2.0) devDependencies: - '@types/analytics-node': - specifier: ^3.1.11 - version: 3.1.11 '@types/big.js': specifier: ^6.1.6 version: 6.1.6 @@ -185,7 +179,7 @@ devDependencies: version: 5.1.26 '@typescript-eslint/eslint-plugin': specifier: ^5.59.2 - version: 5.59.5(@typescript-eslint/parser@5.59.5)(eslint@8.39.0)(typescript@5.0.4) + version: 5.59.5(eslint@8.39.0)(typescript@5.0.4) eslint-config-prettier: specifier: ^8.8.0 version: 8.8.0(eslint@8.39.0) @@ -440,7 +434,7 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: ajv: 6.12.6 - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 espree: 9.5.2 globals: 13.20.0 ignore: 5.2.4 @@ -1686,7 +1680,7 @@ packages: '@hapi/hoek': 9.3.0 dev: false - /@here-wallet/core@1.4.3(bn.js@5.2.1)(borsh@0.7.0)(near-api-js@2.1.3): + /@here-wallet/core@1.4.3(bn.js@5.2.1)(near-api-js@2.1.3): resolution: {integrity: sha512-HtiAd1gMKxFzbnSualrzAw9CuoGWdY9z8aCY5fkpst+z7Fa5yVvBIg+f/6BWn2PFdxIWEnKk8V051FHEX/iYxA==} peerDependencies: bn.js: 5.2.1 @@ -1694,7 +1688,6 @@ packages: near-api-js: ^2.1.1 dependencies: bn.js: 5.2.1 - borsh: 0.7.0 near-api-js: 2.1.3 sha1: 1.1.1 uuid4: 2.0.3 @@ -1709,7 +1702,7 @@ packages: engines: {node: '>=10.10.0'} dependencies: '@humanwhocodes/object-schema': 1.2.1 - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 minimatch: 3.1.2 transitivePeerDependencies: - supports-color @@ -1784,7 +1777,7 @@ packages: '@pedrouid/environment': 1.0.1 dev: false - /@keypom/core@1.0.2(@near-js/accounts@0.1.3)(@near-js/crypto@0.0.4)(@near-js/keystores-browser@0.0.4)(@near-js/keystores@0.0.4)(@near-js/transactions@0.2.0)(@near-js/types@0.0.4)(@near-js/utils@0.0.4)(@near-js/wallet-account@0.0.6)(near-api-js@2.1.3): + /@keypom/core@1.0.2(near-api-js@2.1.3): resolution: {integrity: sha512-FFmOwbZCj3g8IHEdnhbTMHIp53rKjcorOlyoIKk0HaoC8rB/+Cl/BP6It1HP6DxGHorccs7yB4RXBnJei60hAg==} requiresBuild: true peerDependencies: @@ -1797,14 +1790,6 @@ packages: '@near-js/utils': ^0.0.4 '@near-js/wallet-account': ^0.0.6 dependencies: - '@near-js/accounts': 0.1.3 - '@near-js/crypto': 0.0.4 - '@near-js/keystores': 0.0.4 - '@near-js/keystores-browser': 0.0.4 - '@near-js/transactions': 0.2.0 - '@near-js/types': 0.0.4 - '@near-js/utils': 0.0.4 - '@near-js/wallet-account': 0.0.6 '@near-wallet-selector/core': 8.1.1(near-api-js@2.1.3) bn.js: 5.2.1 borsh: 0.7.0 @@ -1814,7 +1799,7 @@ packages: - near-api-js dev: false - /@keypom/selector@1.2.3(@near-js/accounts@0.1.3)(@near-js/crypto@0.0.4)(@near-js/keystores-browser@0.0.4)(@near-js/keystores-node@0.0.4)(@near-js/keystores@0.0.4)(@near-js/transactions@0.2.0)(@near-js/types@0.0.4)(@near-js/utils@0.0.4)(@near-js/wallet-account@0.0.6)(@near-wallet-selector/core@8.1.1)(@types/react@18.2.0)(near-api-js@2.1.3)(react-dom@18.2.0)(react@18.2.0): + /@keypom/selector@1.2.3(@near-wallet-selector/core@8.1.1)(@types/react@18.2.0)(near-api-js@2.1.3)(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-Z/VlZwhSt3NJ+Dv5AkgXNZ2rcFbbrd4F2sC5oTDm/TH6ocoyx5MR6ltxCWEP5/D/8Zi1MghtCtZpxrh1sHub5A==} requiresBuild: true peerDependencies: @@ -1831,15 +1816,7 @@ packages: react: ^18.2.0 react-dom: 18.2.0 dependencies: - '@keypom/core': 1.0.2(@near-js/accounts@0.1.3)(@near-js/crypto@0.0.4)(@near-js/keystores-browser@0.0.4)(@near-js/keystores@0.0.4)(@near-js/transactions@0.2.0)(@near-js/types@0.0.4)(@near-js/utils@0.0.4)(@near-js/wallet-account@0.0.6)(near-api-js@2.1.3) - '@near-js/accounts': 0.1.3 - '@near-js/crypto': 0.0.4 - '@near-js/keystores-browser': 0.0.4 - '@near-js/keystores-node': 0.0.4 - '@near-js/transactions': 0.2.0 - '@near-js/types': 0.0.4 - '@near-js/utils': 0.0.4 - '@near-js/wallet-account': 0.0.6 + '@keypom/core': 1.0.2(near-api-js@2.1.3) '@near-wallet-selector/core': 8.1.1(near-api-js@2.1.3) '@types/react': 18.2.0 bn.js: 5.2.1 @@ -1880,24 +1857,22 @@ packages: query-string: 7.1.3 dev: false - /@monaco-editor/loader@1.3.3(monaco-editor@0.40.0): + /@monaco-editor/loader@1.3.3: resolution: {integrity: sha512-6KKF4CTzcJiS8BJwtxtfyYt9shBiEv32ateQ9T4UVogwn4HM/uPo9iJd2Dmbkpz8CM6Y0PDUpjnZzCwC+eYo2Q==} peerDependencies: monaco-editor: '>= 0.21.0 < 1' dependencies: - monaco-editor: 0.40.0 state-local: 1.0.7 dev: false - /@monaco-editor/react@4.5.1(monaco-editor@0.40.0)(react-dom@18.2.0)(react@18.2.0): + /@monaco-editor/react@4.5.1(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-NNDFdP+2HojtNhCkRfE6/D6ro6pBNihaOzMbGK84lNWzRu+CfBjwzGt4jmnqimLuqp5yE5viHS2vi+QOAnD5FQ==} peerDependencies: monaco-editor: '>= 0.25.0 < 1' react: ^16.8.0 || ^17.0.0 || ^18.0.0 react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 dependencies: - '@monaco-editor/loader': 1.3.3(monaco-editor@0.40.0) - monaco-editor: 0.40.0 + '@monaco-editor/loader': 1.3.3 react: 18.2.0 react-dom: 18.2.0(react@18.2.0) dev: false @@ -1973,7 +1948,7 @@ packages: '@near-js/types': 0.0.4 '@near-js/utils': 0.0.4 ajv: 8.12.0 - ajv-formats: 2.1.1(ajv@8.12.0) + ajv-formats: 2.1.1 bn.js: 5.2.1 borsh: 0.7.0 depd: 2.0.0 @@ -2110,12 +2085,12 @@ packages: rxjs: 7.8.1 dev: false - /@near-wallet-selector/here-wallet@8.1.1(borsh@0.7.0)(near-api-js@2.1.3): + /@near-wallet-selector/here-wallet@8.1.1(near-api-js@2.1.3): resolution: {integrity: sha512-Eql3O5A72YgSPHqJff2l3RfCR7/EYOmtKJ8N/FslNv4sJQF2mq/akMcyY7/EthJIvGl1CMf6+1NpIU36jmIowQ==} peerDependencies: near-api-js: ^1.0.0 || ^2.0.0 dependencies: - '@here-wallet/core': 1.4.3(bn.js@5.2.1)(borsh@0.7.0)(near-api-js@2.1.3) + '@here-wallet/core': 1.4.3(bn.js@5.2.1)(near-api-js@2.1.3) '@near-wallet-selector/core': 8.1.1(near-api-js@2.1.3) bn.js: 5.2.1 near-api-js: 2.1.3 @@ -3355,13 +3330,6 @@ packages: resolution: {integrity: sha512-sXo/qW2/pAcmT43VoRKOJbDOfV3cYpq3szSVfIThQXNt+E4DfKj361vaAt3c88U5tPUxzEswam7GW48PJqtKAg==} dev: false - /@segment/loosely-validate-event@2.0.0: - resolution: {integrity: sha512-ZMCSfztDBqwotkl848ODgVcAmN4OItEWDCkshcKz0/W6gGSQayuuCtWV/MlodFivAZD793d6UgANd6wCXUfrIw==} - dependencies: - component-type: 1.2.1 - join-component: 1.1.0 - dev: false - /@sentry-internal/tracing@7.58.1: resolution: {integrity: sha512-kOWKqyjYdDgvO6CacXneE9UrFQHT3BXF1UpCAlnHchW/TqRFmg89sJAEUjEPGzN7y6IaX1G4j2dBPDE0OFQi3w==} engines: {node: '>=8'} @@ -3655,10 +3623,6 @@ packages: tslib: 2.5.0 dev: false - /@types/analytics-node@3.1.11: - resolution: {integrity: sha512-CNQVFhaEwL5dEzzV+OtJxt5psRQKJ+XHd0eokdPOM432tpDd4vgB6FzYRCDhDo8uxH0JPXlF6BVA9sbJPpUuug==} - dev: true - /@types/big.js@6.1.6: resolution: {integrity: sha512-0r9J+Zz9rYm2hOTwiMAVkm3XFQ4u5uTK37xrQMhc9bysn/sf/okzovWMYYIBMFTn/yrEZ11pusgLEaoarTlQbA==} dev: true @@ -3772,7 +3736,7 @@ packages: resolution: {integrity: sha512-t/Tvs5qR47OLOr+4E9ckN8AmP2Tf16gWq+/qA4iUGS/OOyHVO8wv2vjJuX8SNOUTJyWb+2t7wJm6cXILFnOROA==} dev: false - /@typescript-eslint/eslint-plugin@5.59.5(@typescript-eslint/parser@5.59.5)(eslint@8.39.0)(typescript@5.0.4): + /@typescript-eslint/eslint-plugin@5.59.5(eslint@8.39.0)(typescript@5.0.4): resolution: {integrity: sha512-feA9xbVRWJZor+AnLNAr7A8JRWeZqHUf4T9tlP+TN04b05pFVhO5eN7/O93Y/1OUlLMHKbnJisgDURs/qvtqdg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3784,11 +3748,10 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.5.1 - '@typescript-eslint/parser': 5.59.5(eslint@8.39.0)(typescript@5.0.4) '@typescript-eslint/scope-manager': 5.59.5 '@typescript-eslint/type-utils': 5.59.5(eslint@8.39.0)(typescript@5.0.4) '@typescript-eslint/utils': 5.59.5(eslint@8.39.0)(typescript@5.0.4) - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 eslint: 8.39.0 grapheme-splitter: 1.0.4 ignore: 5.2.4 @@ -3813,11 +3776,12 @@ packages: '@typescript-eslint/scope-manager': 5.59.5 '@typescript-eslint/types': 5.59.5 '@typescript-eslint/typescript-estree': 5.59.5(typescript@5.0.4) - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 eslint: 8.39.0 typescript: 5.0.4 transitivePeerDependencies: - supports-color + dev: false /@typescript-eslint/scope-manager@5.59.5: resolution: {integrity: sha512-jVecWwnkX6ZgutF+DovbBJirZcAxgxC0EOHYt/niMROf8p4PwxxG32Qdhj/iIQQIuOflLjNkxoXyArkcIP7C3A==} @@ -3838,7 +3802,7 @@ packages: dependencies: '@typescript-eslint/typescript-estree': 5.59.5(typescript@5.0.4) '@typescript-eslint/utils': 5.59.5(eslint@8.39.0)(typescript@5.0.4) - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 eslint: 8.39.0 tsutils: 3.21.0(typescript@5.0.4) typescript: 5.0.4 @@ -3861,7 +3825,7 @@ packages: dependencies: '@typescript-eslint/types': 5.59.5 '@typescript-eslint/visitor-keys': 5.59.5 - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 semver: 7.5.0 @@ -4432,15 +4396,13 @@ packages: resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==} engines: {node: '>= 6.0.0'} dependencies: - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 transitivePeerDependencies: - supports-color dev: false - /ajv-formats@2.1.1(ajv@8.12.0): + /ajv-formats@2.1.1: resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==} - peerDependencies: - ajv: ^8.0.0 peerDependenciesMeta: ajv: optional: true @@ -4465,22 +4427,6 @@ packages: uri-js: 4.4.1 dev: false - /analytics-node@6.2.0: - resolution: {integrity: sha512-NLU4tCHlWt0tzEaFQL7NIoWhq2KmQSmz0JvyS2lYn6fc4fEjTMSabhJUx8H1r5995FX8fE3rZ15uIHU6u+ovlQ==} - engines: {node: '>=4'} - dependencies: - '@segment/loosely-validate-event': 2.0.0 - axios: 0.27.2 - axios-retry: 3.2.0 - lodash.isstring: 4.0.1 - md5: 2.3.0 - ms: 2.1.3 - remove-trailing-slash: 0.1.1 - uuid: 8.3.2 - transitivePeerDependencies: - - debug - dev: false - /ansi-regex@4.1.1: resolution: {integrity: sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==} engines: {node: '>=6'} @@ -4588,10 +4534,6 @@ packages: resolution: {integrity: sha512-eBvWn1lvIApYMhzQMsu9ciLfkBY499mFZlNqG+/9WR7PVlroQw0vG30cOQQbaKz3sCEc44TAOu2ykzqXSNnwag==} dev: false - /asynckit@0.4.0: - resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} - dev: false - /atomic-sleep@1.0.0: resolution: {integrity: sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==} engines: {node: '>=8.0.0'} @@ -4607,12 +4549,6 @@ packages: engines: {node: '>=4'} dev: false - /axios-retry@3.2.0: - resolution: {integrity: sha512-RK2cLMgIsAQBDhlIsJR5dOhODPigvel18XUv1dDXW+4k1FzebyfRk+C+orot6WPZOYFKSfhLwHPwVmTVOODQ5w==} - dependencies: - is-retry-allowed: 1.2.0 - dev: false - /axios@0.21.4: resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} dependencies: @@ -4621,15 +4557,6 @@ packages: - debug dev: false - /axios@0.27.2: - resolution: {integrity: sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==} - dependencies: - follow-redirects: 1.15.2 - form-data: 4.0.0 - transitivePeerDependencies: - - debug - dev: false - /axobject-query@3.1.1: resolution: {integrity: sha512-goKlv8DZrK9hUh975fnHzhNIO4jUnFCfv/dszV5VwUGDFjI6vQ2VwoyjYjYNEbBE8AH87TduWP5uyDR1D+Iteg==} dependencies: @@ -4646,7 +4573,7 @@ packages: babel-plugin-syntax-jsx: 6.18.0 lodash: 4.17.21 picomatch: 2.3.1 - styled-components: 5.3.10(react-dom@18.2.0)(react-is@17.0.2)(react@18.2.0) + styled-components: 5.3.10(react-dom@18.2.0)(react@18.2.0) dev: false /babel-plugin-syntax-jsx@6.18.0: @@ -4728,12 +4655,10 @@ packages: resolution: {integrity: sha512-oSX26F37V7QV7NCE53PPEL45d7EGXmBgHG3pDpZvcRaKVzWMqIRL9wcqJUyEha1esFtM3NJzvmxFXDxjJYD0jQ==} dev: false - /bootstrap@5.2.3(@popperjs/core@2.11.7): + /bootstrap@5.2.3: resolution: {integrity: sha512-cEKPM+fwb3cT8NzQZYEu4HilJ3anCrWqh3CHAok1p9jXqMPsPTBhU25fBckEJHJ/p+tTxTFTsFQGM+gaHpi3QQ==} peerDependencies: '@popperjs/core': ^2.11.6 - dependencies: - '@popperjs/core': 2.11.7 dev: false /borsh@0.7.0: @@ -5017,13 +4942,6 @@ packages: /color-name@1.1.4: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} - /combined-stream@1.0.8: - resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} - engines: {node: '>= 0.8'} - dependencies: - delayed-stream: 1.0.0 - dev: false - /comma-separated-tokens@1.0.8: resolution: {integrity: sha512-GHuDRO12Sypu2cV70d1dkA2EUmXHgntrzbpvOB+Qy+49ypNfGgFQIC2fhhXbnyrJRynDCAARsT7Ou0M6hirpfw==} dev: false @@ -5036,10 +4954,6 @@ packages: resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==} dev: false - /component-type@1.2.1: - resolution: {integrity: sha512-Kgy+2+Uwr75vAi6ChWXgHuLvd+QLD7ssgpaRq2zCvt80ptvAfMc/hijcJxXkBa2wMlEZcJvC2H8Ubo+A9ATHIg==} - dev: false - /compute-scroll-into-view@1.0.20: resolution: {integrity: sha512-UCB0ioiyj8CRjtrvaceBLqqhZCVP+1B8+NWQhmdsm0VXOJtobBCf1dBQmebCCo34qZmUwZfIH2MZLqNHazrfjg==} dev: false @@ -5141,6 +5055,17 @@ packages: ms: 2.1.3 dev: false + /debug@4.3.4: + resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} + engines: {node: '>=6.0'} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + dependencies: + ms: 2.1.2 + /debug@4.3.4(supports-color@5.5.0): resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} @@ -5152,6 +5077,7 @@ packages: dependencies: ms: 2.1.2 supports-color: 5.5.0 + dev: false /decamelize@1.2.0: resolution: {integrity: sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==} @@ -5231,11 +5157,6 @@ packages: object-keys: 1.1.1 dev: false - /delayed-stream@1.0.0: - resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} - engines: {node: '>=0.4.0'} - dev: false - /depd@1.1.2: resolution: {integrity: sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==} engines: {node: '>= 0.6'} @@ -5549,7 +5470,7 @@ packages: eslint: '*' eslint-plugin-import: '*' dependencies: - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 enhanced-resolve: 5.14.0 eslint: 8.39.0 eslint-module-utils: 2.8.0(@typescript-eslint/parser@5.59.5)(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.5)(eslint@8.39.0) @@ -5729,7 +5650,7 @@ packages: ajv: 6.12.6 chalk: 4.1.2 cross-spawn: 7.0.3 - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 doctrine: 3.0.0 escape-string-regexp: 4.0.0 eslint-scope: 7.2.0 @@ -6122,15 +6043,6 @@ packages: is-callable: 1.2.7 dev: false - /form-data@4.0.0: - resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} - engines: {node: '>= 6'} - dependencies: - asynckit: 0.4.0 - combined-stream: 1.0.8 - mime-types: 2.1.35 - dev: false - /format@0.2.2: resolution: {integrity: sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww==} engines: {node: '>=0.4.x'} @@ -6312,6 +6224,7 @@ packages: /has-flag@3.0.0: resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==} engines: {node: '>=4'} + dev: false /has-flag@4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} @@ -6422,7 +6335,7 @@ packages: engines: {node: '>= 6'} dependencies: agent-base: 6.0.2 - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 transitivePeerDependencies: - supports-color dev: false @@ -6449,7 +6362,7 @@ packages: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} dev: false - /iframe-resizer-react@1.1.0(prop-types@15.8.1)(react-dom@18.2.0)(react@18.2.0): + /iframe-resizer-react@1.1.0(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-FrytSq91AIJaDgE+6uK/Vdd6IR8CrwLoZ6eGmL2qQMPTzF0xlSV2jaSzRRUh5V2fttD7vzl21jvBl97bV40eBw==} engines: {node: '>=8', npm: '>=5'} peerDependencies: @@ -6458,7 +6371,6 @@ packages: react-dom: '>=16.8.0' dependencies: iframe-resizer: 4.3.6 - prop-types: 15.8.1 react: 18.2.0 react-dom: 18.2.0(react@18.2.0) warning: 4.0.3 @@ -6566,10 +6478,6 @@ packages: has-tostringtag: 1.0.0 dev: false - /is-buffer@1.1.6: - resolution: {integrity: sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==} - dev: false - /is-buffer@2.0.5: resolution: {integrity: sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==} engines: {node: '>=4'} @@ -6699,11 +6607,6 @@ packages: has-tostringtag: 1.0.0 dev: false - /is-retry-allowed@1.2.0: - resolution: {integrity: sha512-RUbUeKwvm3XG2VYamhJL1xFktgjvPzL0Hq8C+6yrWIswDy3BIXGqCxhxkc30N9jqK311gVU137K8Ei55/zVJRg==} - engines: {node: '>=0.10.0'} - dev: false - /is-set@2.0.2: resolution: {integrity: sha512-+2cnTEZeY5z/iXGbLhPrOAaK/Mau5k5eXq9j14CpRTftq0pAJu2MwVRSZhyZWBzx3o6X795Lz6Bpb6R0GKf37g==} dev: false @@ -6794,10 +6697,6 @@ packages: '@sideway/pinpoint': 2.0.0 dev: false - /join-component@1.1.0: - resolution: {integrity: sha512-bF7vcQxbODoGK1imE2P9GS9aw4zD0Sd+Hni68IMZLj7zRnquH7dXUmMw9hDI5S/Jzt7q+IyTXN0rSg2GI0IKhQ==} - dev: false - /jose@4.14.4: resolution: {integrity: sha512-j8GhLiKmUAh+dsFXlX1aJCbt5KMibuKb+d7j1JaOJG6s2UjX1PQlW+OKB/sD4a/5ZYF4RcmYmLSndOoU3Lt/3g==} dev: false @@ -6955,10 +6854,6 @@ packages: resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==} dev: false - /lodash.isstring@4.0.1: - resolution: {integrity: sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==} - dev: false - /lodash.merge@4.6.2: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} @@ -7035,14 +6930,6 @@ packages: safe-buffer: 5.2.1 dev: false - /md5@2.3.0: - resolution: {integrity: sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==} - dependencies: - charenc: 0.0.2 - crypt: 0.0.2 - is-buffer: 1.1.6 - dev: false - /mdast-util-definitions@5.1.2: resolution: {integrity: sha512-8SVPMuHqlPME/z3gqVwWY4zVXn8lqKv/pAhC57FuJ40ImXyBpmO5ukh98zB2v7Blql2FiHjHv9LVztSIqjY+MA==} dependencies: @@ -7428,7 +7315,7 @@ packages: resolution: {integrity: sha512-6Mj0yHLdUZjHnOPgr5xfWIMqMWS12zDN6iws9SLuSz76W8jTtAv24MN4/CL7gJrl5vtxGInkkqDv/JIoRsQOvA==} dependencies: '@types/debug': 4.1.7 - debug: 4.3.4(supports-color@5.5.0) + debug: 4.3.4 decode-named-character-reference: 1.0.2 micromark-core-commonmark: 1.0.6 micromark-factory-space: 1.0.0 @@ -7455,18 +7342,6 @@ packages: braces: 3.0.2 picomatch: 2.3.1 - /mime-db@1.52.0: - resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} - engines: {node: '>= 0.6'} - dev: false - - /mime-types@2.1.35: - resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} - engines: {node: '>= 0.6'} - dependencies: - mime-db: 1.52.0 - dev: false - /mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} @@ -7508,10 +7383,6 @@ packages: minimist: 1.2.8 dev: false - /monaco-editor@0.40.0: - resolution: {integrity: sha512-1wymccLEuFSMBvCk/jT1YDW/GuxMLYwnFwF9CDyYCxoTw2Pt379J3FUhwy9c43j51JdcxVPjwk0jm0EVDsBS2g==} - dev: false - /motion@10.16.2: resolution: {integrity: sha512-p+PurYqfUdcJZvtnmAqu5fJgV2kR0uLFQuBKtLeFVTrYEVllI99tiOTSefVNYuip9ELTEkepIIDftNdze76NAQ==} dependencies: @@ -7590,7 +7461,7 @@ packages: '@near-js/utils': 0.0.4 '@near-js/wallet-account': 0.0.6 ajv: 8.12.0 - ajv-formats: 2.1.1(ajv@8.12.0) + ajv-formats: 2.1.1 bn.js: 5.2.1 borsh: 0.7.0 depd: 2.0.0 @@ -8535,10 +8406,6 @@ packages: - supports-color dev: false - /remove-trailing-slash@0.1.1: - resolution: {integrity: sha512-o4S4Qh6L2jpnCy83ysZDau+VORNvnFw07CKSAymkd6ICNVEPisMyzlc00KlvvicsxKck94SEwhDnMNdICzO+tA==} - dev: false - /require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} @@ -8923,7 +8790,7 @@ packages: inline-style-parser: 0.1.1 dev: false - /styled-components@5.3.10(react-dom@18.2.0)(react-is@17.0.2)(react@18.2.0): + /styled-components@5.3.10(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-3kSzSBN0TiCnGJM04UwO1HklIQQSXW7rCARUk+VyMR7clz8XVlA3jijtf5ypqoDIdNMKx3la4VvaPFR855SFcg==} engines: {node: '>=10'} peerDependencies: @@ -8941,7 +8808,6 @@ packages: hoist-non-react-statics: 3.3.2 react: 18.2.0 react-dom: 18.2.0(react@18.2.0) - react-is: 17.0.2 shallowequal: 1.1.0 supports-color: 5.5.0 dev: false @@ -8968,6 +8834,7 @@ packages: engines: {node: '>=4'} dependencies: has-flag: 3.0.0 + dev: false /supports-color@7.2.0: resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==} @@ -9330,11 +9197,6 @@ packages: resolution: {integrity: sha512-CTpAkEVXMNJl2ojgtpLXHgz23dh8z81u6/HEPiQFOvBc/c2pde6TVHmH4uwY0d/GLF3tb7+VDAj4+2eJaQSdZQ==} dev: false - /uuid@8.3.2: - resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==} - hasBin: true - dev: false - /uvu@0.5.6: resolution: {integrity: sha512-+g8ENReyr8YsOc6fv/NVJs2vFdHBnBNdfE49rshrTzDWOlUx4Gq7KOS2GD8eqhy2j+Ejq29+SbKH8yjkAqXqoA==} engines: {node: '>=8'} @@ -9665,7 +9527,7 @@ packages: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} dev: false - github.com/NearSocial/VM/381ddbdc8ef5bde7975bebe8f640c1a5f9d85b94(@popperjs/core@2.11.7)(@types/react@18.2.0)(near-api-js@2.1.3)(prop-types@15.8.1)(react-dom@18.2.0)(react-is@17.0.2)(react@18.2.0): + github.com/NearSocial/VM/381ddbdc8ef5bde7975bebe8f640c1a5f9d85b94(@types/react@18.2.0)(near-api-js@2.1.3)(react-dom@18.2.0)(react@18.2.0): resolution: {tarball: https://codeload.github.com/NearSocial/VM/tar.gz/381ddbdc8ef5bde7975bebe8f640c1a5f9d85b94} id: github.com/NearSocial/VM/381ddbdc8ef5bde7975bebe8f640c1a5f9d85b94 name: near-social-vm @@ -9707,14 +9569,14 @@ packages: acorn-jsx: 5.3.2(acorn@8.8.2) big.js: 6.2.1 bn.js: 5.2.1 - bootstrap: 5.2.3(@popperjs/core@2.11.7) + bootstrap: 5.2.3 bootstrap-icons: 1.10.5 collections: 5.1.13 deep-equal: 2.2.1 elliptic: 6.5.4 ethers: 5.7.2 idb: 7.1.1 - iframe-resizer-react: 1.1.0(prop-types@15.8.1)(react-dom@18.2.0)(react@18.2.0) + iframe-resizer-react: 1.1.0(react-dom@18.2.0)(react@18.2.0) local-storage: 2.0.0 lodash: 4.17.21 mdast-util-find-and-replace: 2.2.2 @@ -9733,7 +9595,7 @@ packages: react-syntax-highlighter: 15.5.0(react@18.2.0) react-uuid: 1.0.3 remark-gfm: 3.0.1 - styled-components: 5.3.10(react-dom@18.2.0)(react-is@17.0.2)(react@18.2.0) + styled-components: 5.3.10(react-dom@18.2.0)(react@18.2.0) tweetnacl: 1.0.3 transitivePeerDependencies: - '@popperjs/core' diff --git a/src/components/navigation/desktop/DesktopNavigation.tsx b/src/components/navigation/desktop/DesktopNavigation.tsx index 8964db855..10521a2fb 100644 --- a/src/components/navigation/desktop/DesktopNavigation.tsx +++ b/src/components/navigation/desktop/DesktopNavigation.tsx @@ -9,7 +9,6 @@ import { useBosComponents } from '@/hooks/useBosComponents'; import { useSignInRedirect } from '@/hooks/useSignInRedirect'; import { useAuthStore } from '@/stores/auth'; import { recordEvent } from '@/utils/analytics'; -import { flushEvents } from '@/utils/analytics'; import LogoBlack from '../icons/logo-black.svg'; import NearLogotype from '../icons/near-logotype.svg'; @@ -151,12 +150,10 @@ export const DesktopNavigation = () => { }, []); function handleSignIn() { - flushEvents(); requestAuthentication(); } function handleCreateAccount() { - flushEvents(); requestAuthentication(true); } diff --git a/src/components/navigation/mobile/MenuLeft.tsx b/src/components/navigation/mobile/MenuLeft.tsx index 3d0a03162..69fd47aa1 100644 --- a/src/components/navigation/mobile/MenuLeft.tsx +++ b/src/components/navigation/mobile/MenuLeft.tsx @@ -9,7 +9,6 @@ import { Button } from '@/components/lib/Button'; import { useBosComponents } from '@/hooks/useBosComponents'; import { useSignInRedirect } from '@/hooks/useSignInRedirect'; import { useAuthStore } from '@/stores/auth'; -import { flushEvents } from '@/utils/analytics'; import { UserDropdownMenu } from '../desktop/UserDropdownMenu'; import NearLogotype from '../icons/near-logotype.svg'; @@ -136,13 +135,11 @@ export function MenuLeft(props: Props) { const { requestAuthentication } = useSignInRedirect(); function handleSignIn() { - flushEvents(); props.onCloseMenu(); requestAuthentication(); } function handleCreateAccount() { - flushEvents(); props.onCloseMenu(); requestAuthentication(true); } diff --git a/src/components/vm/VmInitializer.tsx b/src/components/vm/VmInitializer.tsx index 1fe323dde..5a3dfb379 100644 --- a/src/components/vm/VmInitializer.tsx +++ b/src/components/vm/VmInitializer.tsx @@ -30,7 +30,7 @@ import { useSignInRedirect } from '@/hooks/useSignInRedirect'; import { setupFastAuth } from '@/lib/selector/setup'; import { useAuthStore } from '@/stores/auth'; import { useVmStore } from '@/stores/vm'; -import { recordWalletConnect, reset as resetSegment } from '@/utils/analytics'; +import { recordWalletConnect, reset as resetAnalytics } from '@/utils/analytics'; import { networkId, signInContractId } from '@/utils/config'; import { KEYPOM_OPTIONS } from '@/utils/keypom-options'; @@ -125,7 +125,7 @@ export default function VmInitializer() { near.accountId = null; setSignedIn(false); setSignedAccountId(null); - resetSegment(); + resetAnalytics(); localStorage.removeItem('accountId'); }, [near]); diff --git a/src/hooks/useBanner.ts b/src/hooks/useBanner.ts index 1ce57e9bf..3da01500f 100644 --- a/src/hooks/useBanner.ts +++ b/src/hooks/useBanner.ts @@ -7,13 +7,13 @@ export function useBanner() { const [isBannerVisible, setBanner] = useState(true); useEffect(() => { - const bannerState = sessionStorage.getItem('hintVisible'); + const bannerState = localStorage.getItem('hintVisible'); const banner = bannerState ? JSON.parse(bannerState) : true; setBanner(banner); }, []); const setBanners = useCallback((newBannerState: boolean) => { - sessionStorage.setItem('hintVisible', JSON.stringify(newBannerState)); + localStorage.setItem('hintVisible', JSON.stringify(newBannerState)); setBanner(newBannerState); }, []); diff --git a/src/utils/analytics.ts b/src/utils/analytics.ts index fa7b52755..459de6019 100644 --- a/src/utils/analytics.ts +++ b/src/utils/analytics.ts @@ -1,17 +1,70 @@ +import { createHash } from 'crypto'; import { get, split, truncate } from 'lodash'; +import { nanoid } from 'nanoid'; import type { UIEvent } from 'react'; -import * as RudderAnalytics from './rudder-analytics'; -import * as Segment from './segment-analytics'; +import type Analytics from '../../types/rudderstack-analytics'; +import { networkId } from './config'; -export async function init() { - await Segment.init(); - await RudderAnalytics.init(); +let rudderAnalytics: Analytics | null = null; +let anonymousUserId = ''; +let hashId = ''; +let anonymousUserIdCreatedAt = ''; + +declare global { + interface Window { + rudderAnalytics: Analytics | undefined; + } } -export function recordPageView(pageName: string) { - Segment.recordPageView(pageName); - RudderAnalytics.recordPageView(pageName); +export function setAccountIdHash(accountId: string) { + const hash = createHash('sha512'); + hash.update(accountId); + hashId = hash.digest('hex'); + localStorage.setItem('hashId', hashId); +} + +function getAnonymousId() { + if (anonymousUserId) { + return anonymousUserId; + } + + const storageId = localStorage.getItem('anonymousUserId'); + anonymousUserIdCreatedAt = localStorage.getItem('anonymousUserIdCreatedAt') || ''; + + if (storageId) { + anonymousUserId = storageId; + } else { + anonymousUserId = nanoid(); + anonymousUserIdCreatedAt = new Date().toUTCString(); + localStorage.setItem('anonymousUserId', anonymousUserId); + localStorage.setItem('anonymousUserIdCreatedAt', anonymousUserIdCreatedAt); + } + + return anonymousUserId; +} + +export async function init() { + if (window?.rudderAnalytics) return; + + getAnonymousId(); + + const rudderAnalyticsKey = networkId === 'testnet' ? '2R7K9phhzpFzk2zFIq2EFBtJ8BM' : '2R7K9phhzpFzk2zFIq2EFBtJ8BM'; + const rudderStackDataPlaneUrl = 'https://near.dataplane.rudderstack.com'; + + let analyticsUrl = rudderStackDataPlaneUrl; + if (typeof window !== 'undefined') { + analyticsUrl = `${window.location.protocol}//${window.location.host}/api/analytics`; + } + + try { + window.rudderAnalytics = await import('rudder-sdk-js'); + window.rudderAnalytics.load(rudderAnalyticsKey, analyticsUrl); + rudderAnalytics = window.rudderAnalytics; + if (rudderAnalytics) rudderAnalytics.setAnonymousId(getAnonymousId()); + } catch (e) { + console.error(e); + } } function isStringAllowed(str: string) { @@ -24,42 +77,75 @@ function filterURL(url: string) { return isStringAllowed(params) ? url : urlTrim; } +export function recordPageView(pageName: string) { + if (!rudderAnalytics) return; + try { + rudderAnalytics.page('category', pageName, { + hashId: localStorage.getItem('hashId'), + url: filterURL(window.location.href), + ref: filterURL(document.referrer), + }); + } catch (e) { + console.error(e); + } +} + const record = (eventType: string, e: UIEvent | PointerEvent) => { const key = get(e.target, 'placeholder', get(e.target, 'innerText', get(e.target, 'href'))); - Segment.recordEventWithProps(eventType, { - element: truncate(key, { length: 255 }), - url: e.target ? filterURL((e.target as HTMLElement).baseURI) : '', - xPath: getXPath(e.target as HTMLElement), - }); - - RudderAnalytics.recordEventWithProps(eventType, { + recordEventWithProps(eventType, { element: truncate(key, { length: 255 }), url: e.target ? filterURL((e.target as HTMLElement).baseURI) : '', xPath: getXPath(e.target as HTMLElement), }); }; - export const recordClick = (e: UIEvent | PointerEvent) => record('click', e); export const recordMouseEnter = (e: UIEvent) => record('mouseover', e); export const recordTouchStart = (e: UIEvent | PointerEvent) => record('touchstart', e); export function recordWalletConnect(accountId: string) { - Segment.recordWalletConnect(accountId); - RudderAnalytics.recordWalletConnect(accountId); + if (!localStorage.getItem('hashId')) { + setAccountIdHash(accountId); + recordEvent('wallet-connected'); + } } export function reset() { - Segment.reset(); - RudderAnalytics.reset(); + if (!rudderAnalytics) return; + try { + recordEvent('wallet-logout'); + localStorage.removeItem('hashId'); + localStorage.removeItem('anonymousUserId'); + localStorage.removeItem('anonymousUserIdCreatedAt'); + rudderAnalytics.reset(); + } catch (e) { + console.error(e); + } } -export function flushEvents() { - Segment.flushEvents(); +export function recordEventWithProps(eventLabel: string, properties: Record) { + if (!rudderAnalytics) return; + try { + rudderAnalytics.track(eventLabel, { + ...properties, + hashId: localStorage.getItem('hashId'), + anonymousUserIdCreatedAt, + }); + } catch (e) { + console.error(e); + } } export function recordEvent(eventLabel: string) { - Segment.recordEvent(eventLabel); - RudderAnalytics.recordEvent(eventLabel); + if (!rudderAnalytics) return; + try { + rudderAnalytics.track(eventLabel, { + hashId: localStorage.getItem('hashId'), + url: window.location.href, + anonymousUserIdCreatedAt, + }); + } catch (e) { + console.error(e); + } } function getXPath(element: HTMLElement | null): string { diff --git a/src/utils/rudder-analytics.ts b/src/utils/rudder-analytics.ts deleted file mode 100644 index 75299c752..000000000 --- a/src/utils/rudder-analytics.ts +++ /dev/null @@ -1,187 +0,0 @@ -import { createHash } from 'crypto'; -import { get, split, truncate } from 'lodash'; -import { nanoid } from 'nanoid'; -import type { UIEvent } from 'react'; - -import type Analytics from '../../types/rudderstack-analytics'; -import { networkId } from './config'; - -let rudderAnalytics: Analytics | null = null; -let anonymousUserId = ''; -let hashId = ''; -let anonymousUserIdCreatedAt = ''; -let pendingEvents: any = []; - -declare global { - interface Window { - rudderanalytics: Analytics | undefined; - } -} - -export function setAccountIdHash(accountId: string) { - const hash = createHash('sha512'); - hash.update(accountId); - hashId = hash.digest('hex'); - localStorage.setItem('hashId', hashId); -} - -function getAnonymousId() { - if (anonymousUserId) { - return anonymousUserId; - } - - const storageId = localStorage.getItem('anonymousUserId'); - anonymousUserIdCreatedAt = localStorage.getItem('anonymousUserIdCreatedAt') || ''; - - if (storageId) { - anonymousUserId = storageId; - } else { - anonymousUserId = nanoid(); - anonymousUserIdCreatedAt = new Date().toUTCString(); - localStorage.setItem('anonymousUserId', anonymousUserId); - localStorage.setItem('anonymousUserIdCreatedAt', anonymousUserIdCreatedAt); - } - - return anonymousUserId; -} - -export async function init() { - if (window?.rudderanalytics) return; - - getAnonymousId(); - - const rudderAnalyticsKey = networkId === 'testnet' ? '2R7K9phhzpFzk2zFIq2EFBtJ8BM' : '2RIih8mrVPUTQ9uWe6TFfwXzcMe'; - const rudderStackDataPlaneUrl = 'https://near.dataplane.rudderstack.com'; - - let analyticsUrl = rudderStackDataPlaneUrl; - if (typeof window !== 'undefined') { - analyticsUrl = `${window.location.protocol}//${window.location.host}/api/analytics`; - } - - try { - window.rudderanalytics = await import('rudder-sdk-js'); - window.rudderanalytics.load(rudderAnalyticsKey, analyticsUrl); - rudderAnalytics = window.rudderanalytics; - if (rudderAnalytics) rudderAnalytics.setAnonymousId(getAnonymousId()); - for (const event of pendingEvents) { - event(); - } - pendingEvents = []; - } catch (e) { - console.error(e); - } -} - -function isStringAllowed(str: string) { - const denyList = ['account_id', 'public_key', 'all_keys', 'publicKey', 'apiKey', 'accountId', 'email']; - return !str || !denyList.some((param) => str.indexOf(param) !== -1); -} - -function filterURL(url: string) { - const [urlTrim, params] = split(url, '?'); - return isStringAllowed(params) ? url : urlTrim; -} - -export function recordPageView(pageName: string) { - if (!rudderAnalytics) { - pendingEvents.push(() => { - recordPageView(pageName); - }); - return; - } - try { - rudderAnalytics.page('category', pageName, { - hashId: localStorage.getItem('hashId'), - url: filterURL(window.location.href), - ref: filterURL(document.referrer), - }); - } catch (e) { - console.error(e); - } -} - -const record = (eventType: string, e: UIEvent) => { - const key = get(e.target, 'placeholder', get(e.target, 'innerText', get(e.target, 'href'))); - recordEventWithProps(eventType, { - element: truncate(key, { length: 255 }), - url: e.target ? filterURL((e.target as HTMLElement).baseURI) : '', - xPath: getXPath(e.target as HTMLElement), - }); -}; -export const recordClick = (e: UIEvent) => record('click', e); -export const recordMouseEnter = (e: UIEvent) => record('mouseover', e); -export const recordTouchStart = (e: UIEvent) => record('touchstart', e); - -export function recordWalletConnect(accountId: string) { - if (!localStorage.getItem('hashId')) { - setAccountIdHash(accountId); - recordEvent('wallet-connected'); - } -} - -export function logout() { - if (!rudderAnalytics) return; - try { - recordEvent('wallet-logout'); - localStorage.removeItem('hashId'); - rudderAnalytics.reset(); - } catch (e) { - console.error(e); - } -} - -export function reset() { - if (!rudderAnalytics) return; - try { - recordEvent('wallet-logout'); - localStorage.removeItem('hashId'); - localStorage.removeItem('anonymousUserId'); - localStorage.removeItem('anonymousUserIdCreatedAt'); - rudderAnalytics.reset(); - } catch (e) { - console.error(e); - } -} - -export function recordEventWithProps(eventLabel: string, properties: Record) { - if (!rudderAnalytics) return; - try { - rudderAnalytics.track(eventLabel, { - ...properties, - hashId: localStorage.getItem('hashId'), - anonymousUserIdCreatedAt, - }); - } catch (e) { - console.error(e); - } -} - -export function recordEvent(eventLabel: string) { - if (!rudderAnalytics) return; - try { - rudderAnalytics.track(eventLabel, { - hashId: localStorage.getItem('hashId'), - url: window.location.href, - anonymousUserIdCreatedAt, - }); - } catch (e) { - console.error(e); - } -} - -function getXPath(element: HTMLElement | null): string { - if (!element) return ''; - if (element.id !== '') return 'id("' + element.id + '")'; - if (element === document.body) return element.tagName; - - let ix = 0; - const siblings = element.parentNode?.children || new HTMLCollection(); - - for (let i = 0; i < siblings.length; i++) { - const sibling = siblings[i]; - if (sibling === element) return getXPath(element.parentElement) + '/' + element.tagName + '[' + (ix + 1) + ']'; - if (sibling.nodeType === 1 && sibling.tagName === element.tagName) ix++; - } - - return ''; -} diff --git a/src/utils/segment-analytics.ts b/src/utils/segment-analytics.ts deleted file mode 100644 index 0bbda3e44..000000000 --- a/src/utils/segment-analytics.ts +++ /dev/null @@ -1,176 +0,0 @@ -import Analytics from 'analytics-node'; -import { createHash } from 'crypto'; -import { get, split, truncate } from 'lodash'; -import { nanoid } from 'nanoid'; -import type { UIEvent } from 'react'; - -import { networkId } from './config'; - -let segment: Analytics | null = null; -let anonymousUserId = ''; -let hashId = ''; -let anonymousUserIdCreatedAt = ''; - -export function setAccountIdHash(accountId: string) { - const hash = createHash('sha512'); - hash.update(accountId); - hashId = hash.digest('hex'); - localStorage.setItem('hashId', hashId); -} - -function getAnonymousId() { - if (anonymousUserId) { - return anonymousUserId; - } - - const storageId = localStorage.getItem('anonymousUserId'); - anonymousUserIdCreatedAt = localStorage.getItem('anonymousUserIdCreatedAt') || ''; - - if (storageId) { - anonymousUserId = storageId; - } else { - anonymousUserId = nanoid(); - anonymousUserIdCreatedAt = new Date().toUTCString(); - localStorage.setItem('anonymousUserId', anonymousUserId); - localStorage.setItem('anonymousUserIdCreatedAt', anonymousUserIdCreatedAt); - } - - return anonymousUserId; -} - -export async function init() { - if (segment) return; // already initialized - - getAnonymousId(); - - const segmentKey = networkId === 'testnet' ? 'diA7hiO28gGeb9fxn615Xs91uX3GyYhL' : 'gVheHtpTIWpmstSvXjGkSY80nGEXgHX4'; - - const options = - typeof window === 'undefined' - ? {} - : { - host: `${window.location.protocol}//${window.location.host}`, - path: '/api/segment', - }; - - try { - segment = new Analytics(segmentKey, options); - } catch (e) { - console.error(e); - } -} - -function isStringAllowed(str: string) { - const denyList = ['account_id', 'public_key', 'all_keys', 'publicKey', 'apiKey', 'accountId', 'email']; - return !str || !denyList.some((param) => str.indexOf(param) !== -1); -} - -function filterURL(url: string) { - const [urlTrim, params] = split(url, '?'); - return isStringAllowed(params) ? url : urlTrim; -} - -export function recordPageView(pageName: string) { - if (!segment) return; - try { - segment.page({ - name: pageName, - anonymousId: getAnonymousId(), - properties: { - hashId: localStorage.getItem('hashId'), - url: filterURL(window.location.href), - ref: filterURL(document.referrer), - }, - }); - } catch (e) { - console.error(e); - } -} - -const record = (eventType: string, e: UIEvent) => { - const key = get(e.target, 'placeholder', get(e.target, 'innerText', get(e.target, 'href'))); - recordEventWithProps(eventType, { - element: truncate(key, { length: 255 }), - url: e.target ? filterURL((e.target as HTMLElement).baseURI) : '', - xPath: getXPath(e.target as HTMLElement), - }); -}; -export const recordClick = (e: UIEvent) => record('click', e); -export const recordMouseEnter = (e: UIEvent) => record('mouseover', e); -export const recordTouchStart = (e: UIEvent) => record('touchstart', e); - -export function recordWalletConnect(accountId: string) { - if (!localStorage.getItem('hashId')) { - setAccountIdHash(accountId); - recordEvent('wallet-connected'); - } -} - -export function reset() { - if (!segment) return; - try { - recordEvent('wallet-logout'); - localStorage.removeItem('hashId'); - localStorage.removeItem('anonymousUserId'); - localStorage.removeItem('anonymousUserIdCreatedAt'); - segment.flush(); - } catch (e) { - console.error(e); - } -} - -export function flushEvents() { - if (!segment) return; - return segment.flush(); -} - -export function recordEventWithProps(eventLabel: string, properties: Record) { - if (!segment) return; - try { - segment.track({ - anonymousId: getAnonymousId(), - event: eventLabel, - properties: { - ...properties, - hashId: localStorage.getItem('hashId'), - anonymousUserIdCreatedAt, - }, - }); - } catch (e) { - console.error(e); - } -} - -export function recordEvent(eventLabel: string) { - if (!segment) return; - try { - segment.track({ - anonymousId: getAnonymousId(), - event: eventLabel, - properties: { - hashId: localStorage.getItem('hashId'), - url: window.location.href, - anonymousUserIdCreatedAt, - }, - }); - } catch (e) { - console.error(e); - } -} - -function getXPath(element: HTMLElement | null): string { - if (!element) return ''; - if (element.id !== '') return 'id("' + element.id + '")'; - if (element === document.body) return element.tagName; - - let ix = 0; - const siblings = element.parentNode?.children || new HTMLCollection(); - - for (let i = 0; i < siblings.length; i++) { - const sibling = siblings[i]; - if (sibling === element) return getXPath(element.parentElement) + '/' + element.tagName + '[' + (ix + 1) + ']'; - if (sibling.nodeType === 1 && sibling.tagName === element.tagName) ix++; - } - - return ''; -}