[APP-511] metrics overhaul: frontend work (#506)
* WIP * fix types and update imports * wip * tagged events that should be server side * remove server-side analytics * remove useless import * add additional profile header events * remove useless import * track follow/unfollow clicks * add missing types
This commit is contained in:
parent
1695ae34db
commit
17e7590bcd
33 changed files with 156 additions and 41 deletions
|
@ -4,10 +4,12 @@ import {
|
|||
createClient,
|
||||
AnalyticsProvider,
|
||||
useAnalytics as useAnalyticsOrig,
|
||||
ClientMethods,
|
||||
} 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',
|
||||
|
@ -16,20 +18,28 @@ const segmentClient = createClient({
|
|||
|
||||
export function useAnalytics() {
|
||||
const store = useStores()
|
||||
const methods = useAnalyticsOrig()
|
||||
const methods: ClientMethods = useAnalyticsOrig()
|
||||
return React.useMemo(() => {
|
||||
if (store.session.hasSession) {
|
||||
return methods
|
||||
return {
|
||||
screen: methods.screen as ScreenEvent, // ScreenEvents defines all the possible screen names
|
||||
track: methods.track as TrackEvent, // TrackEvents defines all the possible track events and their properties
|
||||
identify: methods.identify,
|
||||
flush: methods.flush,
|
||||
group: methods.group,
|
||||
alias: methods.alias,
|
||||
reset: methods.reset,
|
||||
}
|
||||
}
|
||||
// dont send analytics pings for anonymous users
|
||||
return {
|
||||
screen: () => {},
|
||||
track: () => {},
|
||||
identify: () => {},
|
||||
flush: () => {},
|
||||
group: () => {},
|
||||
alias: () => {},
|
||||
reset: () => {},
|
||||
screen: () => Promise<void>,
|
||||
track: () => Promise<void>,
|
||||
identify: () => Promise<void>,
|
||||
flush: () => Promise<void>,
|
||||
group: () => Promise<void>,
|
||||
alias: () => Promise<void>,
|
||||
reset: () => Promise<void>,
|
||||
}
|
||||
}, [store, methods])
|
||||
}
|
98
src/lib/analytics/types.ts
Normal file
98
src/lib/analytics/types.ts
Normal file
|
@ -0,0 +1,98 @@
|
|||
export type TrackEvent = (
|
||||
event: keyof TrackPropertiesMap,
|
||||
properties?: TrackPropertiesMap[keyof TrackPropertiesMap],
|
||||
) => Promise<void>
|
||||
|
||||
export type ScreenEvent = (
|
||||
name: keyof ScreenPropertiesMap,
|
||||
properties?: ScreenPropertiesMap[keyof ScreenPropertiesMap],
|
||||
) => Promise<void>
|
||||
interface TrackPropertiesMap {
|
||||
// LOGIN / SIGN UP events
|
||||
'Sign In': {resumedSession: boolean} // CAN BE SERVER
|
||||
'Create Account': {} // CAN BE SERVER
|
||||
'Signin:PressedForgotPassword': {}
|
||||
'Signin:PressedSelectService': {}
|
||||
// COMPOSER / CREATE POST events
|
||||
'Create Post': {imageCount: string} // CAN BE SERVER
|
||||
'Composer:PastedPhotos': {}
|
||||
'Composer:CameraOpened': {}
|
||||
'Composer:GalleryOpened': {}
|
||||
'HomeScreen:PressCompose': {}
|
||||
'ProfileScreen:PressCompose': {}
|
||||
// EDIT PROFILE events
|
||||
'EditHandle:ViewCustomForm': {}
|
||||
'EditHandle:ViewProvidedForm': {}
|
||||
'EditHandle:SetNewHandle': {}
|
||||
'EditProfile:AvatarSelected': {}
|
||||
'EditProfile:BannerSelected': {}
|
||||
'EditProfile:Save': {} // CAN BE SERVER
|
||||
// FEED events
|
||||
'Feed:onRefresh': {}
|
||||
'Feed:onEndReached': {}
|
||||
// FEED ITEM events
|
||||
'FeedItem:PostReply': {} // CAN BE SERVER
|
||||
'FeedItem:PostRepost': {} // CAN BE SERVER
|
||||
'FeedItem:PostLike': {} // CAN BE SERVER
|
||||
'FeedItem:PostDelete': {} // CAN BE SERVER
|
||||
'FeedItem:ThreadMute': {} // CAN BE SERVER
|
||||
// PROFILE HEADER events
|
||||
'ProfileHeader:EditProfileButtonClicked': {}
|
||||
'ProfileHeader:FollowersButtonClicked': {}
|
||||
'ProfileHeader:FollowsButtonClicked': {}
|
||||
'ProfileHeader:ShareButtonClicked': {}
|
||||
'ProfileHeader:MuteAccountButtonClicked': {}
|
||||
'ProfileHeader:UnmuteAccountButtonClicked': {}
|
||||
'ProfileHeader:ReportAccountButtonClicked': {}
|
||||
'ProfileHeader:AddToListsButtonClicked': {}
|
||||
'ProfileHeader:BlockAccountButtonClicked': {}
|
||||
'ProfileHeader:UnblockAccountButtonClicked': {}
|
||||
'ProfileHeader:FollowButtonClicked': {}
|
||||
'ProfileHeader:UnfollowButtonClicked': {}
|
||||
'ViewHeader:MenuButtonClicked': {}
|
||||
// SETTINGS events
|
||||
'Settings:SwitchAccountButtonClicked': {}
|
||||
'Settings:AddAccountButtonClicked': {}
|
||||
'Settings:ChangeHandleButtonClicked': {}
|
||||
'Settings:InvitecodesButtonClicked': {}
|
||||
'Settings:ContentfilteringButtonClicked': {}
|
||||
'Settings:SignOutButtonClicked': {}
|
||||
'Settings:ContentlanguagesButtonClicked': {}
|
||||
// MENU events
|
||||
'Menu:ItemClicked': {url: string}
|
||||
'Menu:FeedbackClicked': {}
|
||||
// MOBILE SHELL events
|
||||
'MobileShell:MyProfileButtonPressed': {}
|
||||
'MobileShell:HomeButtonPressed': {}
|
||||
'MobileShell:SearchButtonPressed': {}
|
||||
'MobileShell:NotificationsButtonPressed': {}
|
||||
'MobileShell:FeedsButtonPressed': {}
|
||||
// LISTS events
|
||||
'Lists:onRefresh': {}
|
||||
'Lists:onEndReached': {}
|
||||
'CreateMuteList:AvatarSelected': {}
|
||||
'CreateMuteList:Save': {} // CAN BE SERVER
|
||||
// CUSTOM FEED events
|
||||
'MultiFeed:onEndReached': {}
|
||||
'MultiFeed:onRefresh': {}
|
||||
// MODERATION events
|
||||
'Moderation:ContentfilteringButtonClicked': {}
|
||||
}
|
||||
|
||||
interface ScreenPropertiesMap {
|
||||
Login: {}
|
||||
CreateAccount: {}
|
||||
'Choose Account': {}
|
||||
'Signin:ForgotPassword': {}
|
||||
'Signin:SetNewPasswordForm': {}
|
||||
'Signin:PasswordUpdatedForm': {}
|
||||
Feed: {}
|
||||
Notifications: {}
|
||||
Profile: {}
|
||||
Settings: {}
|
||||
AppPasswords: {}
|
||||
Moderation: {}
|
||||
BlockedAccounts: {}
|
||||
MutedAccounts: {}
|
||||
SavedFeeds: {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue