diff --git a/client/.env.development.imex b/client/.env.development.imex index d1383e6ef..0b2eec83e 100644 --- a/client/.env.development.imex +++ b/client/.env.development.imex @@ -14,3 +14,5 @@ VITE_APP_SPLIT_API=ts615lqgnmk84thn72uk18uu5pgce6e0l4rc VITE_APP_INSTANCE=IMEX TEST_USERNAME="test@imex.dev" TEST_PASSWORD="test123" +VITE_PUBLIC_POSTHOG_KEY=phc_xtLmBIu0rjWwExY73Oj5DTH1bGbwq1G1Y8jnlTceien +VITE_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com \ No newline at end of file diff --git a/client/.env.development.rome b/client/.env.development.rome index 15408c90b..fb4690ff6 100644 --- a/client/.env.development.rome +++ b/client/.env.development.rome @@ -16,3 +16,5 @@ VITE_APP_COUNTRY=USA VITE_APP_INSTANCE=ROME TEST_USERNAME="test@imex.dev" TEST_PASSWORD="test123" +VITE_PUBLIC_POSTHOG_KEY=phc_xtLmBIu0rjWwExY73Oj5DTH1bGbwq1G1Y8jnlTceien +VITE_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com \ No newline at end of file diff --git a/client/.env.production.imex b/client/.env.production.imex index 22754aadf..eaa7f6c56 100644 --- a/client/.env.production.imex +++ b/client/.env.production.imex @@ -13,3 +13,5 @@ VITE_APP_AXIOS_BASE_API_URL=https://api.imex.online/ VITE_APP_REPORTS_SERVER_URL=https://reports.imex.online VITE_APP_SPLIT_API=et9pjkik6bn67he5evpmpr1agoo7gactphgk VITE_APP_INSTANCE=IMEX +VITE_PUBLIC_POSTHOG_KEY=phc_xtLmBIu0rjWwExY73Oj5DTH1bGbwq1G1Y8jnlTceien +VITE_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com \ No newline at end of file diff --git a/client/.env.production.rome b/client/.env.production.rome index 8647660c2..64b33ade8 100644 --- a/client/.env.production.rome +++ b/client/.env.production.rome @@ -13,3 +13,5 @@ VITE_APP_AXIOS_BASE_API_URL=https://api.romeonline.io/ VITE_APP_REPORTS_SERVER_URL=https://reports.romeonline.io VITE_APP_SPLIT_API=et9pjkik6bn67he5evpmpr1agoo7gactphgk VITE_APP_INSTANCE=ROME +VITE_PUBLIC_POSTHOG_KEY=phc_xtLmBIu0rjWwExY73Oj5DTH1bGbwq1G1Y8jnlTceien +VITE_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com \ No newline at end of file diff --git a/client/.env.test.imex b/client/.env.test.imex index 84167c4cb..5071568c5 100644 --- a/client/.env.test.imex +++ b/client/.env.test.imex @@ -13,3 +13,5 @@ VITE_APP_REPORTS_SERVER_URL=https://reports.test.imex.online VITE_APP_IS_TEST=true VITE_APP_SPLIT_API=ts615lqgnmk84thn72uk18uu5pgce6e0l4rc VITE_APP_INSTANCE=IMEX +VITE_PUBLIC_POSTHOG_KEY=phc_xtLmBIu0rjWwExY73Oj5DTH1bGbwq1G1Y8jnlTceien +VITE_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com \ No newline at end of file diff --git a/client/.env.test.rome b/client/.env.test.rome index bce8f4cd3..708647c14 100644 --- a/client/.env.test.rome +++ b/client/.env.test.rome @@ -13,3 +13,5 @@ VITE_APP_REPORTS_SERVER_URL=https://reports.test.romeonline.io VITE_APP_IS_TEST=true VITE_APP_SPLIT_API=ts615lqgnmk84thn72uk18uu5pgce6e0l4rc VITE_APP_INSTANCE=ROME +VITE_PUBLIC_POSTHOG_KEY=phc_xtLmBIu0rjWwExY73Oj5DTH1bGbwq1G1Y8jnlTceien +VITE_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com \ No newline at end of file diff --git a/client/package-lock.json b/client/package-lock.json index 36af48cce..ef36f1644 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -50,6 +50,7 @@ "normalize-url": "^8.0.2", "object-hash": "^3.0.0", "phone": "^3.1.59", + "posthog-js": "^1.260.2", "prop-types": "^15.8.1", "query-string": "^9.2.0", "raf-schd": "^4.0.3", @@ -9423,6 +9424,12 @@ } } }, + "node_modules/fflate": { + "version": "0.4.8", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.4.8.tgz", + "integrity": "sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==", + "license": "MIT" + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -13355,6 +13362,57 @@ "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==", "license": "MIT" }, + "node_modules/posthog-js": { + "version": "1.260.2", + "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.260.2.tgz", + "integrity": "sha512-2Q+QUz9j9+uG16wp0WcOEbezVsLZCobZyTX8NvWPMGKyPaf2lOsjbPjznsq5JiIt324B6NAqzpWYZTzvhn9k9Q==", + "license": "SEE LICENSE IN LICENSE", + "dependencies": { + "core-js": "^3.38.1", + "fflate": "^0.4.8", + "preact": "^10.19.3", + "web-vitals": "^4.2.4" + }, + "peerDependencies": { + "@rrweb/types": "2.0.0-alpha.17", + "rrweb-snapshot": "2.0.0-alpha.17" + }, + "peerDependenciesMeta": { + "@rrweb/types": { + "optional": true + }, + "rrweb-snapshot": { + "optional": true + } + } + }, + "node_modules/posthog-js/node_modules/core-js": { + "version": "3.45.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.45.1.tgz", + "integrity": "sha512-L4NPsJlCfZsPeXukyzHFlg/i7IIVwHSItR0wg0FLNqYClJ4MQYTYLbC7EkjKYRLZF2iof2MUgN0EGy7MdQFChg==", + "hasInstallScript": true, + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, + "node_modules/posthog-js/node_modules/web-vitals": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-4.2.4.tgz", + "integrity": "sha512-r4DIlprAGwJ7YM11VZp4R884m0Vmgr6EAKe3P+kO0PPj3Unqyvv59rczf6UiGcb9Z8QxZVcqKNwv/g0WNdWwsw==", + "license": "Apache-2.0" + }, + "node_modules/preact": { + "version": "10.27.1", + "resolved": "https://registry.npmjs.org/preact/-/preact-10.27.1.tgz", + "integrity": "sha512-V79raXEWch/rbqoNc7nT9E4ep7lu+mI3+sBmfRD4i1M73R3WLYcCtdI0ibxGVf4eQL8ZIz2nFacqEC+rmnOORQ==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", diff --git a/client/package.json b/client/package.json index 7c5b7bc42..bfff507a7 100644 --- a/client/package.json +++ b/client/package.json @@ -49,6 +49,7 @@ "normalize-url": "^8.0.2", "object-hash": "^3.0.0", "phone": "^3.1.59", + "posthog-js": "^1.260.2", "prop-types": "^15.8.1", "query-string": "^9.2.0", "raf-schd": "^4.0.3", diff --git a/client/src/firebase/firebase.utils.js b/client/src/firebase/firebase.utils.js index 9fb866b30..9a836eceb 100644 --- a/client/src/firebase/firebase.utils.js +++ b/client/src/firebase/firebase.utils.js @@ -5,6 +5,7 @@ import { getFirestore } from "@firebase/firestore"; import { getMessaging, getToken, onMessage } from "@firebase/messaging"; import { store } from "../redux/store"; import * as amplitude from '@amplitude/analytics-browser'; +import posthog from 'posthog-js' const config = JSON.parse(import.meta.env.VITE_APP_FIREBASE_CONFIG); initializeApp(config); @@ -96,6 +97,8 @@ export const logImEXEvent = (eventName, additionalParams, stateProp = null) => { // ); logEvent(analytics, eventName, eventParams); amplitude.track(eventName, eventParams); + posthog.capture(eventName, eventParams); + } finally { //If it fails, just keep going. } diff --git a/client/src/index.jsx b/client/src/index.jsx index 23d32134d..3c41b9f5b 100644 --- a/client/src/index.jsx +++ b/client/src/index.jsx @@ -15,6 +15,8 @@ import reportWebVitals from "./reportWebVitals"; import "./translations/i18n"; import "./utils/CleanAxios"; import * as amplitude from "@amplitude/analytics-browser"; +import { PostHogProvider } from "posthog-js/react"; + window.global ||= window; registerSW({ immediate: true }); @@ -37,7 +39,12 @@ function App() { return ( } persistor={persistor}> - + + + ); diff --git a/client/src/redux/user/user.sagas.js b/client/src/redux/user/user.sagas.js index 5841c5982..362118e71 100644 --- a/client/src/redux/user/user.sagas.js +++ b/client/src/redux/user/user.sagas.js @@ -48,7 +48,8 @@ import { validatePasswordResetSuccess } from "./user.actions"; import UserActionTypes from "./user.types"; -import * as amplitude from '@amplitude/analytics-browser'; +import * as amplitude from "@amplitude/analytics-browser"; +import posthog from "posthog-js"; const fpPromise = FingerprintJS.load(); @@ -90,7 +91,8 @@ export function* isUserAuthenticated() { } LogRocket.identify(user.email); - amplitude.setUserId(user.email) + amplitude.setUserId(user.email); + posthog.identify(user.email); const eulaQuery = yield client.query({ query: QUERY_EULA, @@ -336,7 +338,7 @@ export function* SetAuthLevelFromShopDetails({ payload }) { } try { - amplitude.setGroup('Shop', payload.shopname); + amplitude.setGroup("Shop", payload.shopname); window.$crisp.push(["set", "user:company", [payload.shopname]]); window.$crisp.push(["set", "session:segments", [[`region:${payload.region_config}`]]]); if (authRecord[0] && authRecord[0].user.validemail) {