-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Program Analytics page #2519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TWilson023
wants to merge
49
commits into
main
Choose a base branch
from
program-analytics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,226
−1,219
Open
Program Analytics page #2519
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
34dbe8d
Add analytics tab+page
TWilson023 0101c20
Add area chart
TWilson023 d4ae66c
Merge branch 'main' into program-analytics
TWilson023 0bdae09
Big filtering refactor + implementation
TWilson023 0f859f0
Fix filter counts
TWilson023 d259cf0
Hide UTM filters
TWilson023 969ff68
WIP analytics partners table
TWilson023 c9f2ad0
Update analytics-partners-table.tsx
TWilson023 ae5432f
Merge branch 'main' into program-analytics
TWilson023 69ecbd9
Add type predicate for filtering out `null`
TWilson023 3276d14
Merge branch 'program-analytics' of github.com:dubinc/dub into progra…
TWilson023 0cad27c
Fully mock pagination
TWilson023 1779ed7
switch from 2 calls to 1 call
steven-tey ded8046
improve loading state
steven-tey 06fd681
Update page-client.tsx
steven-tey 78ac707
simplify filters
steven-tey d57a43b
Merge branch 'main' into program-analytics
steven-tey dd347c7
Merge branch 'main' into program-analytics
steven-tey 5d2bb8f
Add analytics tabs
TWilson023 410d383
WIP partner filter
TWilson023 010b92f
Merge branch 'main' into program-analytics
TWilson023 fc52ba9
Update analytics-partners-table.tsx
TWilson023 d45ddc7
Add sorting by event
TWilson023 70f1820
Merge branch 'program-analytics' of github.com:dubinc/dub into progra…
TWilson023 3cde99c
Add saleAmount to filters
TWilson023 67ec72a
Update use-analytics-filters.tsx
TWilson023 c25bc59
Add analytics cards
TWilson023 67c1519
Types fix
TWilson023 a32c6a6
Merge branch 'main' into program-analytics
TWilson023 4f96103
Merge branch 'main' into program-analytics
TWilson023 9430e5a
Update record-link.ts
TWilson023 e3e3f55
Update analytics-partners-table.tsx
TWilson023 edfee16
Merge branch 'program-analytics' of github.com:dubinc/dub into progra…
TWilson023 4d46ec0
Update analytics-chart.tsx
TWilson023 b2284ee
Update analytics-chart.tsx
TWilson023 788def1
Update page-client.tsx
TWilson023 225c732
Merge branch 'main' into program-analytics
TWilson023 cb6f86e
speed up `GET /analytics`
steven-tey 6d6cd7e
remove useProgramRevenue
steven-tey 4f4ac13
Merge branch 'main' into program-analytics
steven-tey 3b358c2
Refactor context + add funnel chart
TWilson023 a4d30da
Merge branch 'program-analytics' of github.com:dubinc/dub into progra…
TWilson023 d95c977
Merge branch 'main' into program-analytics
TWilson023 1bba815
Merge branch 'main' into program-analytics
steven-tey 217bddd
Update overview-chart.tsx
steven-tey ca7c7b8
Update apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/analyt…
steven-tey 2798afd
Update README.md
steven-tey bd45b3e
Update analytics-chart.tsx
steven-tey 0162c4f
Merge branch 'main' into program-analytics
steven-tey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
44 changes: 0 additions & 44 deletions
44
apps/web/app/(ee)/api/programs/[programId]/revenue/route.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
181 changes: 181 additions & 0 deletions
181
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/analytics/analytics-chart.tsx
This file contains hidden or 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,181 @@ | ||
import { formatDateTooltip } from "@/lib/analytics/format-date-tooltip"; | ||
import { editQueryString } from "@/lib/analytics/utils"; | ||
import { AnalyticsFunnelChart } from "@/ui/analytics/analytics-funnel-chart"; | ||
import { AnalyticsContext } from "@/ui/analytics/analytics-provider"; | ||
import { AnalyticsTabs } from "@/ui/analytics/analytics-tabs"; | ||
import { ChartViewSwitcher } from "@/ui/analytics/chart-view-switcher"; | ||
import { useRouterStuff } from "@dub/ui"; | ||
import { | ||
Areas, | ||
ChartContext, | ||
TimeSeriesChart, | ||
XAxis, | ||
YAxis, | ||
} from "@dub/ui/charts"; | ||
import { LoadingSpinner } from "@dub/ui/icons"; | ||
import { capitalize, currencyFormatter, fetcher, nFormatter } from "@dub/utils"; | ||
import { LinearGradient } from "@visx/gradient"; | ||
import { useContext, useId, useMemo } from "react"; | ||
import useSWR from "swr"; | ||
|
||
export function AnalyticsChart() { | ||
const id = useId(); | ||
|
||
const { queryParams } = useRouterStuff(); | ||
|
||
const { | ||
start, | ||
end, | ||
interval, | ||
selectedTab, | ||
saleUnit, | ||
view, | ||
totalEvents, | ||
queryString, | ||
} = useContext(AnalyticsContext); | ||
|
||
const { data, error } = useSWR< | ||
{ | ||
start: Date; | ||
clicks: number; | ||
leads: number; | ||
sales: number; | ||
saleAmount: number; | ||
}[] | ||
>( | ||
`/api/analytics?${editQueryString(queryString ?? "", { | ||
event: "composite", | ||
groupBy: "timeseries", | ||
})}`, | ||
fetcher, | ||
); | ||
|
||
const chartData = useMemo( | ||
() => | ||
data?.map((d) => ({ | ||
date: new Date(d.start), | ||
values: { | ||
amount: | ||
selectedTab === "sales" && saleUnit === "saleAmount" | ||
? d.saleAmount / 100 | ||
: d[selectedTab], | ||
}, | ||
})), | ||
[data, selectedTab, saleUnit], | ||
); | ||
|
||
const dataLoading = !chartData && !error; | ||
|
||
return ( | ||
<div> | ||
<div className="border-b border-neutral-200"> | ||
<AnalyticsTabs | ||
showConversions={true} | ||
totalEvents={totalEvents} | ||
tab={selectedTab} | ||
tabHref={(id) => | ||
queryParams({ | ||
set: { | ||
event: id, | ||
}, | ||
getNewPath: true, | ||
}) as string | ||
} | ||
saleUnit={saleUnit} | ||
setSaleUnit={(option) => | ||
queryParams({ | ||
set: { saleUnit: option }, | ||
}) | ||
} | ||
/> | ||
</div> | ||
<div className="relative h-72 md:h-96"> | ||
{dataLoading ? ( | ||
<div className="flex size-full items-center justify-center"> | ||
<LoadingSpinner /> | ||
</div> | ||
) : error ? ( | ||
<div className="flex size-full items-center justify-center text-sm text-neutral-500"> | ||
Failed to load data | ||
</div> | ||
) : ( | ||
<> | ||
{view === "timeseries" ? ( | ||
<div className="relative size-full p-6 pt-10"> | ||
<TimeSeriesChart | ||
key={`${start?.toString()}-${end?.toString()}-${interval ?? ""}-${selectedTab}-${saleUnit}`} | ||
data={chartData || []} | ||
series={[ | ||
{ | ||
id: "amount", | ||
valueAccessor: (d) => d.values.amount, | ||
colorClassName: "text-[#8B5CF6]", | ||
isActive: true, | ||
}, | ||
]} | ||
tooltipClassName="p-0" | ||
tooltipContent={(d) => { | ||
return ( | ||
<> | ||
<p className="border-b border-neutral-200 px-4 py-3 text-sm text-neutral-900"> | ||
{formatDateTooltip(d.date, { interval, start, end })} | ||
</p> | ||
<div className="grid grid-cols-2 gap-x-6 gap-y-2 px-4 py-3 text-sm"> | ||
<div className="flex items-center gap-2"> | ||
<div className="h-2 w-2 rounded-sm bg-violet-500 shadow-[inset_0_0_0_1px_#0003]" /> | ||
<p className="capitalize text-neutral-600"> | ||
{capitalize(selectedTab)} | ||
</p> | ||
</div> | ||
<p className="text-right font-medium text-neutral-900"> | ||
{selectedTab === "sales" && | ||
saleUnit === "saleAmount" | ||
? currencyFormatter(d.values.amount, { | ||
minimumFractionDigits: 2, | ||
maximumFractionDigits: 2, | ||
}) | ||
: nFormatter(d.values.amount)} | ||
</p> | ||
</div> | ||
</> | ||
); | ||
}} | ||
> | ||
<ChartContext.Consumer> | ||
{(context) => ( | ||
<LinearGradient | ||
id={`${id}-color-gradient`} | ||
from="#7D3AEC" | ||
to="#DA2778" | ||
x1={0} | ||
x2={context?.width ?? 1} | ||
gradientUnits="userSpaceOnUse" | ||
/> | ||
)} | ||
</ChartContext.Consumer> | ||
<XAxis | ||
tickFormat={(date) => | ||
formatDateTooltip(date, { interval, start, end }) | ||
} | ||
/> | ||
<YAxis | ||
showGridLines | ||
tickFormat={ | ||
selectedTab === "sales" && saleUnit === "saleAmount" | ||
? currencyFormatter | ||
: nFormatter | ||
} | ||
/> | ||
<Areas /> | ||
</TimeSeriesChart> | ||
</div> | ||
) : ( | ||
<AnalyticsFunnelChart /> | ||
)} | ||
<ChartViewSwitcher className="absolute right-3 top-3" /> | ||
</> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.