The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Stop soft-indexing unpublished and staging program landers
Cursor Agent7af320219ceb
diff --git a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/(default)/layout.tsx b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/(default)/layout.tsxindex 9c4323575b..ff7e9b1667 100644--- a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/(default)/layout.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/(default)/layout.tsx@@ -1,6 +1,7 @@import { getProgram } from "@/lib/fetchers/get-program";import { getProgramSlugs } from "@/lib/fetchers/get-program-slugs";import { isProductionEnvironment } from "@/lib/sandbox/environment";+import { shouldIndexProgramLander } from "@/lib/sandbox/program-seo";import { DEFAULT_PARTNER_GROUP } from "@/lib/zod/schemas/groups";import { formatRewardDescription } from "@/ui/partners/format-reward-description";import { Wordmark } from "@dub/ui";@@ -26,6 +27,19 @@ export async function generateMetadata(props: {notFound();}+ const landerPublishedAt = program.group?.landerPublishedAt;+ const isPublished = Boolean(landerPublishedAt && program.group?.landerData);+ const isProduction = isProductionEnvironment(program.environment);++ // Unpublished landers 404/redirect in the page — don't soft-index them with+ // rich program SEO. Staging/sandbox landers stay shareable but noindex.+ if (!isPublished) {+ return constructMetadata({+ title: "Dub Partners",+ noIndex: true,+ });+ }+return constructMetadata({title: `${program.name} Affiliate Program`,description: `Join the ${program.name} affiliate program and ${@@ -34,8 +48,14 @@ export async function generateMetadata(props: {: "earn commissions"} by referring ${program.name} to your friends and followers.`,image: `${APP_DOMAIN}/api/og/program?slug=${program.slug}${groupSlug ? `&groupSlug=${groupSlug}` : ""}`,- canonicalUrl: `${PARTNERS_DOMAIN}/${program.slug}`,- noIndex: !isProductionEnvironment(program.environment),+ // Avoid self-canonicalizing non-production URLs into the index.+ ...(isProduction && {+ canonicalUrl: `${PARTNERS_DOMAIN}/${program.slug}`,+ }),+ noIndex: !shouldIndexProgramLander({+ environment: program.environment,+ landerPublishedAt,+ }),});}diff --git a/apps/web/app/(ee)/partners.dub.co/(auth-login-register)/(generic)/layout.tsx b/apps/web/app/(ee)/partners.dub.co/(auth-login-register)/(generic)/layout.tsxindex 42036a6e34..576ce72840 100644--- a/apps/web/app/(ee)/partners.dub.co/(auth-login-register)/(generic)/layout.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(auth-login-register)/(generic)/layout.tsx@@ -25,6 +25,8 @@ export async function generateMetadata(props: {}if (program) {+ const isProduction = isProductionEnvironment(program.environment);+return constructMetadata({title: `${program.name} Affiliate Program`,description: `Join the ${program.name} affiliate program and ${@@ -33,8 +35,10 @@ export async function generateMetadata(props: {: "earn commissions"} by referring ${program.name} to your friends and followers.`,image: `${PARTNERS_DOMAIN}/api/og/program?slug=${program.slug}`,- canonicalUrl: `${PARTNERS_DOMAIN}/${program.slug}`,- noIndex: !isProductionEnvironment(program.environment),+ ...(isProduction && {+ canonicalUrl: `${PARTNERS_DOMAIN}/${program.slug}`,+ }),+ noIndex: !isProduction,});}diff --git a/apps/web/app/app.dub.co/marketplace/[[...segments]]/page.tsx b/apps/web/app/app.dub.co/marketplace/[[...segments]]/page.tsxindex 04d0724d89..3f4986bebb 100644--- a/apps/web/app/app.dub.co/marketplace/[[...segments]]/page.tsx+++ b/apps/web/app/app.dub.co/marketplace/[[...segments]]/page.tsx@@ -23,6 +23,8 @@ export async function generateMetadata(props: {let description = `Browse and apply to the best SaaS affiliate programs on Dub's Partner Network.`;let image = "https://assets.dub.co/og/marketplace.jpg";+ let noIndex = false;+if (segments.length === 1 && segments[0] === "all") {title = `Top SaaS affiliate programs in ${currentYear}`;} else if (@@ -40,6 +42,10 @@ export async function generateMetadata(props: {image =program.marketplaceHeaderImage ||`${APP_DOMAIN}/api/og/program?slug=${program.slug}`;+ } else {+ // Missing/non-production program slugs redirect in the page — don't+ // soft-index `/marketplace/{slug}-staging` with a marketplace canonical.+ noIndex = true;}} else if (segments.length === 2 && segments[0] === "c") {const category = Object.values(Category).find(@@ -55,6 +61,8 @@ export async function generateMetadata(props: {categoryMeta?.listPageDescription ??`Browse the best ${label} affiliate programs on Dub's Program Marketplace.`;image = `${APP_DOMAIN}/api/og/program/categories?categorySlug=${category.toLowerCase()}`;+ } else {+ noIndex = true;}}@@ -62,7 +70,10 @@ export async function generateMetadata(props: {title,description,image,- canonicalUrl: `https://dub.co${pathname.startsWith("/") ? pathname : `/${pathname}`}`,+ ...(!noIndex && {+ canonicalUrl: `https://dub.co${pathname.startsWith("/") ? pathname : `/${pathname}`}`,+ }),+ noIndex,});}diff --git a/apps/web/app/sitemap.ts b/apps/web/app/sitemap.tsindex ab186652dc..0a93c410f6 100644--- a/apps/web/app/sitemap.ts+++ b/apps/web/app/sitemap.ts@@ -54,6 +54,7 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {if (isAppHostname(domain)) {const marketplacePrograms = await prisma.program.findMany({where: {+ environment: WorkspaceEnvironment.production,addedToMarketplaceAt: {not: null,},diff --git a/apps/web/lib/fetchers/get-marketplace-programs-summary.ts b/apps/web/lib/fetchers/get-marketplace-programs-summary.tsindex d647ff8b88..f611297876 100644--- a/apps/web/lib/fetchers/get-marketplace-programs-summary.ts+++ b/apps/web/lib/fetchers/get-marketplace-programs-summary.ts@@ -11,7 +11,7 @@ import {MarketplaceProgramsSummarySchema,NetworkProgramSchema,} from "@/lib/zod/schemas/program-network";-import { Category, Prisma } from "@prisma/client";+import { Category, Prisma, WorkspaceEnvironment } from "@prisma/client";import { cache } from "react";const programInclude = {@@ -146,6 +146,7 @@ function selectCategoryRows(programMeta: ProgramMeta[], usedIds: Set<string>) {export const getMarketplaceProgramsSummary = cache(async () => {const programs = await prisma.program.findMany({where: {+ environment: WorkspaceEnvironment.production,addedToMarketplaceAt: {not: null,},diff --git a/apps/web/lib/fetchers/get-network-program-counts.ts b/apps/web/lib/fetchers/get-network-program-counts.tsindex 9a4cdd0712..174ab7e2a8 100644--- a/apps/web/lib/fetchers/get-network-program-counts.ts+++ b/apps/web/lib/fetchers/get-network-program-counts.ts@@ -1,7 +1,12 @@import { prisma } from "@/lib/prisma";import { DEFAULT_PARTNER_GROUP } from "@/lib/zod/schemas/groups";import { getPublicNetworkProgramsQuerySchema } from "@/lib/zod/schemas/program-network";-import { Category, Prisma, ProgramEnrollmentStatus } from "@prisma/client";+import {+ Category,+ Prisma,+ ProgramEnrollmentStatus,+ WorkspaceEnvironment,+} from "@prisma/client";import { cache } from "react";import * as z from "zod/v4";@@ -38,6 +43,7 @@ export function buildNetworkProgramCountWhereSql({return Prisma.sql`p.addedToMarketplaceAt IS NOT NULL+ AND p.environment = ${WorkspaceEnvironment.production}AND EXISTS (SELECT 1 FROM PartnerGroup pgWHEREdiff --git a/apps/web/lib/fetchers/get-network-program.ts b/apps/web/lib/fetchers/get-network-program.tsindex 9c20a836ca..fa6680c642 100644--- a/apps/web/lib/fetchers/get-network-program.ts+++ b/apps/web/lib/fetchers/get-network-program.ts@@ -1,5 +1,6 @@import { getGroupBountySummaries } from "@/lib/bounty/api/get-group-bounty-summaries";import { prisma } from "@/lib/prisma";+import { WorkspaceEnvironment } from "@prisma/client";import { cache } from "react";import { DEFAULT_PARTNER_GROUP } from "../zod/schemas/groups";import { programLanderSchema } from "../zod/schemas/program-lander";@@ -9,6 +10,7 @@ export const getNetworkProgram = cache(async ({ slug }: { slug: string }) => {const program = await prisma.program.findUnique({where: {slug,+ environment: WorkspaceEnvironment.production,addedToMarketplaceAt: {not: null,},diff --git a/apps/web/lib/fetchers/get-public-network-programs.ts b/apps/web/lib/fetchers/get-public-network-programs.tsindex 1f060a5228..9cdc13442c 100644--- a/apps/web/lib/fetchers/get-public-network-programs.ts+++ b/apps/web/lib/fetchers/get-public-network-programs.ts@@ -5,6 +5,7 @@ import {NetworkProgramSchema,PROGRAM_NETWORK_MAX_PAGE_SIZE,} from "@/lib/zod/schemas/program-network";+import { WorkspaceEnvironment } from "@prisma/client";import { cache } from "react";import * as z from "zod/v4";@@ -25,6 +26,7 @@ export const getPublicNetworkPrograms = cache(const programs = await prisma.program.findMany({where: {+ environment: WorkspaceEnvironment.production,addedToMarketplaceAt: {not: null,},diff --git a/apps/web/lib/sandbox/program-seo.ts b/apps/web/lib/sandbox/program-seo.tsnew file mode 100644index 0000000000..c7bbd9991a--- /dev/null+++ b/apps/web/lib/sandbox/program-seo.ts@@ -0,0 +1,18 @@+import { WorkspaceEnvironment } from "@prisma/client";+import { isProductionEnvironment } from "./environment";++/**+ * Public program landers should only be indexed when they are published on a+ * production program. Staging/sandbox landers stay crawlable for testing but+ * must not emit indexable SEO; unpublished landers must not soft-404 with rich+ * metadata either.+ */+export function shouldIndexProgramLander({+ environment,+ landerPublishedAt,+}: {+ environment: WorkspaceEnvironment | null | undefined;+ landerPublishedAt: Date | string | null | undefined;+}) {+ return isProductionEnvironment(environment) && Boolean(landerPublishedAt);+}diff --git a/apps/web/tests/misc/program-seo.test.ts b/apps/web/tests/misc/program-seo.test.tsnew file mode 100644index 0000000000..4897193837--- /dev/null+++ b/apps/web/tests/misc/program-seo.test.ts@@ -0,0 +1,37 @@+import { shouldIndexProgramLander } from "@/lib/sandbox/program-seo";+import { WorkspaceEnvironment } from "@prisma/client";+import { describe, expect, it } from "vitest";++describe("shouldIndexProgramLander", () => {+ it("indexes published production landers only", () => {+ expect(+ shouldIndexProgramLander({+ environment: WorkspaceEnvironment.production,+ landerPublishedAt: new Date(),+ }),+ ).toBe(true);+ });++ it("does not index unpublished production landers", () => {+ expect(+ shouldIndexProgramLander({+ environment: WorkspaceEnvironment.production,+ landerPublishedAt: null,+ }),+ ).toBe(false);+ });++ it("does not index published staging or sandbox landers", () => {+ for (const environment of [+ WorkspaceEnvironment.staging,+ WorkspaceEnvironment.sandbox,+ ]) {+ expect(+ shouldIndexProgramLander({+ environment,+ landerPublishedAt: new Date(),+ }),+ ).toBe(false);+ }+ });+});