Only send analytics events when the user is logged in (web)
This commit is contained in:
@@ -20,6 +20,7 @@ export function useAnalytics() {
|
|||||||
if (store.session.hasSession) {
|
if (store.session.hasSession) {
|
||||||
return methods
|
return methods
|
||||||
}
|
}
|
||||||
|
// dont send analytics pings for anonymous users
|
||||||
return {
|
return {
|
||||||
screen: () => {},
|
screen: () => {},
|
||||||
track: () => {},
|
track: () => {},
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {createClient, AnalyticsProvider} from '@segment/analytics-react'
|
import {
|
||||||
|
createClient,
|
||||||
|
AnalyticsProvider,
|
||||||
|
useAnalytics as useAnalyticsOrig,
|
||||||
|
} from '@segment/analytics-react'
|
||||||
import {RootStoreModel} from 'state/models/root-store'
|
import {RootStoreModel} from 'state/models/root-store'
|
||||||
|
import {useStores} from 'state/models/root-store'
|
||||||
|
|
||||||
const segmentClient = createClient(
|
const segmentClient = createClient(
|
||||||
{
|
{
|
||||||
@@ -16,7 +21,26 @@ const segmentClient = createClient(
|
|||||||
)
|
)
|
||||||
export const track = segmentClient?.track?.bind?.(segmentClient)
|
export const track = segmentClient?.track?.bind?.(segmentClient)
|
||||||
|
|
||||||
export {useAnalytics} from '@segment/analytics-react'
|
export function useAnalytics() {
|
||||||
|
const store = useStores()
|
||||||
|
const methods = useAnalyticsOrig()
|
||||||
|
return React.useMemo(() => {
|
||||||
|
if (store.session.hasSession) {
|
||||||
|
console.log('real')
|
||||||
|
return methods
|
||||||
|
}
|
||||||
|
// dont send analytics pings for anonymous users
|
||||||
|
return {
|
||||||
|
screen: () => {},
|
||||||
|
track: () => {},
|
||||||
|
identify: () => {},
|
||||||
|
flush: () => {},
|
||||||
|
group: () => {},
|
||||||
|
alias: () => {},
|
||||||
|
reset: () => {},
|
||||||
|
}
|
||||||
|
}, [store, methods])
|
||||||
|
}
|
||||||
|
|
||||||
export function init(_store: RootStoreModel) {
|
export function init(_store: RootStoreModel) {
|
||||||
// no init needed on web
|
// no init needed on web
|
||||||
|
|||||||
Reference in New Issue
Block a user