-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c45d18d
commit 6c7ad03
Showing
34 changed files
with
244 additions
and
309 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "../../route"; |
20 changes: 0 additions & 20 deletions
20
apps/web/app/api/analytics/admin/clicks/[endpoint]/route.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { getAnalytics } from "@/lib/analytics/get-analytics"; | ||
import { withAdmin } from "@/lib/auth"; | ||
import { analyticsQuerySchema } from "@/lib/zod/schemas/analytics"; | ||
import { NextResponse } from "next/server"; | ||
|
||
// GET /api/analytics/admin – get analytics for admin | ||
export const GET = withAdmin(async ({ searchParams }) => { | ||
const parsedParams = analyticsQuerySchema.parse(searchParams); | ||
|
||
const response = await getAnalytics(parsedParams); | ||
|
||
return NextResponse.json(response); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
9 changes: 2 additions & 7 deletions
9
...tics/demo/[eventType]/[endpoint]/route.ts → apps/web/app/api/analytics/demo/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { withWorkspace } from "@/lib/auth"; | ||
import { getDomainOrLink } from "@/lib/planetscale"; | ||
import { prisma } from "@/lib/prisma"; | ||
import z from "@/lib/zod"; | ||
import { domainKeySchema } from "@/lib/zod/schemas/links"; | ||
import { NextResponse } from "next/server"; | ||
|
||
const updatePublicStatsSchema = z.object({ | ||
publicStats: z.boolean(), | ||
}); | ||
|
||
// GET /api/analytics – get the publicStats setting for a link | ||
export const GET = withWorkspace(async ({ searchParams }) => { | ||
const { domain, key } = domainKeySchema.parse(searchParams); | ||
const response = await getDomainOrLink({ domain, key }); | ||
return NextResponse.json(response); | ||
}); | ||
|
||
// PUT /api/analytics – update the publicStats setting for a link | ||
export const PUT = withWorkspace(async ({ req, searchParams }) => { | ||
const { domain, key } = domainKeySchema.parse(searchParams); | ||
const { publicStats } = updatePublicStatsSchema.parse(await req.json()); | ||
const response = | ||
key === "_root" | ||
? await prisma.domain.update({ | ||
where: { slug: domain }, | ||
data: { publicStats }, | ||
}) | ||
: await prisma.link.update({ | ||
where: { domain_key: { domain, key } }, | ||
data: { publicStats }, | ||
}); | ||
return NextResponse.json(response); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,50 @@ | ||
import { getAnalytics } from "@/lib/analytics/get-analytics"; | ||
import { validDateRangeForPlan } from "@/lib/analytics/utils"; | ||
import { withWorkspace } from "@/lib/auth"; | ||
import { getDomainOrLink } from "@/lib/planetscale"; | ||
import { prisma } from "@/lib/prisma"; | ||
import z from "@/lib/zod"; | ||
import { domainKeySchema } from "@/lib/zod/schemas/links"; | ||
import { getDomainViaEdge } from "@/lib/planetscale"; | ||
import { | ||
analyticsPathParamsSchema, | ||
analyticsQuerySchema, | ||
} from "@/lib/zod/schemas/analytics"; | ||
import { NextResponse } from "next/server"; | ||
|
||
const updatePublicStatsSchema = z.object({ | ||
publicStats: z.boolean(), | ||
}); | ||
// GET /api/analytics – get analytics | ||
export const GET = withWorkspace( | ||
async ({ params, searchParams, workspace, link }) => { | ||
const { eventType: oldEvent, endpoint: oldType } = | ||
analyticsPathParamsSchema.parse(params); | ||
|
||
// GET /api/analytics – get the publicStats setting for a link | ||
export const GET = withWorkspace(async ({ searchParams }) => { | ||
const { domain, key } = domainKeySchema.parse(searchParams); | ||
const response = await getDomainOrLink({ domain, key }); | ||
return NextResponse.json(response); | ||
}); | ||
const parsedParams = analyticsQuerySchema.parse(searchParams); | ||
let { event, type, domain, key, interval, start, end } = parsedParams; | ||
|
||
// PUT /api/analytics – update the publicStats setting for a link | ||
export const PUT = withWorkspace(async ({ req, searchParams }) => { | ||
const { domain, key } = domainKeySchema.parse(searchParams); | ||
const { publicStats } = updatePublicStatsSchema.parse(await req.json()); | ||
const response = | ||
key === "_root" | ||
? await prisma.domain.update({ | ||
where: { slug: domain }, | ||
data: { publicStats }, | ||
}) | ||
: await prisma.link.update({ | ||
where: { domain_key: { domain, key } }, | ||
data: { publicStats }, | ||
}); | ||
return NextResponse.json(response); | ||
}); | ||
event = oldEvent || event; | ||
type = oldType || type; | ||
|
||
validDateRangeForPlan({ | ||
plan: workspace.plan, | ||
interval, | ||
start, | ||
end, | ||
throwError: true, | ||
}); | ||
|
||
const linkId = link | ||
? link.id | ||
: domain && key === "_root" | ||
? await getDomainViaEdge(domain).then((d) => d?.id) | ||
: null; | ||
|
||
const response = await getAnalytics({ | ||
...parsedParams, | ||
event, | ||
type, | ||
...(linkId && { linkId }), | ||
workspaceId: workspace.id, | ||
}); | ||
|
||
return NextResponse.json(response); | ||
}, | ||
{ | ||
needNotExceededClicks: true, | ||
}, | ||
); |
Oops, something went wrong.