fix types and update imports

This commit is contained in:
Ansh Nanda
2023-04-20 23:47:48 -07:00
parent 630d750a08
commit a03e376737
24 changed files with 57 additions and 60 deletions
@@ -5,11 +5,11 @@ import {
AnalyticsProvider,
useAnalytics as useAnalyticsOrig,
ClientMethods,
JsonMap,
} from '@segment/analytics-react-native'
import {RootStoreModel, AppInfo} from 'state/models/root-store'
import {useStores} from 'state/models/root-store'
import {sha256} from 'js-sha256'
import {ScreenEvent, TrackEvent} from './types'
const segmentClient = createClient({
writeKey: '8I6DsgfiSLuoONyaunGoiQM7A6y2ybdI',
@@ -21,17 +21,25 @@ export function useAnalytics() {
const methods: ClientMethods = useAnalyticsOrig()
return React.useMemo(() => {
if (store.session.hasSession) {
return methods
return {
screen: methods.screen as ScreenEvent,
track: methods.track as TrackEvent,
identify: methods.identify,
flush: methods.flush,
group: methods.group,
alias: methods.alias,
reset: methods.reset,
}
}
// dont send analytics pings for anonymous users
return {
screen: (name: string, properties?: JsonMap) => Promise<void>,
track: (event: string, properties?: JsonMap) => Promise<void>,
identify: (userId?: string, userTraits?: UserTraits) => Promise<void>,
screen: () => Promise<void>,
track: () => Promise<void>,
identify: () => Promise<void>,
flush: () => Promise<void>,
group: (groupId: string, groupTraits?: GroupTraits) => Promise<void>,
alias: (newUserId: string) => Promise<void>,
reset: (resetAnonymousId?: boolean) => Promise<void>,
group: () => Promise<void>,
alias: () => Promise<void>,
reset: () => Promise<void>,
}
}, [store, methods])
}
+17 -30
View File
@@ -1,31 +1,18 @@
import {
ClientMethods,
GroupTraits,
JsonMap,
UserTraits,
} from '@segment/analytics-react-native'
export type TrackEvent = (
event: keyof TrackPropertiesMap,
properties?: TrackPropertiesMap[keyof TrackPropertiesMap],
) => Promise<void>
export type IAnalyticsEvent = {
name: keyof TrackPropertiesMap
properties: TrackPropertiesMap[keyof TrackPropertiesMap]
}
export interface IAnalyticsProvider extends ClientMethods {
screen: (name: string, properties?: JsonMap) => Promise<void>
track: (event: string, properties?: JsonMap) => Promise<void>
identify: (userId?: string, userTraits?: UserTraits) => Promise<void>
flush: () => Promise<void>
group: (groupId: string, groupTraits?: GroupTraits) => Promise<void>
alias: (newUserId: string) => Promise<void>
reset: (resetAnonymousId?: boolean) => Promise<void>
}
export interface TrackPropertiesMap {
export type ScreenEvent = (
name: keyof ScreenPropertiesMap,
properties?: ScreenPropertiesMap[keyof ScreenPropertiesMap],
) => Promise<void>
interface TrackPropertiesMap {
// LOGIN / SIGN UP events
'Sing In': {resumedSession: boolean}
'Sign In': {resumedSession: boolean}
'Create Account': {}
'SignIn:ForgotPassowrd': {}
'SignIn:PressedSelectService': {}
'Signin:PressedForgotPassword': {}
'Signin:PressedSelectService': {}
// COMPOSER / CREATE POST events
'Create Post': {imageCount: string}
'Composer:PastedPhotos': {}
@@ -49,7 +36,7 @@ export interface TrackPropertiesMap {
'FeedItem:PostLike': {}
'FeedItem:PostDelete': {}
// PROFILE HEADER events
'ProfileHeaeder:EditProfileButtonClicked': {}
'ProfileHeader:EditProfileButtonClicked': {}
'ProfileHeader:FollowersButtonClicked': {}
'ProfileHeader:FollowsButtonClicked': {}
'ProfileHeader:ShareButtonClicked': {}
@@ -58,7 +45,7 @@ export interface TrackPropertiesMap {
'ProfileHeader:ReportAccountButtonClicked': {}
'ViewHeader:MenuButtonClicked': {}
// SETTINGS events
'Settings:SwitchAccountButtonCLicked': {}
'Settings:SwitchAccountButtonClicked': {}
'Settings:AddAccountButtonClicked': {}
'Settings:ChangeHandleButtonClicked': {}
'Settings:InvitecodesButtonClicked': {}
@@ -68,13 +55,13 @@ export interface TrackPropertiesMap {
'Menu:ItemClicked': {url: string}
'Menu:FeedbackClicked': {}
// MOBILE SHELL events
'MobileShell:ProfileButtonPressed': {}
'MobileShell:FeedButtonPressed': {}
'MobileShell:MyProfileButtonPressed': {}
'MobileShell:HomeButtonPressed': {}
'MobileShell:SearchButtonPressed': {}
'MobileShell:NotificationsButtonPressed': {}
}
export interface ScreenPropertiesMap {
interface ScreenPropertiesMap {
Login: {}
CreateAccount: {}
'Choose Account': {}