인기 페이지 통계와 추천 사이트 메타데이터 추가 v1.5.9
This commit is contained in:
@@ -2,9 +2,10 @@ import { z } from 'zod'
|
||||
import {
|
||||
isBotUserAgent,
|
||||
isTrackableAnalyticsPath,
|
||||
normalizePageSlugForAnalytics,
|
||||
normalizePostSlugForAnalytics
|
||||
} from '../../lib/analytics.js'
|
||||
import { getPostBySlug } from '../repositories/content-repository.js'
|
||||
import { getPageBySlug, getPostBySlug } from '../repositories/content-repository.js'
|
||||
import {
|
||||
createVisitorHashFromEvent,
|
||||
recordAnalyticsPageview
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
const pageviewInputSchema = z.object({
|
||||
path: z.string().trim().min(1).max(500),
|
||||
postSlug: z.string().trim().max(200).optional().default(''),
|
||||
pageSlug: z.string().trim().max(200).optional().default(''),
|
||||
read: z.boolean().optional().default(false)
|
||||
})
|
||||
|
||||
@@ -43,7 +45,9 @@ export const handleAnalyticsPageview = async (event) => {
|
||||
}
|
||||
|
||||
const postSlug = normalizePostSlugForAnalytics(body.postSlug)
|
||||
const pageSlug = normalizePageSlugForAnalytics(body.pageSlug)
|
||||
let postId = null
|
||||
let pageId = null
|
||||
|
||||
if (postSlug) {
|
||||
const post = await getPostBySlug(postSlug)
|
||||
@@ -53,14 +57,23 @@ export const handleAnalyticsPageview = async (event) => {
|
||||
postId = post.id
|
||||
}
|
||||
|
||||
if (!postId && pageSlug) {
|
||||
const page = await getPageBySlug(pageSlug)
|
||||
if (!page) {
|
||||
return { ok: true }
|
||||
}
|
||||
pageId = page.id
|
||||
}
|
||||
|
||||
const visitorHash = createVisitorHashFromEvent(event)
|
||||
const isReadEvent = Boolean(body.read)
|
||||
|
||||
await recordAnalyticsPageview({
|
||||
visitorHash,
|
||||
postId,
|
||||
pageId,
|
||||
recordSite: !isReadEvent,
|
||||
recordView: Boolean(postId) && !isReadEvent,
|
||||
recordView: (Boolean(postId) || Boolean(pageId)) && !isReadEvent,
|
||||
recordRead: Boolean(postId) && isReadEvent
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user