Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): send subscription revenue as a property

Andrej445b735188ea
diff --git a/apps/web/index.html b/apps/web/index.html
index 6b4996005..bb88da882 100644
--- a/apps/web/index.html
+++ b/apps/web/index.html
@@ -49,7 +49,7 @@
const script = document.createElement('script');
script.defer = true;
script.setAttribute('data-domain', 'cloud.kaneo.app');
- script.src = 'https://plausible.kaneo.app/js/script.revenue.js';
+ script.src = 'https://plausible.kaneo.app/js/script.js';
document.head.appendChild(script);
}
</script>
diff --git a/apps/web/src/hooks/use-track-subscription.ts b/apps/web/src/hooks/use-track-subscription.ts
index 7d309a90d..f07c1a05a 100644
--- a/apps/web/src/hooks/use-track-subscription.ts
+++ b/apps/web/src/hooks/use-track-subscription.ts
@@ -1,6 +1,6 @@
import { useEffect } from "react";
import { takePendingPurchase } from "@/lib/analytics/pending-purchase";
-import { subscriptionRevenue } from "@/lib/analytics/subscription-revenue";
+import { subscriptionRevenueUsd } from "@/lib/analytics/subscription-revenue";
import { track } from "@/lib/analytics/track";
export function useTrackSubscription(
@@ -11,9 +11,16 @@ export function useTrackSubscription(
if (checkout !== "success" || seats === undefined) return;
const purchase = takePendingPurchase();
if (!purchase) return;
+ const revenue = subscriptionRevenueUsd(
+ purchase.plan,
+ purchase.interval,
+ seats,
+ );
track("Subscribed", {
- props: purchase,
- revenue: subscriptionRevenue(purchase.plan, purchase.interval, seats),
+ props: {
+ ...purchase,
+ ...(revenue === undefined ? {} : { revenue_usd: revenue }),
+ },
});
}, [checkout, seats]);
}
diff --git a/apps/web/src/lib/analytics/subscription-revenue.test.ts b/apps/web/src/lib/analytics/subscription-revenue.test.ts
index f7e47b093..9cdc21ea6 100644
--- a/apps/web/src/lib/analytics/subscription-revenue.test.ts
+++ b/apps/web/src/lib/analytics/subscription-revenue.test.ts
@@ -1,30 +1,18 @@
import { describe, expect, it } from "vite-plus/test";
-import { subscriptionRevenue } from "./subscription-revenue";
+import { subscriptionRevenueUsd } from "./subscription-revenue";
-describe("subscriptionRevenue", () => {
+describe("subscriptionRevenueUsd", () => {
it("prices the personal plan as a single seat", () => {
- expect(subscriptionRevenue("personal", "monthly", 3)).toEqual({
- currency: "USD",
- amount: 4,
- });
- expect(subscriptionRevenue("personal", "annual", 1)).toEqual({
- currency: "USD",
- amount: 40,
- });
+ expect(subscriptionRevenueUsd("personal", "monthly", 3)).toBe(4);
+ expect(subscriptionRevenueUsd("personal", "annual", 1)).toBe(40);
});
it("multiplies the team price by seats", () => {
- expect(subscriptionRevenue("team", "monthly", 6)).toEqual({
- currency: "USD",
- amount: 30,
- });
- expect(subscriptionRevenue("team", "annual", 3)).toEqual({
- currency: "USD",
- amount: 150,
- });
+ expect(subscriptionRevenueUsd("team", "monthly", 6)).toBe(30);
+ expect(subscriptionRevenueUsd("team", "annual", 3)).toBe(150);
});
it("counts at least one team seat", () => {
- expect(subscriptionRevenue("team", "monthly", 0)?.amount).toBe(5);
+ expect(subscriptionRevenueUsd("team", "monthly", 0)).toBe(5);
});
});
diff --git a/apps/web/src/lib/analytics/subscription-revenue.ts b/apps/web/src/lib/analytics/subscription-revenue.ts
index fa51e7819..9a3f40734 100644
--- a/apps/web/src/lib/analytics/subscription-revenue.ts
+++ b/apps/web/src/lib/analytics/subscription-revenue.ts
@@ -4,7 +4,7 @@ import {
type BillingPlanKey,
} from "@/constants/billing";
-export function subscriptionRevenue(
+export function subscriptionRevenueUsd(
plan: BillingPlanKey,
interval: BillingIntervalKey,
seats: number,
@@ -14,5 +14,5 @@ export function subscriptionRevenue(
];
if (price === undefined) return undefined;
const units = plan === "team" ? Math.max(1, Math.floor(seats) || 1) : 1;
- return { currency: "USD", amount: price * units };
+ return price * units;
}
diff --git a/apps/web/src/lib/analytics/track.test.ts b/apps/web/src/lib/analytics/track.test.ts
index 18723d349..187584085 100644
--- a/apps/web/src/lib/analytics/track.test.ts
+++ b/apps/web/src/lib/analytics/track.test.ts
@@ -11,18 +11,16 @@ describe("track", () => {
expect(() => track("Signup")).not.toThrow();
});
- it("forwards the event, props, and revenue to Plausible", () => {
+ it("forwards the event and props to Plausible", () => {
const plausible = vi.fn();
window.plausible = plausible;
track("Subscribed", {
- props: { plan: "team", interval: "annual" },
- revenue: { currency: "USD", amount: 150 },
+ props: { plan: "team", interval: "annual", revenue_usd: 150 },
});
expect(plausible).toHaveBeenCalledWith("Subscribed", {
- props: { plan: "team", interval: "annual" },
- revenue: { currency: "USD", amount: 150 },
+ props: { plan: "team", interval: "annual", revenue_usd: 150 },
});
});
diff --git a/apps/web/src/lib/analytics/track.ts b/apps/web/src/lib/analytics/track.ts
index 3877893ee..00076ca9b 100644
--- a/apps/web/src/lib/analytics/track.ts
+++ b/apps/web/src/lib/analytics/track.ts
@@ -8,7 +8,6 @@ export type AnalyticsEvent =
export type TrackOptions = {
props?: Record<string, string | number | boolean>;
- revenue?: { currency: string; amount: number };
};
declare global {