From f886b9f8678b87837703278cbde7410dcd545ae3 Mon Sep 17 00:00:00 2001 From: vrtnis <123119434+vrtnis@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:53:19 -0700 Subject: [PATCH] Add Pendo integration with initialization (#373) * Add Pendo integration with initialization and typescript types * Fix formatting issues --- frontend/index.html | 15 ++++++++++++++- frontend/src/App.tsx | 33 ++++++++++++++++++++++++++++++++- frontend/src/pendo.d.ts | 23 +++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 frontend/src/pendo.d.ts diff --git a/frontend/index.html b/frontend/index.html index e1945184..cabbd9c2 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -21,6 +21,19 @@ + + K-Scale Store @@ -29,4 +42,4 @@ - + \ No newline at end of file diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 31a33d98..c9693bba 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,4 +1,10 @@ -import { Route, BrowserRouter as Router, Routes } from "react-router-dom"; +import { useEffect } from "react"; +import { + Route, + BrowserRouter as Router, + Routes, + useLocation, +} from "react-router-dom"; import "App.css"; @@ -25,6 +31,29 @@ import NotFound from "components/pages/NotFound"; import Profile from "components/pages/Profile"; import Signup from "components/pages/Signup"; +const PendoInitializer = () => { + const location = useLocation(); // Hook to get current route + + useEffect(() => { + if (window.pendo) { + window.pendo.initialize({ + visitor: { id: "" }, // Leave empty for anonymous tracking + account: { id: "" }, + }); + console.log("Pendo initialized"); + } + }, []); + + useEffect(() => { + // Track page views when the route changes + if (window.pendo) { + window.pendo.pageLoad(); // Notify Pendo of page transitions + } + }, [location.pathname]); + + return null; // This component only handles Pendo initialization and page tracking +}; + const App = () => { return ( @@ -34,6 +63,8 @@ const App = () => {
+ {" "} + {/* This component is where Pendo is initialized */}
diff --git a/frontend/src/pendo.d.ts b/frontend/src/pendo.d.ts new file mode 100644 index 00000000..a93000c5 --- /dev/null +++ b/frontend/src/pendo.d.ts @@ -0,0 +1,23 @@ +interface PendoVisitor { + id: string; +} + +interface PendoAccount { + id: string; +} + +interface Pendo { + initialize: (options: { + visitor: PendoVisitor; + account?: PendoAccount; + }) => void; + pageLoad: () => void; +} + +declare global { + interface Window { + pendo: Pendo; + } +} + +export {};