Merge pull request #4015 from omnivore-app/content-fetch-event

fix: only send content_fetch_failure event to analytics
This commit is contained in:
Hongbo Wu
2024-05-31 12:58:13 +08:00
committed by GitHub
2 changed files with 7 additions and 9 deletions

View File

@ -202,11 +202,9 @@ const rankCandidates = async (
return candidates
}
const unscoredCandidates = candidates.filter((item) => item.score === 0)
const data = {
user_id: userId,
items: unscoredCandidates.reduce((acc, item) => {
items: candidates.reduce((acc, item) => {
acc[item.id] = {
library_item_id: item.id,
title: item.title,
@ -227,14 +225,14 @@ const rankCandidates = async (
}, {} as Record<string, Feature>),
}
const newScores = await getScores(data)
const scores = await getScores(data)
// update scores for candidates
unscoredCandidates.forEach((item) => {
item.score = newScores[item.id]['score'] || 0
candidates.forEach((item) => {
item.score = scores[item.id]['score'] || 0
})
// rank candidates by score in ascending order
candidates.sort((a, b) => a.score - b.score)
// rank candidates by score in descending order
candidates.sort((a, b) => b.score - a.score)
return candidates
}

View File

@ -17,7 +17,7 @@ class PostHogClient implements AnalyticClient {
}
capture(userIds: string[], { properties, result }: AnalyticEvent) {
if (process.env.SEND_ANALYTICS) {
if (process.env.SEND_ANALYTICS && result === 'failure') {
userIds.forEach((userId) => {
this.client.capture({
distinctId: userId,