Skip to content

Commit

Permalink
Made it so we log to v5 on tab opens
Browse files Browse the repository at this point in the history
  • Loading branch information
Spicer Matthews committed Mar 21, 2024
1 parent 8a6a80f commit 9a8f17f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/utils/relayEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -86,6 +87,8 @@ const createFetchQuery = ({ getIdToken }) => {
const { currentUser } = firebase.auth()
if (currentUser) {
token = await currentUser.getIdToken()

localStorageManager.setItem('access_token', token)
}
}

Expand Down

0 comments on commit 9a8f17f

Please sign in to comment.