File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// Enable analytics during development - for debugging purposes
2- // Analytics are always enabled in non-dev environments
2+ // Analytics are always enabled in non-dev environments if a measurement ID is provided
33NEXT_PUBLIC_ENABLE_ANALYTICS = false
44// Enables ads during development - for debugging purposes
5- // Ads are always enabled in non-dev environments
5+ // Ads are always enabled in non-dev environments if a publisher ID is provided
66NEXT_PUBLIC_ENABLE_ADS = false
77
88// Google Analytics measurement ID - not required
Original file line number Diff line number Diff line change @@ -3,7 +3,16 @@ import React from "react";
33import { getEnvironment } from "@/scripts/Utils/Environment" ;
44
55export function Adsense ( ) : React . ReactNode {
6+ const [ useGA , setUseGA ] = React . useState < boolean > ( false ) ;
7+
68 React . useEffect ( ( ) => {
9+ if (
10+ process . env . NEXT_PUBLIC_ADSENSE_PUBLISHER_ID === "pub-XXXXXXXXXXXXXXXX" ||
11+ ! process . env . NEXT_PUBLIC_ADSENSE_PUBLISHER_ID
12+ ) {
13+ // console.info("No publisher ID provided, disabling Google Adsense");
14+ return ;
15+ }
716 if ( getEnvironment ( ) === "development" ) {
817 if ( process . env . NEXT_PUBLIC_ENABLE_ADS ) {
918 console . info ( "Enabling Google Adsense during development" ) ;
@@ -12,13 +21,11 @@ export function Adsense(): React.ReactNode {
1221 return ;
1322 }
1423 }
24+
25+ setUseGA ( true ) ;
1526 } , [ ] ) ;
1627
17- return getEnvironment ( ) === "development" ? (
18- < > </ >
19- ) : (
20- < GoogleAdSense publisherId = "pub-XXXXXXXXXXXXXXXX" />
21- ) ;
28+ return useGA ? < > </ > : < GoogleAdSense publisherId = "pub-XXXXXXXXXXXXXXXX" /> ;
2229}
2330
2431export default Adsense ;
Original file line number Diff line number Diff line change @@ -67,6 +67,13 @@ export function Analytics(): React.ReactNode {
6767 analytics_storage : getAnalyticsStorageConsent ( ) ,
6868 } ) ;
6969
70+ if (
71+ process . env . NEXT_PUBLIC_GA_MEASUREMENT_ID === "G-XXXXXXXXXX" ||
72+ ! process . env . NEXT_PUBLIC_GA_MEASUREMENT_ID
73+ ) {
74+ console . info ( "No measurement ID provided, disabling Google Analytics" ) ;
75+ return ;
76+ }
7077 if ( getEnvironment ( ) === "development" ) {
7178 if ( process . env . NEXT_PUBLIC_ENABLE_ANALYTICS ) {
7279 console . info ( "Enabling Google Analytics during development" ) ;
Original file line number Diff line number Diff line change 1+ import { ListLayout } from "@/components/AwesomeArcadeList/listLayout" ;
2+
13export namespace AnalyticEvents {
24 export function sendAwesomeClick ( type : "extension" | "tool" , repo : string ) {
35 window . gtag ( "event" , "click_awesome" , {
@@ -31,4 +33,17 @@ export namespace AnalyticEvents {
3133 variationId,
3234 } ) ;
3335 }
36+
37+ export function setUserPreferredTheme (
38+ theme : "light" | "dark" | "auto light" | "auto dark" ,
39+ ) {
40+ // https://ithoughthecamewithyou.com/post/user-scoped-custom-dimensions-in-google-analytics-4-using-gtag
41+ console . log ( `Setting user preferred theme to ${ theme } ` ) ;
42+ window . gtag ( "set" , "user_properties" , { theme : theme } ) ;
43+ }
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+ }
3449}
Original file line number Diff line number Diff line change 11import React from "react" ;
2+ import { AnalyticEvents } from "@/components/Analytics/specific" ;
23
34const ListLayouts = [ "masonry" , "grid" , "github" ] as const ;
45export 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
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