send analytic events for each digest channel

This commit is contained in:
Hongbo Wu
2024-05-09 11:30:28 +08:00
parent 2f00c4dbc6
commit e1990258f1
2 changed files with 17 additions and 3 deletions

View File

@ -28,6 +28,7 @@ import {
findUserAndPersonalization, findUserAndPersonalization,
sendPushNotifications, sendPushNotifications,
} from '../../services/user' } from '../../services/user'
import { analytics } from '../../utils/analytics'
import { enqueueSendEmail } from '../../utils/createTask' import { enqueueSendEmail } from '../../utils/createTask'
import { wordsCount } from '../../utils/helpers' import { wordsCount } from '../../utils/helpers'
import { logger } from '../../utils/logger' import { logger } from '../../utils/logger'
@ -716,15 +717,27 @@ const sendToChannels = async (
deduplicateChannels.map(async (channel) => { deduplicateChannels.map(async (channel) => {
switch (channel) { switch (channel) {
case 'push': case 'push':
return sendPushNotification(user.id, digest) await sendPushNotification(user.id, digest)
break
case 'email': case 'email':
return sendEmail(user, digest, deduplicateChannels) await sendEmail(user, digest, deduplicateChannels)
break
case 'library': case 'library':
return moveDigestToLibrary(user, digest) await moveDigestToLibrary(user, digest)
break
default: default:
logger.error('Unknown channel', { channel }) logger.error('Unknown channel', { channel })
return return
} }
analytics.capture({
distinctId: user.id,
event: 'digest_created',
properties: {
channel,
digestId: digest.id,
},
})
}) })
) )
} }

View File

@ -30,6 +30,7 @@ class PostHogClient implements AnalyticClient {
properties: { properties: {
...properties, ...properties,
client, client,
env: env.server.apiEnv,
}, },
}) })
} }