@fourierhq/sdk (英语)
开源产品分析 SDK. Drop- in符合 Side 分析器.js API: identify, (中文(简体) ), track, (中文(简体) ), page, (中文(简体) ), group, (中文(简体) ), alias, (中文(简体) ), reset, (中文(简体) ), user(), (中文(简体) ), ready(), (中文(简体) ), on(), (中文(简体) ), trackLink, (中文(简体) ), trackForm,源的中间件和相同 ajs_* cookie,所以一个已有的Side安装会保留其匿名的ID.
它跟一个 傅里叶 在 Vercel 上,您可以自行运行服务器,在下方使用 ClickHouse 。 SDK为MIT;服务器为AGPL-3.0.
pnpm add @fourierhq/sdk
Next.js (App路由器) (英语)
// app/layout.tsx
import { FourierProvider } from "@fourierhq/sdk/next";
export default function RootLayout({ children }) {
return (
<html>
<body>
<FourierProvider writeKey={process.env.NEXT_PUBLIC_FOURIER_WRITE_KEY!} host={process.env.NEXT_PUBLIC_FOURIER_HOST!}>
{children}
</FourierProvider>
</body>
</html>
);
}
"use client";
import { useFourier } from "@fourierhq/sdk/next";
export function UpgradeButton() {
const fourier = useFourier();
return <button onClick={() => fourier.track("Upgrade Clicked", { plan: "pro" })}>Upgrade</button>;
}
在路由更改时自动跟踪页面视图.
浏览器中的任何地方
import fourier from "@fourierhq/sdk";
fourier.init({ writeKey: "...", host: "https://analytics.example.com" });
fourier.identify("user_123", { email: "[email protected]", plan: "pro" });
fourier.group("acme", { name: "Acme Inc", plan: "enterprise" });
fourier.track("Report Exported", { format: "csv" });
服务器( API 路由、 服务器动作、 cron)
import { FourierServer } from "@fourierhq/sdk/server";
const fourier = new FourierServer({ writeKey: process.env.FOURIER_WRITE_KEY!, host: process.env.FOURIER_HOST! });
fourier.track({ userId: "user_123", event: "Invoice Paid", properties: { amount: 4900 } });
await fourier.closeAndFlush();
几个地点,一个身份
fourier.init({
writeKey, // this site's own source key from the dashboard
host,
cookieDomain: ".example.com", // subdomains share the anonymous id via the cookie
crossDomain: ["example.io"], // links to other domains carry it as ?ajs_aid=… (and ?ajs_uid=… when identified)
});
fourier.decorateUrl("https://app.example.io/signup"); // for URLs you build yourself
fourier.newSession(); // force a new session (attribution touch)
公司/工作场所
group(groupId, traits) 注册一个公司,并链接当前用户。 之后的每一个事件都带有 context.groupId,因此仪表板和查询API可以按公司滚动用户和事件.