From 7058484420592ed06111e34bb3325a400f521bc5 Mon Sep 17 00:00:00 2001 From: jffarge Date: Fri, 25 Jun 2021 16:46:00 +0200 Subject: [PATCH] docs: :bug: log amplitude only when location pathname change Signed-off-by: jffarge --- website/src/theme/DocPage/index.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/website/src/theme/DocPage/index.js b/website/src/theme/DocPage/index.js index 8e226730..ddfd5807 100644 --- a/website/src/theme/DocPage/index.js +++ b/website/src/theme/DocPage/index.js @@ -148,6 +148,7 @@ function DocPage(props) { if (typeof window !== "undefined") return JSON.parse(window.localStorage.getItem('user')) })()) + useEffect(async () => { if (!isEmpty(authQuery) && userAccessStatus === null) { //callback after successful auth with github const user = await checkUserCollaboratorStatus(authQuery.code); @@ -159,6 +160,16 @@ function DocPage(props) { setIsLoading(false) }, [userAccessStatus]) + useEffect(() => { + import('amplitude-js').then(amplitude => { + if (userAccessStatus?.login) { + var amplitudeInstance = amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE_ID, userAccessStatus?.login.toLowerCase(), { + apiEndpoint: `${window.location.hostname}/t` + }); + amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": window.location.pathname }); + } + }) + }, [window.location.pathname]) if (isLoading) return @@ -171,16 +182,6 @@ function DocPage(props) { ) } - - // TODO: DISABLE FOR LOCALHOST ENV - import('amplitude-js').then(amplitude => { - if (userAccessStatus?.login) { - var amplitudeInstance = amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE_ID, userAccessStatus?.login.toLowerCase(), { - apiEndpoint: `${window.location.hostname}/t` - }); - amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": window.location.pathname }); - } - }) } // END CUSTOM DOCPAGE