File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,4 +31,12 @@ export namespace AnalyticEvents {
3131 variationId,
3232 } ) ;
3333 }
34+
35+ export function setUserPreferredTheme (
36+ theme : "light" | "dark" | "auto light" | "auto dark" ,
37+ ) {
38+ // https://ithoughthecamewithyou.com/post/user-scoped-custom-dimensions-in-google-analytics-4-using-gtag
39+ // console.log(`Setting user preferred theme to ${theme}`);
40+ window . gtag ( "set" , "user_properties" , { theme : theme } ) ;
41+ }
3442}
Original file line number Diff line number Diff line change 11import React from "react" ;
2+ import { AnalyticEvents } from "@/components/Analytics/specific" ;
23
34export type Theme = "Light" | "Dark" ;
45export type ThemeOptions = Theme | "Auto" ;
@@ -175,6 +176,16 @@ export function ThemeProxy({
175176 } ) ,
176177 ) ;
177178 window . localStorage . setItem ( "theme" , dropdownTheme ) ;
179+
180+ if ( dropdownTheme === "Auto" ) {
181+ AnalyticEvents . setUserPreferredTheme (
182+ osWantsDark . matches ? "auto dark" : "auto light" ,
183+ ) ;
184+ } else {
185+ AnalyticEvents . setUserPreferredTheme (
186+ dropdownTheme . toLowerCase ( ) as "light" | "dark" ,
187+ ) ;
188+ }
178189 }
179190 } , [ dropdownTheme , loadedPreferredTheme ] ) ;
180191
You can’t perform that action at this time.
0 commit comments