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.

Added event tracking with VA

Steven Tey6e4255acce8b
diff --git a/components/app/modals/add-edit-link-modal/index.tsx b/components/app/modals/add-edit-link-modal/index.tsx
index 666237858d..3685b8e993 100644
--- a/components/app/modals/add-edit-link-modal/index.tsx
+++ b/components/app/modals/add-edit-link-modal/index.tsx
@@ -39,6 +39,7 @@ import AndroidSection from "./android-section";
import { DEFAULT_LINK_PROPS } from "@/lib/constants";
import useDomains from "@/lib/swr/use-domains";
import { toast } from "react-hot-toast";
+import va from "@vercel/analytics";
function AddEditLinkModal({
showAddEditLinkModal,
@@ -280,11 +281,17 @@ function AddEditLinkModal({
}).then((res) => {
setSaving(false);
if (res.status === 200) {
+ // track link creation event
+ endpoint.method === "POST" &&
+ va.track("Created Link", {
+ type: slug ? "Custom Domain" : "Default Domain",
+ });
mutate(
- domain
+ slug
? `/api/projects/${slug}/links${getQueryString(router)}`
: `/api/links${getQueryString(router)}`,
);
+ // for welcome page, redirect to links page after adding a link
if (router.asPath === "/welcome") {
router.push("/links").then(() => {
setShowAddEditLinkModal(false);
diff --git a/components/app/modals/add-project-modal.tsx b/components/app/modals/add-project-modal.tsx
index a544970d67..d8e3cb1329 100644
--- a/components/app/modals/add-project-modal.tsx
+++ b/components/app/modals/add-project-modal.tsx
@@ -14,6 +14,7 @@ import BlurImage from "@/components/shared/blur-image";
import { AlertCircleFill, LoadingDots } from "@/components/shared/icons";
import Modal from "@/components/shared/modal";
import { generateDomainFromName } from "@/lib/utils";
+import va from "@vercel/analytics";
function AddProjectModalHelper({
showAddProjectModal,
@@ -112,6 +113,8 @@ function AddProjectModalHelper({
body: JSON.stringify(data),
}).then(async (res) => {
if (res.status === 200) {
+ // track project creation event
+ va.track("Created Project");
mutate("/api/projects");
router.push(`/${slug}`);
} else if (res.status === 422) {
diff --git a/components/app/modals/delete-link-modal.tsx b/components/app/modals/delete-link-modal.tsx
index 86a5f7e8e8..b306f381ef 100644
--- a/components/app/modals/delete-link-modal.tsx
+++ b/components/app/modals/delete-link-modal.tsx
@@ -64,7 +64,7 @@ function DeleteLinkModal({
e.preventDefault();
setDeleting(true);
fetch(
- domain
+ slug
? `/api/projects/${slug}/links/${props.key}?domain=${domain}`
: `/api/links/${props.key}`,
{
@@ -77,7 +77,7 @@ function DeleteLinkModal({
setDeleting(false);
if (res.status === 200) {
mutate(
- domain
+ slug
? `/api/projects/${slug}/links${getQueryString(router)}`
: `/api/links${getQueryString(router)}`,
);
diff --git a/components/app/settings/plan-usage.tsx b/components/app/settings/plan-usage.tsx
index 5d04ce9762..b58fb18851 100644
--- a/components/app/settings/plan-usage.tsx
+++ b/components/app/settings/plan-usage.tsx
@@ -1,5 +1,5 @@
import { useRouter } from "next/router";
-import { useMemo, useState } from "react";
+import { useEffect, useMemo, useState } from "react";
import { motion } from "framer-motion";
import { useUpgradePlanModal } from "@/components/app/modals/upgrade-plan-modal";
import {
@@ -13,6 +13,9 @@ import { getFirstAndLastDay, nFormatter } from "@/lib/utils";
import useProject from "@/lib/swr/use-project";
import useDomains from "@/lib/swr/use-domains";
import PlanBadge from "./plan-badge";
+import { toast } from "react-hot-toast";
+import { mutate } from "swr";
+import va from "@vercel/analytics";
export default function PlanUsage() {
const router = useRouter();
@@ -40,6 +43,19 @@ export default function PlanUsage() {
const { UpgradePlanModal, setShowUpgradePlanModal } = useUpgradePlanModal();
+ useEffect(() => {
+ if (router.query.success) {
+ toast.success("Upgrade success!");
+ setTimeout(() => {
+ mutate(`/api/projects/${slug}`);
+ // track upgrade to pro event
+ va.track("Upgraded Plan", {
+ plan,
+ });
+ }, 1000);
+ }
+ }, [router.query.success, plan]);
+
return (
<div className="rounded-lg border border-gray-200 bg-white">
<UpgradePlanModal />
diff --git a/components/layout/app/user-dropdown.tsx b/components/layout/app/user-dropdown.tsx
index 3141498b43..18abca9783 100644
--- a/components/layout/app/user-dropdown.tsx
+++ b/components/layout/app/user-dropdown.tsx
@@ -4,6 +4,7 @@ import { Logout } from "@/components/shared/icons";
import Popover from "@/components/shared/popover";
import IconMenu from "../../shared/icon-menu";
import Image from "next/image";
+import va from "@vercel/analytics";
export default function UserDropdown() {
const { data: session } = useSession();
@@ -16,7 +17,11 @@ export default function UserDropdown() {
<div className="w-full rounded-md bg-white p-1 sm:w-56">
<button
className="relative w-full rounded-md p-2 text-left text-sm transition-all duration-75 hover:bg-gray-100"
- onClick={() => signOut()}
+ onClick={() => {
+ signOut();
+ // track logout event
+ va.track("Logout");
+ }}
>
<IconMenu text="Logout" icon={<Logout className="h-4 w-4" />} />
</button>
diff --git a/lib/tinybird.ts b/lib/tinybird.ts
index ddfc76c441..ae67da1619 100644
--- a/lib/tinybird.ts
+++ b/lib/tinybird.ts
@@ -51,12 +51,13 @@ export async function recordClick(
},
).then((res) => res.json()),
// increment the click count for the link if key is specified (not root click)
+ // also increment the usage count for the project, and then we have a cron that will reset it at the start of new billing cycle
+ // TODO: might wanna include root clicks in the usage count as well?
...(key && [
conn.execute(
"UPDATE Link SET clicks = clicks + 1 WHERE domain = ? AND `key` = ?",
[domain, key],
),
- // increment the usage count for the project, and then we have a cron that will reset it at the start of new billing cycle
conn.execute(
"UPDATE Project p JOIN Domain d ON p.id = d.projectId SET p.usage = p.usage + 1 WHERE d.slug = ?",
[domain],
diff --git a/package.json b/package.json
index b81d644a70..257d97f7fd 100644
--- a/package.json
+++ b/package.json
@@ -28,7 +28,7 @@
"@upstash/qstash": "^0.3.0",
"@upstash/ratelimit": "^0.3.6",
"@upstash/redis": "^1.18.0",
- "@vercel/analytics": "^0.1.5",
+ "@vercel/analytics": "^1.0.0",
"@vercel/edge": "^0.3.1",
"@vercel/edge-config": "^0.1.0-canary.15",
"@vercel/og": "^0.0.21",
diff --git a/pages/api/projects/[slug]/billing/upgrade.ts b/pages/api/projects/[slug]/billing/upgrade.ts
index a7ca5f406b..aef6eae530 100644
--- a/pages/api/projects/[slug]/billing/upgrade.ts
+++ b/pages/api/projects/[slug]/billing/upgrade.ts
@@ -14,7 +14,7 @@ export default withProjectAuth(async (req, res, project, session) => {
process.env.VERCEL === "1"
? "https://app.dub.sh"
: "http://app.localhost:3000"
- }/${slug}/settings/billing`,
+ }/${slug}/settings/billing?success=true`,
cancel_url: `${
process.env.VERCEL === "1"
? "https://app.dub.sh"
diff --git a/pages/app/register.tsx b/pages/app/register.tsx
index e8d2ea0024..acb51ed967 100644
--- a/pages/app/register.tsx
+++ b/pages/app/register.tsx
@@ -6,6 +6,7 @@ import BlurImage from "@/components/shared/blur-image";
import { LoadingDots } from "@/components/shared/icons";
import Background from "@/components/shared/background";
import { toast, Toaster } from "react-hot-toast";
+import va from "@vercel/analytics";
export default function Login() {
const [signInClicked, setSignInClicked] = useState(false);
@@ -52,6 +53,8 @@ export default function Login() {
if (res?.ok && !res?.error) {
setEmail("");
toast.success("Email sent - check your inbox!");
+ // track signup event
+ va.track("Sign Up");
} else {
toast.error("Error sending email - try again?");
}
diff --git a/yarn.lock b/yarn.lock
index 9f10a16360..2af3b880d5 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1676,10 +1676,10 @@
dependencies:
isomorphic-fetch "^3.0.0"
-"@vercel/analytics@^0.1.5":
- version "0.1.5"
- resolved "https://registry.yarnpkg.com/@vercel/analytics/-/analytics-0.1.5.tgz#285275b64a5b47cae0e5d11002fb8856b1ec6b0c"
- integrity sha512-/k9N8Ea3Yc5A52GlkjzUEbi2vE/izClrOf++ryBkxEfrZM/OZwtHkdNw/QExZ1h/B67RCZLK7bCOnKKrhG7gTg==
+"@vercel/analytics@^1.0.0":
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/@vercel/analytics/-/analytics-1.0.0.tgz#7041bf3f14d65ab685f053b2fab09c605d12543e"
+ integrity sha512-RQmj7pv82JwGDHrnKeRc6TtSw2U7rWNubc2IH0ernTzWTj02yr9zvIYiYJeztsBzrJtWv7m8Nz6vxxb+cdEtJw==
"@vercel/edge-config@^0.1.0-canary.15":
version "0.1.0-canary.15"