2022-04-19 05:16:08 +00:00
|
|
|
import { doc, collection, setDoc } from 'firebase/firestore'
|
|
|
|
|
|
|
|
import { db } from './init'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { ClickEvent, LatencyEvent, View } from 'common/tracking'
|
2022-04-19 05:16:08 +00:00
|
|
|
|
2022-07-21 07:38:26 +00:00
|
|
|
export async function trackView(userId: string, contractId: string) {
|
|
|
|
const ref = doc(collection(db, 'private-users', userId, 'views'))
|
2022-04-19 05:16:08 +00:00
|
|
|
|
|
|
|
const view: View = {
|
|
|
|
contractId,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
}
|
|
|
|
|
|
|
|
return await setDoc(ref, view)
|
|
|
|
}
|
|
|
|
|
2022-07-21 07:38:26 +00:00
|
|
|
export async function trackClick(userId: string, contractId: string) {
|
|
|
|
const ref = doc(collection(db, 'private-users', userId, 'events'))
|
2022-04-19 05:16:08 +00:00
|
|
|
|
|
|
|
const clickEvent: ClickEvent = {
|
|
|
|
type: 'click',
|
|
|
|
contractId,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
}
|
|
|
|
|
|
|
|
return await setDoc(ref, clickEvent)
|
|
|
|
}
|
2022-04-21 06:00:08 +00:00
|
|
|
|
|
|
|
export async function trackLatency(
|
2022-07-21 07:38:26 +00:00
|
|
|
userId: string,
|
2022-04-21 06:00:08 +00:00
|
|
|
type: 'feed' | 'portfolio',
|
|
|
|
latency: number
|
|
|
|
) {
|
2022-07-21 07:38:26 +00:00
|
|
|
const ref = doc(collection(db, 'private-users', userId, 'latency'))
|
2022-04-21 06:00:08 +00:00
|
|
|
|
|
|
|
const latencyEvent: LatencyEvent = {
|
|
|
|
type,
|
|
|
|
latency,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
}
|
|
|
|
|
|
|
|
return await setDoc(ref, latencyEvent)
|
|
|
|
}
|