feat(growth): 接入游客推荐与权益体验
- 登录:新增游客体验、登录承接和同源及请求体积校验 - 推荐与埋点:接入曝光回执、兴趣偏好和按账号隔离的重试队列 - 聊天体验:展示剩余额度、支持回答反馈及故事记忆管理 - 文档和测试:同步业务边界,覆盖队列幂等与代理登录校验
This commit is contained in:
@@ -10,6 +10,11 @@ import {
|
||||
expiredDigitalSessionPath,
|
||||
type DigitalTab,
|
||||
} from "@/lib/digital-routes";
|
||||
import { GrowthJourney } from "./growth-journey";
|
||||
import { GrowthRecommendations } from "./growth-recommendations";
|
||||
import { GrowthProfile } from "./growth-profile";
|
||||
import { GrowthChat, ReplyFeedback } from "./growth-chat";
|
||||
import { trackGrowth, flushGrowth, recommendationReceipt } from "@/lib/growth";
|
||||
import { mergeConversationSnapshot } from "@/lib/digital-recovery";
|
||||
import { useDigitalBack } from "./digital-route-history";
|
||||
import {
|
||||
@@ -550,6 +555,11 @@ export function DigitalHome({
|
||||
const c = await digital<{ id: string }>("conversations", "POST", {
|
||||
characterId: card.id,
|
||||
greetingIndex: index,
|
||||
recommendationReceiptId:
|
||||
searchParams.get("recommendation") ===
|
||||
recommendationReceipt(initial.account, card.id)
|
||||
? recommendationReceipt(initial.account, card.id)
|
||||
: undefined,
|
||||
uiDecisionId: boot?.decision.decisionId ?? undefined,
|
||||
});
|
||||
router.push(chatPath(c.id));
|
||||
@@ -922,7 +932,7 @@ export function DigitalHome({
|
||||
}>(
|
||||
`conversations/${id}/suggestions`,
|
||||
"POST",
|
||||
{ draft: draft.slice(0, 1000) },
|
||||
{ draft: draft.slice(0, 1000), requestId: crypto.randomUUID() },
|
||||
controller.signal,
|
||||
);
|
||||
if (ideasRequest.current !== controller || currentId.current !== id)
|
||||
@@ -1415,6 +1425,15 @@ export function DigitalHome({
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<GrowthJourney account={initial.account} page="chat" />
|
||||
<GrowthChat
|
||||
account={initial.account}
|
||||
conversation={conversation.id}
|
||||
busy={busy}
|
||||
onExpanded={() => {
|
||||
atBottom.current = false;
|
||||
}}
|
||||
/>
|
||||
<div className="dh-chat-intro">
|
||||
<span>✦</span>
|
||||
<p>这里是你与 {currentCard?.name} 的私人故事</p>
|
||||
@@ -1504,6 +1523,16 @@ export function DigitalHome({
|
||||
<RefreshCw size={13} /> 重新生成
|
||||
</button>
|
||||
)}
|
||||
{!busy &&
|
||||
m.role === "assistant" &&
|
||||
!!m.requestId &&
|
||||
m.status !== "generating" && (
|
||||
<ReplyFeedback
|
||||
account={initial.account}
|
||||
conversation={conversation.id}
|
||||
messageId={m.id}
|
||||
/>
|
||||
)}
|
||||
{m.status === "failed" && (
|
||||
<small className="dh-message-status">
|
||||
生成失败,可重新生成
|
||||
@@ -1701,8 +1730,18 @@ export function DigitalHome({
|
||||
✦
|
||||
</span>
|
||||
</header>
|
||||
<GrowthJourney
|
||||
account={initial.account}
|
||||
page={tab === "me" ? "profile" : tab}
|
||||
/>
|
||||
{tab === "discover" && (
|
||||
<>
|
||||
{!detail && (
|
||||
<GrowthRecommendations
|
||||
account={initial.account}
|
||||
cards={cards}
|
||||
/>
|
||||
)}
|
||||
{summaries.length > 0 && (
|
||||
<section aria-label="继续最近聊天">
|
||||
<h2>继续最近聊天</h2>
|
||||
@@ -1820,9 +1859,17 @@ export function DigitalHome({
|
||||
<h2>{onlyFavorites ? "心动收藏" : "为你发现"}</h2>
|
||||
<span>{filtered.length} 位角色 · 全部成年</span>
|
||||
</div>
|
||||
<CatalogExposure
|
||||
account={initial.account}
|
||||
cardIds={filtered.map((c) => c.id).join(",")}
|
||||
/>
|
||||
<div className="dh-card-grid">
|
||||
{filtered.map((c) => (
|
||||
<article className="dh-card" key={c.id}>
|
||||
<article
|
||||
className="dh-card"
|
||||
data-growth-card={c.id}
|
||||
key={c.id}
|
||||
>
|
||||
<Link className="dh-card-open" href={contentPath(c)}>
|
||||
<img
|
||||
src={c.cover || "/icon.svg"}
|
||||
@@ -1960,6 +2007,9 @@ export function DigitalHome({
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{tab === "me" && (
|
||||
<GrowthProfile account={initial.account} cards={cards} />
|
||||
)}
|
||||
{tab === "me" && profile && profileDraft && (
|
||||
<form className="dh-profile-form" onSubmit={saveProfile}>
|
||||
<div className="dh-profile-banner">
|
||||
@@ -2008,13 +2058,20 @@ export function DigitalHome({
|
||||
<span>
|
||||
<strong>NSFW 成人内容</strong>
|
||||
<small>
|
||||
登录账号默认开启,可随时关闭;保存后用于后续回复。
|
||||
{initial.account.startsWith("guest:")
|
||||
? "游客体验仅提供日常内容,登录后可管理账号偏好。"
|
||||
: "登录账号默认开启,可随时关闭;保存后用于后续回复。"}
|
||||
</small>
|
||||
</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
checked={profileDraft.nsfwEnabled ?? true}
|
||||
disabled={initial.account.startsWith("guest:")}
|
||||
checked={
|
||||
initial.account.startsWith("guest:")
|
||||
? false
|
||||
: (profileDraft.nsfwEnabled ?? true)
|
||||
}
|
||||
onChange={(event) =>
|
||||
setProfileDraft({
|
||||
...profileDraft,
|
||||
@@ -2054,6 +2111,14 @@ export function DigitalHome({
|
||||
)}
|
||||
{detail && (
|
||||
<div className="dh-detail-page">
|
||||
<GrowthJourney account={initial.account} page="detail" />
|
||||
{detail.kind === "character" && (
|
||||
<CardOpenTracker
|
||||
account={initial.account}
|
||||
cardId={detail.id}
|
||||
receipt={searchParams.get("recommendation")}
|
||||
/>
|
||||
)}
|
||||
<header className="dh-detail-nav">
|
||||
<button className="dh-detail-back" onClick={goBack}>
|
||||
<ArrowLeft size={18} />
|
||||
@@ -2427,3 +2492,57 @@ export function DigitalHome({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 独立详情路由打开也计入漏斗;推荐入口已上报的点击由回执事件去重链路承接。 */
|
||||
function CardOpenTracker({
|
||||
account,
|
||||
cardId,
|
||||
receipt,
|
||||
}: {
|
||||
account: string;
|
||||
cardId: string;
|
||||
receipt: string | null;
|
||||
}) {
|
||||
const seen = useRef("");
|
||||
useEffect(() => {
|
||||
if (seen.current === `${cardId}:${receipt}`) return;
|
||||
seen.current = `${cardId}:${receipt}`;
|
||||
const source =
|
||||
receipt === recommendationReceipt(account, cardId) ? receipt : undefined;
|
||||
if (source)
|
||||
trackGrowth(account, "recommendation_exposure", undefined, source);
|
||||
trackGrowth(account, "card_open", cardId, source ?? undefined);
|
||||
void flushGrowth(account);
|
||||
}, [account, cardId, receipt]);
|
||||
return null;
|
||||
}
|
||||
/** 普通发现列表也只在可见时记曝光,筛选重渲染不会重复统计同一张卡。 */
|
||||
function CatalogExposure({
|
||||
account,
|
||||
cardIds,
|
||||
}: {
|
||||
account: string;
|
||||
cardIds: string;
|
||||
}) {
|
||||
const seen = useRef(new Set<string>());
|
||||
useEffect(() => {
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
for (const entry of entries) {
|
||||
const id = (entry.target as HTMLElement).dataset.growthCard;
|
||||
if (entry.isIntersecting && id && !seen.current.has(id)) {
|
||||
seen.current.add(id);
|
||||
trackGrowth(account, "card_impression", id);
|
||||
observer.unobserve(entry.target);
|
||||
}
|
||||
}
|
||||
},
|
||||
{ threshold: 0.5 },
|
||||
);
|
||||
document
|
||||
.querySelectorAll("[data-growth-card]")
|
||||
.forEach((e) => observer.observe(e));
|
||||
return () => observer.disconnect();
|
||||
}, [account, cardIds]);
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user