Skip to content

Commit 0889338

Browse files
authored
Add isLoggedIn to analytics events (#50278)
1 parent dccc21b commit 0889338

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/events/components/events.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import Cookies from 'src/frame/components/lib/cookies'
33
import { parseUserAgent } from './user-agent'
44
import { Router } from 'next/router'
5+
import { isLoggedIn } from 'src/frame/components/hooks/useHasAccount'
56

67
const COOKIE_NAME = '_docs-events'
78

@@ -18,7 +19,6 @@ let scrollDirection = 1
1819
let scrollFlipCount = 0
1920
let maxScrollY = 0
2021
let previousPath: string | undefined
21-
2222
let hoveredUrls = new Set()
2323

2424
function resetPageParams() {
@@ -158,6 +158,7 @@ export function sendEvent<T extends EventType>({
158158
page_document_type: getMetaContent('page-document-type'),
159159
page_type: getMetaContent('page-type'),
160160
status: Number(getMetaContent('status') || 0),
161+
is_logged_in: isLoggedIn(),
161162

162163
// Device information
163164
// os, os_version, browser, browser_version:

src/events/lib/schema.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ const context = {
9898
minimum: 0,
9999
maximum: 999,
100100
},
101+
is_logged_in: {
102+
type: 'boolean',
103+
description: 'Anonymous -- whether the user has github.com cookies set.',
104+
},
101105

102106
// Device information
103107
os: {

src/frame/components/hooks/useHasAccount.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ export function useHasAccount() {
1414
const [hasAccount, setHasAccount] = useState<boolean | null>(null)
1515

1616
useEffect(() => {
17-
const cookieValue = Cookies.get('color_mode')
18-
const altCookieValue = Cookies.get('preferred_color_mode')
19-
setHasAccount(Boolean(cookieValue || altCookieValue))
17+
setHasAccount(isLoggedIn())
2018
}, [])
2119

2220
return { hasAccount }
2321
}
22+
23+
export function isLoggedIn() {
24+
const cookieValue = Cookies.get('color_mode')
25+
const altCookieValue = Cookies.get('preferred_color_mode')
26+
return Boolean(cookieValue || altCookieValue)
27+
}

0 commit comments

Comments
 (0)