Skip to content

Commit 5b44bc8

Browse files
committed
feat: Add user connection and disconnection tracking to analytics
1 parent dfcd2b0 commit 5b44bc8

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/features/auth/components/AuthModal.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IoMdClose } from 'react-icons/io'
55
import ReactModal from 'react-modal'
66
import toast from 'react-simple-toasts'
77
import { useAuth } from 'src/features/auth'
8+
import { trackUserConnect } from 'src/lib/analytics'
89
import { firebaseAuth, githubAuthProvider, googleAuthProvider } from 'src/lib/firebase'
910
import './authModal.css'
1011

@@ -24,6 +25,7 @@ export const AuthModal = ({ showAuth }: AuthModalProps) => {
2425
const name = result.user.displayName
2526
const imageURL = result.user.photoURL
2627
if (idToken && name && email && imageURL) {
28+
trackUserConnect(providerName)
2729
closeAuthModal()
2830
initState({
2931
idToken: idToken,

src/features/auth/hooks/useAuth.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { AuthModalStore, AuthStore } from 'src/features/auth'
2+
import { trackUserDisconnect } from 'src/lib/analytics'
23

34
export const useAuth = () => {
45
const { isAuthModalOpen, openAuthModal, closeAuthModal } = AuthModalStore()
56
const authStore = AuthStore()
67
const { idToken, user, initState, clear } = authStore
8+
79
const isConnected = () => user != null
10+
811
const logout = () => {
12+
trackUserDisconnect()
913
clear()
1014
}
1115

src/lib/analytics.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ enum Verbs {
4444
DISABLE = 'Disable',
4545
SHARE = 'Share',
4646
COPY = 'Copy',
47+
CONNECT = 'Connect',
48+
DISCONNECT = 'Disconnect',
4749
}
4850

4951
export enum Attributes {
@@ -376,6 +378,21 @@ export const trackLinkCopy = ({
376378
})
377379
}
378380

381+
export const trackUserConnect = (provider: string) => {
382+
trackEvent({
383+
object: Objects.USER,
384+
verb: Verbs.CONNECT,
385+
attributes: { [Attributes.PROVIDER]: provider },
386+
})
387+
}
388+
389+
export const trackUserDisconnect = () => {
390+
trackEvent({
391+
object: Objects.USER,
392+
verb: Verbs.DISCONNECT,
393+
})
394+
}
395+
379396
// Identification
380397

381398
export const identifyUserLanguages = (languages: string[]) => {

0 commit comments

Comments
 (0)