Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

wip

Kiran K9db82ae9b5c8
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
index 76e3825939..ee1e896eba 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
@@ -1,24 +1,18 @@
-import { getConversionEvents } from "@/lib/actions/get-conversion-events";
-import { getReferralLink } from "@/lib/actions/get-referral-link";
-import { getTotalEvents } from "@/lib/actions/get-total-events";
import { EventType } from "@/lib/analytics/types";
import {
REFERRAL_CLICKS_QUOTA_BONUS,
REFERRAL_CLICKS_QUOTA_BONUS_MAX,
REFERRAL_REVENUE_SHARE,
} from "@/lib/referrals/constants";
-import { EventListSkeleton } from "@dub/blocks";
import { Wordmark } from "@dub/ui";
import { Check } from "@dub/ui/src/icons";
-import { nFormatter, randomValue } from "@dub/utils";
-import { subDays } from "date-fns";
+import { nFormatter } from "@dub/utils";
import { Suspense } from "react";
-import { ActivityList } from "./activity-list";
import { EventTabs } from "./event-tabs";
+import { Events } from "./events";
import { HeroBackground } from "./hero-background";
import ReferralsPageClient from "./page-client";
import ReferralLink, { ReferralLinkSkeleton } from "./referral-link";
-import { Stats } from "./stats";
export const revalidate = 0;
@@ -93,96 +87,20 @@ export default function ReferralsPage({
</p>
</a>
</div>
- <div className="mt-8">
- <Stats slug={slug} />
- </div>
+
+ {/* <div className="mt-8">
+ <Stats />
+ </div> */}
+
+ {/* Events */}
<div className="mt-12">
<div className="mb-5 flex flex-wrap items-end justify-between gap-4">
<h2 className="text-xl font-semibold text-gray-800">Activity</h2>
<EventTabs />
</div>
- <Suspense
- key={`${slug}-${event}-${page}`}
- fallback={<EventListSkeleton />}
- >
- <ActivityListRSC slug={slug} event={event} page={page} />
- </Suspense>
+ <Events />
</div>
</div>
</ReferralsPageClient>
);
}
-
-const placeholderEvents = {
- clicks: [...Array(10)].map(
- (_, idx) =>
- ({
- timestamp: subDays(new Date(), idx).toISOString(),
- click_id: "1",
- link_id: "1",
- domain: "refer.dub.co",
- key: "",
- url: "https://dub.co",
- country: randomValue(["US", "GB", "CA", "AU", "DE", "FR", "ES", "IT"]),
- }) as any,
- ),
- leads: [...Array(10)].map(
- (_, idx) =>
- ({
- timestamp: subDays(new Date(), idx).toISOString(),
- click_id: "1",
- link_id: "1",
- domain: "refer.dub.co",
- key: "",
- url: "https://dub.co",
- country: randomValue(["US", "GB", "CA", "AU", "DE", "FR", "ES", "IT"]),
- }) as any,
- ),
- sales: [...Array(10)].map(
- (_, idx) =>
- ({
- timestamp: subDays(new Date(), idx).toISOString(),
- click_id: "1",
- link_id: "1",
- domain: "refer.dub.co",
- key: "",
- url: "https://dub.co",
- country: randomValue(["US", "GB", "CA", "AU", "DE", "FR", "ES", "IT"]),
- event_name: [
- "Subscription creation",
- "Subscription paid",
- "Plan upgraded",
- ][idx % 3],
- // TODO update to saleAmount
- amount: [1100, 4900, 2400][idx % 3],
- }) as any,
- ),
-};
-
-async function ActivityListRSC({
- slug,
- event,
- page,
-}: {
- slug: string;
- event: EventType;
- page: number;
-}) {
- const link = await getReferralLink(slug);
- if (!link) {
- return (
- <ActivityList
- events={placeholderEvents[event]}
- totalEvents={placeholderEvents[event].length}
- demo
- />
- );
- }
-
- const [events, totalEvents] = await Promise.all([
- getConversionEvents({ linkId: link.id, event, page }),
- getTotalEvents(link.id),
- ]);
-
- return <ActivityList events={events} totalEvents={totalEvents[event] ?? 0} />;
-}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
index 8715125d8b..01ff1387e6 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
@@ -1,4 +1,5 @@
-import { getReferralLink } from "@/lib/actions/get-referral-link";
+"use client";
+
import { getTotalEvents } from "@/lib/actions/get-total-events";
import { dub } from "@/lib/dub";
import {
@@ -11,113 +12,61 @@ import {
MiniAreaChart,
StatsCard,
StatsCardSkeleton,
+ useAnalytics,
} from "@dub/blocks";
import { CountingNumbers } from "@dub/ui";
import { User } from "@dub/ui/src/icons";
-import { nFormatter, randomValue } from "@dub/utils";
-import { subDays } from "date-fns";
import { AnalyticsTimeseries } from "dub/dist/commonjs/models/components";
-import { Suspense } from "react";
-export function Stats({ slug }: { slug: string }) {
- return (
- <div className="grid grid-cols-1 gap-x-4 gap-y-4 md:grid-cols-2 lg:gap-x-6">
- <Suspense
- fallback={[...Array(2)].map(() => (
- <StatsCardSkeleton />
- ))}
- >
- <StatsInner slug={slug} />
- </Suspense>
- </div>
- );
+export function Stats() {
+ const { analytics, isLoading } = useAnalytics();
+
+ return <StatsInner />;
+
+ // return (
+ // <div className="grid grid-cols-1 gap-x-4 gap-y-4 md:grid-cols-2 lg:gap-x-6">
+ // {isLoading ? (
+ // [...Array(2)].map(() => <StatsCardSkeleton />)
+ // ) : (
+ // <StatsInner />
+ // )}
+ // </div>
+ // );
}
-async function StatsInner({ slug }: { slug: string }) {
- try {
- const link = await getReferralLink(slug);
- if (!link) {
- return (
- <>
- <StatsCard
- label="Affiliate Earnings"
- demo
- graphic={
- <MiniAreaChart
- // generate a random bell curve
- data={[...Array(16)].map((_, idx) => {
- const x = (idx - 7.5) / 4;
- const curve1 = 800 * Math.exp(-Math.pow(x + 0.5, 2));
- const curve2 = 600 * Math.exp(-Math.pow(x - 0.5, 2));
- return {
- date: subDays(new Date(), 15 - idx),
- value: Math.floor(
- 1500 + curve1 + curve2 + (Math.random() - 0.5) * 200,
- ),
- };
- })}
- />
- }
- >
- ${Math.floor(Math.random() * 50) + 50}
- </StatsCard>
- <StatsCard
- label="Clicks Quota Earned"
- demo
- graphic={
- <Gauge value={2500} max={REFERRAL_CLICKS_QUOTA_BONUS_MAX}>
- <div className="flex items-end gap-1 text-xs font-medium text-gray-500">
- <User className="size-4" />
- <CountingNumbers>5</CountingNumbers>
- </div>
- </Gauge>
- }
- >
- {nFormatter(randomValue([1000, 1500, 2000, 2500, 3000]), {
- full: true,
- })}
- </StatsCard>
- </>
- );
- }
+const StatsInner = () => {
+ const { totalSales, sales, referredSignups, clicksQuotaBonus } =
+ await loadData(link.id);
- const { totalSales, sales, referredSignups, clicksQuotaBonus } =
- await loadData(link.id);
+ return (
+ <>
+ <StatsCard
+ label="Affiliate Earnings"
+ graphic={<MiniAreaChart data={sales} />}
+ >
+ <CountingNumbers prefix="$" variant="full">
+ {(totalSales / 100) * REFERRAL_REVENUE_SHARE}
+ </CountingNumbers>
+ </StatsCard>
- return (
- <>
- <StatsCard
- label="Affiliate Earnings"
- graphic={<MiniAreaChart data={sales} />}
- >
- <CountingNumbers prefix="$" variant="full">
- {(totalSales / 100) * REFERRAL_REVENUE_SHARE}
- </CountingNumbers>
- </StatsCard>
- <StatsCard
- label="Clicks Quota Earned"
- graphic={
- <Gauge
- value={clicksQuotaBonus}
- max={REFERRAL_CLICKS_QUOTA_BONUS_MAX}
- >
- <div className="flex items-end gap-1 text-xs font-medium text-gray-500">
- <User className="size-4" />
- <CountingNumbers>{referredSignups}</CountingNumbers>
- </div>
- </Gauge>
- }
- >
- <CountingNumbers variant="full">{clicksQuotaBonus}</CountingNumbers>
- </StatsCard>
- </>
- );
- } catch (e) {
- console.error("Failed to load referral stats", e);
- }
+ <StatsCard
+ label="Clicks Quota Earned"
+ graphic={
+ <Gauge value={clicksQuotaBonus} max={REFERRAL_CLICKS_QUOTA_BONUS_MAX}>
+ <div className="flex items-end gap-1 text-xs font-medium text-gray-500">
+ <User className="size-4" />
+ <CountingNumbers>{referredSignups}</CountingNumbers>
+ </div>
+ </Gauge>
+ }
+ >
+ <CountingNumbers variant="full">{clicksQuotaBonus}</CountingNumbers>
+ </StatsCard>
+ </>
+ );
return [...Array(2)].map(() => <StatsCardSkeleton error />);
-}
+};
async function loadData(linkId: string) {
const [clicks, sales, totalEvents] = await Promise.all([
diff --git a/apps/web/lib/edge-config/get-feature-flags.ts b/apps/web/lib/edge-config/get-feature-flags.ts
index d649eb90b3..1b6a2fb840 100644
--- a/apps/web/lib/edge-config/get-feature-flags.ts
+++ b/apps/web/lib/edge-config/get-feature-flags.ts
@@ -17,7 +17,7 @@ export const getFeatureFlags = async ({
}
const workspaceFeatures: Record<BetaFeatures, boolean> = {
- referrals: false,
+ referrals: true,
webhooks: false,
newlinkbuilder: false,
};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 770370ded3..e09addc7eb 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -450,6 +450,9 @@ importers:
react-dom:
specifier: ^18.2.0
version: 18.2.0([email protected])
+ swr:
+ specifier: ^2.1.5
+ version: 2.1.5([email protected])
devDependencies:
'@dub/tailwind-config':
specifier: workspace:*
@@ -708,7 +711,7 @@ importers:
version: link:../tsconfig
tsup:
specifier: ^6.1.3
- version: 6.1.3([email protected])
typescript:
specifier: ^5.1.6
version: 5.1.6
@@ -20237,42 +20240,6 @@ packages:
- ts-node
dev: true
- resolution: {integrity: sha512-eRpBnbfpDFng+EJNTQ90N7QAf4HAGGC7O3buHIjroKWK7D1ibk9/YnR/3cS8HsMU5T+6Oi+cnF+yU5WmCnB//Q==}
- engines: {node: '>=14'}
- hasBin: true
- peerDependencies:
- '@swc/core': ^1
- postcss: ^8.4.12
- typescript: ^4.1.0
- peerDependenciesMeta:
- '@swc/core':
- optional: true
- postcss:
- optional: true
- typescript:
- optional: true
- dependencies:
- bundle-require: 3.1.2([email protected])
- cac: 6.7.14
- chokidar: 3.5.3
- debug: 4.3.4
- esbuild: 0.14.54
- execa: 5.1.1
- globby: 11.1.0
- joycon: 3.1.1
- postcss-load-config: 3.1.4([email protected])
- resolve-from: 5.0.0
- rollup: 2.79.1
- source-map: 0.8.0-beta.0
- sucrase: 3.34.0
- tree-kill: 1.2.2
- typescript: 5.1.6
- transitivePeerDependencies:
- - supports-color
- - ts-node
- dev: true
-
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
engines: {node: '>= 6'}