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.

Add Plausible

Steven Tey938ac786a5de
diff --git a/apps/web/app/app.dub.co/(auth)/welcome/page-client.tsx b/apps/web/app/app.dub.co/(auth)/welcome/page-client.tsx
index a01da359e9..1e350c0285 100644
--- a/apps/web/app/app.dub.co/(auth)/welcome/page-client.tsx
+++ b/apps/web/app/app.dub.co/(auth)/welcome/page-client.tsx
@@ -6,11 +6,14 @@ import Intro from "@/ui/welcome/intro";
import { AnimatePresence } from "framer-motion";
import { ArrowLeft } from "lucide-react";
import { useSession } from "next-auth/react";
+import { usePlausible } from "next-plausible";
import { useRouter, useSearchParams } from "next/navigation";
import posthog from "posthog-js";
import { useEffect } from "react";
export default function WelcomePageClient() {
+ const plausible = usePlausible();
+
const { setShowAddWorkspaceModal, AddWorkspaceModal } =
useAddWorkspaceModal();
const { setShowUpgradePlanModal, UpgradePlanModal } = useUpgradePlanModal();
@@ -21,6 +24,7 @@ export default function WelcomePageClient() {
const { data: session } = useSession();
useEffect(() => {
+ plausible("Signed Up");
if (session?.user) {
posthog.identify(session.user["id"], {
email: session.user.email,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
index 7a18f4341f..87a45e68f5 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
@@ -12,7 +12,8 @@ import {
ProgressBar,
useRouterStuff,
} from "@dub/ui";
-import { getFirstAndLastDay, nFormatter } from "@dub/utils";
+import { getFirstAndLastDay, getPlanDetails, nFormatter } from "@dub/utils";
+import { usePlausible } from "next-plausible";
import { useRouter, useSearchParams } from "next/navigation";
import posthog from "posthog-js";
import { useEffect, useMemo, useState } from "react";
@@ -64,16 +65,28 @@ export default function WorkspaceBillingClient() {
const { queryParams } = useRouterStuff();
const [confetti, setConfetti] = useState(false);
+ const plausible = usePlausible();
+
useEffect(() => {
if (searchParams?.get("success")) {
toast.success("Upgrade success!");
setConfetti(true);
- setTimeout(() => {
- mutate(`/api/workspaces/${id}`);
- // track upgrade event
+ setTimeout(async () => {
+ await mutate(`/api/workspaces/${id}`);
if (plan) {
+ const planDetails = getPlanDetails(plan)!;
+ // track upgrade event
+ plausible("Upgraded Plan TEST", {
+ props: {
+ revenue: {
+ currency: "USD",
+ amount: planDetails.price.monthly,
+ },
+ },
+ });
posthog.capture("plan_upgraded", {
plan,
+ revenue: planDetails.price.monthly,
});
}
}, 1000);
diff --git a/apps/web/app/providers.tsx b/apps/web/app/providers.tsx
index e3ec0cdb09..c40366eb5f 100644
--- a/apps/web/app/providers.tsx
+++ b/apps/web/app/providers.tsx
@@ -5,13 +5,14 @@ import { ModalProvider } from "@/ui/modals/modal-provider";
import { KeyboardShortcutProvider } from "@dub/ui";
import { Analytics as VercelAnalytics } from "@vercel/analytics/react";
import { SessionProvider } from "next-auth/react";
+import PlausibleProvider from "next-plausible";
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
import { ReactNode } from "react";
if (typeof window !== "undefined") {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
- api_host: "/_posthog/ingest",
+ api_host: "/_proxy/posthog/ingest",
ui_host: "https://us.posthog.com",
person_profiles: "identified_only",
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
@@ -22,6 +23,15 @@ if (typeof window !== "undefined") {
export default function Providers({ children }: { children: ReactNode }) {
return (
<PostHogProvider client={posthog}>
+ <PlausibleProvider
+ domain="dub.co"
+ revenue
+ scriptProps={{
+ src: "/_proxy/plausible/script.js",
+ // @ts-ignore
+ "data-api": "/_proxy/plausible/event",
+ }}
+ />
<SessionProvider>
<ModalProvider>
<KeyboardShortcutProvider>
diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts
index 026aa3a1d3..19dfee7c7d 100644
--- a/apps/web/middleware.ts
+++ b/apps/web/middleware.ts
@@ -25,10 +25,9 @@ export const config = {
* 3. /_proxy/ (special page for OG tags proxying)
* 4. /_static (inside /public)
* 5. /_vercel (Vercel internals)
- * 6. /_posthog (PostHog proxy)
- * 7. Static files (e.g. /favicon.ico, /sitemap.xml, /robots.txt, etc.)
+ * 6. Static files (e.g. /favicon.ico, /sitemap.xml, /robots.txt, etc.)
*/
- "/((?!api/|_next/|_proxy/|_static|_vercel|_posthog|[\\w-]+\\.\\w+).*)",
+ "/((?!api/|_next/|_proxy/|_static|_vercel|[\\w-]+\\.\\w+).*)",
],
};
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index 03649b4956..868b3a39d1 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -215,13 +215,22 @@ module.exports = withAxiom({
return [
// for posthog proxy
{
- source: "/_posthog/ingest/static/:path*",
+ source: "/_proxy/posthog/ingest/static/:path*",
destination: "https://us-assets.i.posthog.com/static/:path*",
},
{
- source: "/_posthog/ingest/:path*",
+ source: "/_proxy/posthog/ingest/:path*",
destination: "https://us.i.posthog.com/:path*",
},
+ // for plausible proxy
+ {
+ source: "/_proxy/plausible/script.js",
+ destination: "https://plausible.io/js/script.js",
+ },
+ {
+ source: "/_proxy/plausible/event",
+ destination: "https://plausible.io/api/event",
+ },
];
},
});
diff --git a/apps/web/package.json b/apps/web/package.json
index 9061006f60..ba0b968d1b 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -78,6 +78,7 @@
"next": "14.3.0-canary.42",
"next-auth": "^4.24.4",
"next-axiom": "^1.3.0",
+ "next-plausible": "^3.12.0",
"next-safe-action": "7.1.4-experimental.1",
"node-html-parser": "^6.1.4",
"nodemailer": "^6.9.3",
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index e1a831d38a..efadfd558c 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -92,7 +92,7 @@ function LinksList({
<CardList variant={compact ? "compact" : "loose"} loading={loading}>
{links?.length
? // Link cards
- links.map((link) => <LinkCard link={link} />)
+ links.map((link) => <LinkCard key={link.id} link={link} />)
: // Loading placeholder cards
Array.from({ length: 12 }).map((_, idx) => (
<CardList.Card
diff --git a/apps/web/ui/modals/accept-invite-modal.tsx b/apps/web/ui/modals/accept-invite-modal.tsx
index 03ff173d9b..deecc4174c 100644
--- a/apps/web/ui/modals/accept-invite-modal.tsx
+++ b/apps/web/ui/modals/accept-invite-modal.tsx
@@ -1,6 +1,7 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { LoadingDots, Logo, Modal } from "@dub/ui";
import { useSession } from "next-auth/react";
+import { usePlausible } from "next-plausible";
import Link from "next/link";
import { useParams } from "next/navigation";
import posthog from "posthog-js";
@@ -25,6 +26,7 @@ function AcceptInviteModal({
const [accepting, setAccepting] = useState(false);
const { error } = useWorkspace();
const { data: session } = useSession();
+ const plausible = usePlausible();
return (
<Modal
diff --git a/apps/web/ui/modals/add-workspace-modal.tsx b/apps/web/ui/modals/add-workspace-modal.tsx
index b2b4b2b7b2..bcb1fb524c 100644
--- a/apps/web/ui/modals/add-workspace-modal.tsx
+++ b/apps/web/ui/modals/add-workspace-modal.tsx
@@ -8,6 +8,7 @@ import {
useRouterStuff,
} from "@dub/ui";
import slugify from "@sindresorhus/slugify";
+import { usePlausible } from "next-plausible";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import posthog from "posthog-js";
import {
@@ -31,6 +32,7 @@ function AddWorkspaceModalHelper({
}) {
const router = useRouter();
const pathname = usePathname();
+ const plausible = usePlausible();
const [data, setData] = useState<{
name: string;
@@ -99,6 +101,7 @@ function AddWorkspaceModalHelper({
}).then(async (res) => {
if (res.status === 200) {
const { id: workspaceId } = await res.json();
+ plausible("Created Workspace");
// track workspace creation event
posthog.capture("workspace_created", {
workspace_id: workspaceId,
diff --git a/apps/web/ui/modals/upgrade-plan-modal.tsx b/apps/web/ui/modals/upgrade-plan-modal.tsx
index f76b405026..ed2c214686 100644
--- a/apps/web/ui/modals/upgrade-plan-modal.tsx
+++ b/apps/web/ui/modals/upgrade-plan-modal.tsx
@@ -22,6 +22,7 @@ import {
} from "@dub/utils";
import { motion } from "framer-motion";
import { ChevronDown } from "lucide-react";
+import { usePlausible } from "next-plausible";
import Link from "next/link";
import {
useParams,
@@ -70,6 +71,8 @@ function UpgradePlanModal({
const [clickedCompare, setClickedCompare] = useState(false);
const { queryParams } = useRouterStuff();
+ const plausible = usePlausible();
+
return (
<Modal
showModal={showUpgradePlanModal}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7f006d2eaf..088f8f7ade 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -230,6 +230,9 @@ importers:
next-axiom:
specifier: ^1.3.0
+ next-plausible:
+ specifier: ^3.12.0
next-safe-action:
specifier: 7.1.4-experimental.1
@@ -15947,6 +15950,18 @@ packages:
- terser
dev: false
+ resolution: {integrity: sha512-SSkEqKQ6PgR8fx3sYfIAT69k2xuCUXO5ngkSS19CjxY97lAoZxsfZpYednxB4zo0mHYv87JzhPynrdBPlCBVHg==}
+ peerDependencies:
+ next: ^11.1.0 || ^12.0.0 || ^13.0.0 || ^14.0.0
+ react: ^16.8.0 || ^17.0.0 || ^18.0.0
+ react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
+ dependencies:
+ next: 14.3.0-canary.42(@babel/[email protected])(@opentelemetry/[email protected])([email protected])([email protected])
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ dev: false
+
resolution: {integrity: sha512-6BihKPIJ/Wu7qgEGUKAUJfy5NTPO2eV1BJ/7WWpgMarHzm+6/OUkllwwndAw85YLy+khVmzHYkSCS+n0Ei7qMg==}
engines: {node: '>=18.17'}