From 8fdb008e57694273c95d47925bebd6201441c726 Mon Sep 17 00:00:00 2001 From: spicermatthews <120526656+spicermatthews@users.noreply.github.com> Date: Thu, 21 Mar 2024 01:07:26 -0700 Subject: [PATCH] Made it so we log to v5 on tab opens (#571) Co-authored-by: Spicer Matthews --- src/pages/index.js | 25 +++++++++++++++++++++++++ src/utils/relayEnvironment.js | 3 +++ 2 files changed, 28 insertions(+) diff --git a/src/pages/index.js b/src/pages/index.js index 0154255a..60446493 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -430,6 +430,31 @@ const Index = ({ data: fallbackData, userAgent }) => { const showAchievements = showMockAchievements() const enableBackgroundImages = showBackgroundImages() + const logTabWithV5 = async () => { + const userToken = localStorageMgr.getItem('access_token') + + // This should not happen + if (!userToken) { + return + } + + const headers = { + Accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: `Bearer ${userToken}`, + } + + fetch(`${process.env.NEXT_PUBLIC_API_ENDPOINT}/api/v1/tab/log`, { + method: 'POST', + headers, + body: JSON.stringify({}), + }) + } + + useEffect(() => { + logTabWithV5() + }, []) + // No scrolling on this home page. useEffect(() => { // Add the style when the component mounts diff --git a/src/utils/relayEnvironment.js b/src/utils/relayEnvironment.js index 28697a67..3c892836 100644 --- a/src/utils/relayEnvironment.js +++ b/src/utils/relayEnvironment.js @@ -5,6 +5,7 @@ import { Environment, Network, RecordSource, Store } from 'relay-runtime' import { isServerSide } from 'src/utils/ssr' import logger from 'src/utils/logger' import ensureValuesAreDefined from 'src/utils/ensureValuesAreDefined' +import localStorageManager from 'src/utils/localstorage-mgr' try { ensureValuesAreDefined(process.env.NEXT_PUBLIC_RELAY_ENDPOINT) @@ -86,6 +87,8 @@ const createFetchQuery = ({ getIdToken }) => { const { currentUser } = firebase.auth() if (currentUser) { token = await currentUser.getIdToken() + + localStorageManager.setItem('access_token', token) } }