Skip to content

Commit ddd368f

Browse files
Track user preferred layout
Fixes #166
1 parent 73024f6 commit ddd368f

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/components/Analytics/specific.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ListLayout } from "@/components/AwesomeArcadeList/listLayout";
2+
13
export namespace AnalyticEvents {
24
export function sendAwesomeClick(type: "extension" | "tool", repo: string) {
35
window.gtag("event", "click_awesome", {
@@ -36,7 +38,12 @@ export namespace AnalyticEvents {
3638
theme: "light" | "dark" | "auto light" | "auto dark",
3739
) {
3840
// https://ithoughthecamewithyou.com/post/user-scoped-custom-dimensions-in-google-analytics-4-using-gtag
39-
// console.log(`Setting user preferred theme to ${theme}`);
41+
console.log(`Setting user preferred theme to ${theme}`);
4042
window.gtag("set", "user_properties", { theme: theme });
4143
}
44+
45+
export function setUserPreferredLayout(layout: ListLayout) {
46+
console.log(`Setting user preferred layout to ${layout}`);
47+
window.gtag("set", "user_properties", { layout: layout });
48+
}
4249
}

src/components/AwesomeArcadeList/listLayout.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import { AnalyticEvents } from "@/components/Analytics/specific";
23

34
const ListLayouts = ["masonry", "grid", "github"] as const;
45
export type ListLayout = (typeof ListLayouts)[number];
@@ -28,12 +29,10 @@ export default function NavbarDropdownListLayoutPicker({
2829
const [layout, setLayout] = React.useState<ListLayout>("masonry");
2930

3031
React.useEffect(() => {
31-
const l = window.localStorage.getItem("listLayout");
32-
if (l) {
33-
setLayout(l as ListLayout);
34-
} else {
35-
setLayout("masonry");
36-
}
32+
const l = (window.localStorage.getItem("listLayout") ??
33+
"masonry") as ListLayout;
34+
setLayout(l);
35+
AnalyticEvents.setUserPreferredLayout(l);
3736
// eslint-disable-next-line react-hooks/exhaustive-deps
3837
}, []);
3938

0 commit comments

Comments
 (0)