From e59d656e0ec41beeed2cb15713f1a020ed55da1a Mon Sep 17 00:00:00 2001 From: nklhrstv Date: Wed, 20 Jan 2021 18:40:32 +0200 Subject: [PATCH] send LocationPathChanged analytics event to core --- src/App/App.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/App/App.js b/src/App/App.js index 9ebd40527..08e7acc3b 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -28,6 +28,22 @@ const App = () => { }), []); const [coreInitialized, setCoreInitialized] = React.useState(false); const [shellInitialized, setShellInitialized] = React.useState(false); + React.useEffect(() => { + let prevPath = window.location.hash.slice(1); + const onLocationHashChange = () => { + if (services.core.active) { + services.core.transport.analytics({ + event: 'LocationPathChanged', + args: { prevPath } + }); + } + prevPath = window.location.hash.slice(1); + }; + window.addEventListener('hashchange', onLocationHashChange); + return () => { + window.removeEventListener('hashchange', onLocationHashChange); + }; + }, []); React.useEffect(() => { const onCoreStateChanged = () => { setCoreInitialized(services.core.active);