数据分析
配置 OpenPanel,只在关键漏斗节点按需埋点
数据分析
EasyStarter 移动端使用 OpenPanel 作为数据分析方案 —— 开源、隐私友好、支持自托管,未配置 Client ID 或 Client Secret 时自动跳过初始化。
移动端默认不监听每次页面切换。建议只在关键漏斗节点显式埋点,例如首次完成 onboarding、登录成功、订阅开始、核心生成任务完成、提交作品等。这样既能看清转化,也不会把免费额度消耗在低价值的普通导航事件上。
注册 OpenPanel 并创建项目
官方文档:React Native SDK
- 前往 openpanel.dev 注册账号
- 在 Dashboard 中点击 Create Project
- 填写 Project name(可与 Web 端共用同一个项目,方便跨端漏斗分析)
- 开启 App,关闭暂时不需要的 Website、Backend / API
- 点击 Create project
- 创建完成后,在项目的客户端信息中复制 App 对应的 Client ID 和 Client Secret
填入环境变量
本地开发(apps/native/.env.development.local):
由 expo start 在开发态加载,仅对本地 dev server 生效,不进入任何打包产物:
EXPO_PUBLIC_OPENPANEL_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
EXPO_PUBLIC_OPENPANEL_CLIENT_SECRET=xxxxxxxx-client-secret本地生产构建(apps/native/.env.production):
当你在本地以生产模式构建(例如 eas build --local --profile production、expo prebuild 后的原生构建,或 expo export 生成 OTA bundle)时,Expo 会按 NODE_ENV=production 自动加载这个文件。先从 .env.production.example 拷贝一份:
cp apps/native/.env.production.example apps/native/.env.production然后填入对应的 Client ID 和 Client Secret:
EXPO_PUBLIC_OPENPANEL_CLIENT_ID=xxxxxxxx-prod-client-id
EXPO_PUBLIC_OPENPANEL_CLIENT_SECRET=xxxxxxxx-prod-client-secret
.env.production已加入.gitignore,不会被提交。当你使用 EAS 云端构建时,eas.json的env字段优先级更高,会覆盖文件中的同名变量——所以云端构建只看下面那份配置即可。
云端构建(apps/native/eas.json 的 env 字段):
eas.json 中有三个 build profile(development、preview、production),每个 profile 都有独立的 env,需要按需各自填入 Client ID 和 Client Secret。如果想区分线上 / 测试数据,建议在 OpenPanel 控制台为不同环境分别创建独立的 Client,避免事件混到一起。
{
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"env": {
// ...
"EXPO_PUBLIC_OPENPANEL_CLIENT_ID": "xxxxxxxx-dev-client-id",
"EXPO_PUBLIC_OPENPANEL_CLIENT_SECRET": "xxxxxxxx-dev-client-secret"
}
},
"preview": {
"distribution": "internal",
"channel": "preview",
"env": {
// ...
"EXPO_PUBLIC_OPENPANEL_CLIENT_ID": "xxxxxxxx-preview-client-id",
"EXPO_PUBLIC_OPENPANEL_CLIENT_SECRET": "xxxxxxxx-preview-client-secret"
}
},
"production": {
"autoIncrement": true,
"channel": "production",
"env": {
// ...
"EXPO_PUBLIC_OPENPANEL_CLIENT_ID": "xxxxxxxx-prod-client-id",
"EXPO_PUBLIC_OPENPANEL_CLIENT_SECRET": "xxxxxxxx-prod-client-secret"
}
}
}
}按需上报关键事件
Native 端提供显式调用的统计 helper。只在关键业务节点调用即可:
import { trackOpenPanelEvent } from "@/lib/analytics/openpanel";
trackOpenPanelEvent("onboarding_completed", {
source: "welcome_flow",
});如果某个 screen 是漏斗的一步,也可以手动记录 screen view:
import { trackOpenPanelScreenView } from "@/lib/analytics/openpanel";
trackOpenPanelScreenView("/paywall");不要默认监听所有路由变化。先围绕 3-5 个关键漏斗节点埋点,再根据真实问题补事件。