diff --git a/package.json b/package.json index 3baec636a..63e75ed27 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "dependencies": { "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", + "@livesession/sdk": "^1.1.4", "@mui/icons-material": "^5.14.0", "@mui/material": "^5.14.0", "@mui/styled-engine": "npm:@mui/styled-engine-sc@latest", diff --git a/src/app/components/page/index.tsx b/src/app/components/page/index.tsx index 085b27ac0..6e8df0d21 100644 --- a/src/app/components/page/index.tsx +++ b/src/app/components/page/index.tsx @@ -5,10 +5,12 @@ import { Header } from "app/components/header"; import { Footer } from "app/components/footer"; import Container from "@mui/material/Container"; import { useUrlFilters } from "app/hooks/useUrlFilters"; +import { useRouteListener } from "app/hooks/useRouteListener"; import { useScrollToAnchor } from "app/hooks/useScrollToAnchor"; export const Page: React.FC = () => { useUrlFilters(); + useRouteListener(); useScrollToAnchor(); return ( diff --git a/src/app/hooks/useRouteListener.tsx b/src/app/hooks/useRouteListener.tsx new file mode 100644 index 000000000..56b61a149 --- /dev/null +++ b/src/app/hooks/useRouteListener.tsx @@ -0,0 +1,16 @@ +import React from "react"; +import ls from "@livesession/sdk"; +import { useLocation } from "react-router-dom"; + +export const useRouteListener = () => { + const location = useLocation(); + + React.useEffect(() => { + if (window.location.hostname === "data.theglobalfund.org") { + ls.init(process.env.REACT_APP_LIVE_SESSION_ID as string); + ls.newPageView(); + } + }, [location.pathname]); + + return null; +}; diff --git a/yarn.lock b/yarn.lock index 7da51826e..6e2e1ecb2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1947,6 +1947,11 @@ resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz#4fc56c15c580b9adb7dc3c333a134e540b44bfb1" integrity sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw== +"@livesession/sdk@^1.1.4": + version "1.1.4" + resolved "https://registry.yarnpkg.com/@livesession/sdk/-/sdk-1.1.4.tgz#e8c020faffe4b51308a6b0bf404a1871f246a595" + integrity sha512-xyiDd3M9wx5k586BIQRcVxSJP5/2XWF9Ca1seLGRSaFoV8o270p5Mn5kpceZFN4STzlYubiMcrPZFFSNWEceVw== + "@mdx-js/react@^3.0.0": version "3.0.1" resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-3.0.1.tgz#997a19b3a5b783d936c75ae7c47cfe62f967f746"