forked from benvinegar/counterscale
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track city and region of site visitors
resolves benvinegar#85
- Loading branch information
1 parent
8f67e80
commit 557d87f
Showing
8 changed files
with
187 additions
and
5 deletions.
There are no files selected for viewing
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 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 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,42 @@ | ||
import { useFetcher } from "@remix-run/react"; | ||
|
||
import type { LoaderFunctionArgs } from "@remix-run/cloudflare"; | ||
import { json } from "@remix-run/cloudflare"; | ||
|
||
import { paramsFromUrl } from "~/lib/utils"; | ||
import PaginatedTableCard from "~/components/PaginatedTableCard"; | ||
|
||
export async function loader({ context, request }: LoaderFunctionArgs) { | ||
const { analyticsEngine } = context; | ||
|
||
const { interval, site, page = 1 } = paramsFromUrl(request.url); | ||
const tz = context.requestTimezone as string; | ||
|
||
return json({ | ||
countsByProperty: await analyticsEngine.getCountByCity( | ||
site, | ||
interval, | ||
tz, | ||
Number(page), | ||
), | ||
page: Number(page), | ||
}); | ||
} | ||
|
||
export const CityCard = ({ | ||
siteId, | ||
interval, | ||
}: { | ||
siteId: string; | ||
interval: string; | ||
}) => { | ||
return ( | ||
<PaginatedTableCard | ||
siteId={siteId} | ||
interval={interval} | ||
columnHeaders={["City", "Visitors"]} | ||
dataFetcher={useFetcher<typeof loader>()} | ||
loaderUrl="/resources/city" | ||
/> | ||
); | ||
}; |
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,42 @@ | ||
import { useFetcher } from "@remix-run/react"; | ||
|
||
import type { LoaderFunctionArgs } from "@remix-run/cloudflare"; | ||
import { json } from "@remix-run/cloudflare"; | ||
|
||
import { paramsFromUrl } from "~/lib/utils"; | ||
import PaginatedTableCard from "~/components/PaginatedTableCard"; | ||
|
||
export async function loader({ context, request }: LoaderFunctionArgs) { | ||
const { analyticsEngine } = context; | ||
|
||
const { interval, site, page = 1 } = paramsFromUrl(request.url); | ||
const tz = context.requestTimezone as string; | ||
|
||
return json({ | ||
countsByProperty: await analyticsEngine.getCountByRegion( | ||
site, | ||
interval, | ||
tz, | ||
Number(page), | ||
), | ||
page: Number(page), | ||
}); | ||
} | ||
|
||
export const RegionCard = ({ | ||
siteId, | ||
interval, | ||
}: { | ||
siteId: string; | ||
interval: string; | ||
}) => { | ||
return ( | ||
<PaginatedTableCard | ||
siteId={siteId} | ||
interval={interval} | ||
columnHeaders={["Region", "Visitors"]} | ||
dataFetcher={useFetcher<typeof loader>()} | ||
loaderUrl="/resources/region" | ||
/> | ||
); | ||
}; |