-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add support for top_base_urls
#3120
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ export function AnalyticsChart() { | |
| values: { | ||
| amount: | ||
| selectedTab === "sales" && saleUnit === "saleAmount" | ||
| ? d.saleAmount / 100 | ||
| ? d.saleAmount | ||
| : d[selectedTab], | ||
|
Comment on lines
40
to
43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainPlease verify
You can sanity-check consistency with a quick search: 🏁 Script executed: #!/bin/bash
# Look for other places that scale saleAmount
rg -n "saleAmount\s*/\s*100" .
# Inspect other usages of saleAmount in the web app
rg -n "saleAmount" apps/web -C3Length of output: 143921 Verify backend consistency for The removed
The API schema in This indicates either:
Confirm that 🤖 Prompt for AI Agents |
||
| }, | ||
| })), | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,51 +11,75 @@ import { AnalyticsContext } from "./analytics-provider"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| import BarList from "./bar-list"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useAnalyticsFilterOption } from "./utils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| type TabId = "referers" | "utms"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| type RefererSubtab = "referers" | "referer_urls"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| type Subtab = UTM_TAGS_PLURAL | RefererSubtab; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const TAB_CONFIG: Record< | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TabId, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| subtabs: Subtab[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultSubtab: Subtab; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| getSubtabLabel: (subtab: Subtab) => string; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| > = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| referers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| subtabs: ["referers", "referer_urls"], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultSubtab: "referers", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| getSubtabLabel: (subtab) => (subtab === "referers" ? "Domain" : "URL"), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| utms: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| subtabs: [...UTM_TAGS_PLURAL_LIST] as Subtab[], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultSubtab: "utm_sources" as Subtab, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| getSubtabLabel: (subtab) => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| SINGULAR_ANALYTICS_ENDPOINTS[subtab as UTM_TAGS_PLURAL].replace( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "utm_", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| export default function Referer() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const { queryParams, searchParams } = useRouterStuff(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const { selectedTab, saleUnit } = useContext(AnalyticsContext); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const dataKey = selectedTab === "sales" ? saleUnit : "count"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const [tab, setTab] = useState<"referers" | "utms">("referers"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const [utmTag, setUtmTag] = useState<UTM_TAGS_PLURAL>("utm_sources"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const [refererType, setRefererType] = useState<"referers" | "referer_urls">( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "referers", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const [tab, setTab] = useState<TabId>("referers"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const [subtab, setSubtab] = useState<Subtab>(TAB_CONFIG[tab].defaultSubtab); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Reset subtab when tab changes to ensure it's valid for the new tab | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleTabChange = (newTab: TabId) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| setTab(newTab); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| setSubtab(TAB_CONFIG[newTab].defaultSubtab); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data } = useAnalyticsFilterOption({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| groupBy: tab === "utms" ? utmTag : refererType, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| groupBy: subtab, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const singularTabName = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| SINGULAR_ANALYTICS_ENDPOINTS[tab === "utms" ? utmTag : refererType]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const singularTabName = SINGULAR_ANALYTICS_ENDPOINTS[subtab]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const { icon: UTMTagIcon } = UTM_PARAMETERS.find( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| (p) => p.key === utmTag.slice(0, -1), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| )!; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const UTMTagIcon = useMemo(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (tab === "utms") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return UTM_PARAMETERS.find( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| (p) => p.key === (subtab as UTM_TAGS_PLURAL).slice(0, -1), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| )?.icon; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [tab, subtab]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const subTabProps = useMemo(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| utms: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| subTabs: UTM_TAGS_PLURAL_LIST.map((u) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| id: u, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| label: SINGULAR_ANALYTICS_ENDPOINTS[u].replace("utm_", ""), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| })), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| selectedSubTabId: utmTag, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| onSelectSubTab: setUtmTag, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| referers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| subTabs: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { id: "referers", label: "Domain" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { id: "referer_urls", label: "URL" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| selectedSubTabId: refererType, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| onSelectSubTab: setRefererType, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }[tab] ?? {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [tab, utmTag, refererType]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const config = TAB_CONFIG[tab]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| subTabs: config.subtabs.map((s) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| id: s, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| label: config.getSubtabLabel(s), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| })), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| selectedSubTabId: subtab, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| onSelectSubTab: setSubtab, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [tab, subtab]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <AnalyticsCard | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -64,7 +88,7 @@ export default function Referer() { | |||||||||||||||||||||||||||||||||||||||||||||||||
| { id: "utms", label: "UTM Parameters", icon: Note }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ]} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| selectedTabId={tab} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| onSelectTab={setTab} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| onSelectTab={handleTabChange} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| {...subTabProps} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| expandLimit={8} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| hasMore={(data?.length ?? 0) > 8} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -77,38 +101,44 @@ export default function Referer() { | |||||||||||||||||||||||||||||||||||||||||||||||||
| tab={tab === "referers" ? "Referrer" : "UTM Parameter"} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| data={ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ?.map((d) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| icon: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| tab === "utms" ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <UTMTagIcon /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : d[singularTabName] === "(direct)" ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <Link2 className="h-4 w-4" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <BlurImage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| src={`${GOOGLE_FAVICON_URL}${ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| tab === "referers" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ? d[singularTabName] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| : getApexDomain(d[singularTabName]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }`} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| alt={d[singularTabName]} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| width={20} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| height={20} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| className="h-4 w-4 rounded-full" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| title: d[singularTabName], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| href: queryParams({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ...(searchParams.has(singularTabName) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ? { del: singularTabName } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| : { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| set: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| [singularTabName]: d[singularTabName], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| getNewPath: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }) as string, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| value: d[dataKey] || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ?.map((d) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const isUtmTab = tab === "utms"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const isDirect = d[singularTabName] === "(direct)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const isRefererUrl = subtab === "referer_urls"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| icon: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| isUtmTab && UTMTagIcon ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <UTMTagIcon /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : isDirect ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <Link2 className="h-4 w-4" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <BlurImage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| src={`${GOOGLE_FAVICON_URL}${ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| isRefererUrl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ? getApexDomain(d[singularTabName]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| : d[singularTabName] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }`} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| alt={d[singularTabName]} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| width={20} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| height={20} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| className="h-4 w-4 rounded-full" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| title: d[singularTabName], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| href: queryParams({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ...(searchParams.has(singularTabName) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ? { del: singularTabName } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| : { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| set: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| [singularTabName]: d[singularTabName], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| getNewPath: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }) as string, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| value: d[dataKey] || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+129
to
+139
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix UTM/referrer filter toggling
- href: queryParams({
- ...(searchParams.has(singularTabName)
- ? { del: singularTabName }
- : {
- set: {
- [singularTabName]: d[singularTabName],
- },
- }),
- getNewPath: true,
- }) as string,
+ href: queryParams({
+ ...(
+ searchParams.get(singularTabName) === d[singularTabName]
+ ? { del: singularTabName }
+ : {
+ set: {
+ [singularTabName]: d[singularTabName],
+ },
+ }
+ ),
+ getNewPath: true,
+ }) as string,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ?.sort((a, b) => b.value - a.value) || [] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| unit={selectedTab} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.