[Statsig] Track likes, reposts, follows (#3195)
* [Statsig] Track likes * Move tracking to intent * Track repost/unrepost * Track profile follows/unfollows * Less copy paste * Reorder
This commit is contained in:
parent
db79c918b2
commit
7eaa573b57
15 changed files with 125 additions and 30 deletions
|
@ -5,6 +5,7 @@ import {Shadow} from '#/state/cache/types'
|
|||
import {getAgent} from '#/state/session'
|
||||
import {updatePostShadow} from '#/state/cache/post-shadow'
|
||||
import {track} from '#/lib/analytics/analytics'
|
||||
import {logEvent, LogEvents} from '#/lib/statsig/statsig'
|
||||
import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue'
|
||||
|
||||
export const RQKEY = (postUri: string) => ['post', postUri]
|
||||
|
@ -58,12 +59,14 @@ export function useGetPost() {
|
|||
|
||||
export function usePostLikeMutationQueue(
|
||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||
logContext: LogEvents['post:like']['logContext'] &
|
||||
LogEvents['post:unlike']['logContext'],
|
||||
) {
|
||||
const postUri = post.uri
|
||||
const postCid = post.cid
|
||||
const initialLikeUri = post.viewer?.like
|
||||
const likeMutation = usePostLikeMutation()
|
||||
const unlikeMutation = usePostUnlikeMutation()
|
||||
const likeMutation = usePostLikeMutation(logContext)
|
||||
const unlikeMutation = usePostUnlikeMutation(logContext)
|
||||
|
||||
const queueToggle = useToggleMutationQueue({
|
||||
initialState: initialLikeUri,
|
||||
|
@ -111,22 +114,30 @@ export function usePostLikeMutationQueue(
|
|||
return [queueLike, queueUnlike]
|
||||
}
|
||||
|
||||
function usePostLikeMutation() {
|
||||
function usePostLikeMutation(logContext: LogEvents['post:like']['logContext']) {
|
||||
return useMutation<
|
||||
{uri: string}, // responds with the uri of the like
|
||||
Error,
|
||||
{uri: string; cid: string} // the post's uri and cid
|
||||
>({
|
||||
mutationFn: post => getAgent().like(post.uri, post.cid),
|
||||
mutationFn: post => {
|
||||
logEvent('post:like', {logContext})
|
||||
return getAgent().like(post.uri, post.cid)
|
||||
},
|
||||
onSuccess() {
|
||||
track('Post:Like')
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function usePostUnlikeMutation() {
|
||||
function usePostUnlikeMutation(
|
||||
logContext: LogEvents['post:unlike']['logContext'],
|
||||
) {
|
||||
return useMutation<void, Error, {postUri: string; likeUri: string}>({
|
||||
mutationFn: ({likeUri}) => getAgent().deleteLike(likeUri),
|
||||
mutationFn: ({likeUri}) => {
|
||||
logEvent('post:unlike', {logContext})
|
||||
return getAgent().deleteLike(likeUri)
|
||||
},
|
||||
onSuccess() {
|
||||
track('Post:Unlike')
|
||||
},
|
||||
|
@ -135,12 +146,14 @@ function usePostUnlikeMutation() {
|
|||
|
||||
export function usePostRepostMutationQueue(
|
||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||
logContext: LogEvents['post:repost']['logContext'] &
|
||||
LogEvents['post:unrepost']['logContext'],
|
||||
) {
|
||||
const postUri = post.uri
|
||||
const postCid = post.cid
|
||||
const initialRepostUri = post.viewer?.repost
|
||||
const repostMutation = usePostRepostMutation()
|
||||
const unrepostMutation = usePostUnrepostMutation()
|
||||
const repostMutation = usePostRepostMutation(logContext)
|
||||
const unrepostMutation = usePostUnrepostMutation(logContext)
|
||||
|
||||
const queueToggle = useToggleMutationQueue({
|
||||
initialState: initialRepostUri,
|
||||
|
@ -188,22 +201,32 @@ export function usePostRepostMutationQueue(
|
|||
return [queueRepost, queueUnrepost]
|
||||
}
|
||||
|
||||
function usePostRepostMutation() {
|
||||
function usePostRepostMutation(
|
||||
logContext: LogEvents['post:repost']['logContext'],
|
||||
) {
|
||||
return useMutation<
|
||||
{uri: string}, // responds with the uri of the repost
|
||||
Error,
|
||||
{uri: string; cid: string} // the post's uri and cid
|
||||
>({
|
||||
mutationFn: post => getAgent().repost(post.uri, post.cid),
|
||||
mutationFn: post => {
|
||||
logEvent('post:repost', {logContext})
|
||||
return getAgent().repost(post.uri, post.cid)
|
||||
},
|
||||
onSuccess() {
|
||||
track('Post:Repost')
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function usePostUnrepostMutation() {
|
||||
function usePostUnrepostMutation(
|
||||
logContext: LogEvents['post:unrepost']['logContext'],
|
||||
) {
|
||||
return useMutation<void, Error, {postUri: string; repostUri: string}>({
|
||||
mutationFn: ({repostUri}) => getAgent().deleteRepost(repostUri),
|
||||
mutationFn: ({repostUri}) => {
|
||||
logEvent('post:unrepost', {logContext})
|
||||
return getAgent().deleteRepost(repostUri)
|
||||
},
|
||||
onSuccess() {
|
||||
track('Post:Unrepost')
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue