-
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.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
5 changed files
with
79 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import ReactGA from 'react-ga4'; | ||
|
||
const GA_ID = process.env.REACT_APP_GA_ID || process.env.VITE_GA_ID || process.env.CF_GA_ID; | ||
const isProduction = process.env.NODE_ENV === 'production'; | ||
|
||
export const initGA = () => { | ||
if (!GA_ID) { | ||
if (!isProduction) { | ||
console.log('Analytics disabled: No measurement ID available'); | ||
} | ||
return; | ||
} | ||
|
||
try { | ||
ReactGA.initialize(GA_ID, { | ||
gaOptions: { | ||
debug_mode: !isProduction | ||
} | ||
}); | ||
// Send initial pageview | ||
ReactGA.send({ | ||
hitType: "pageview", | ||
page: window.location.pathname, | ||
title: "Match Five - Word Association Game" | ||
}); | ||
} catch (error) { | ||
if (!isProduction) { | ||
console.warn('Failed to initialize Google Analytics:', error); | ||
} | ||
} | ||
}; | ||
|
||
export const logPageView = (page: string) => { | ||
if (!GA_ID) return; | ||
|
||
try { | ||
ReactGA.send({ | ||
hitType: "pageview", | ||
page, | ||
title: "Match Five - Word Association Game" | ||
}); | ||
} catch (error) { | ||
if (!isProduction) { | ||
console.warn('Failed to log page view:', error); | ||
} | ||
} | ||
}; | ||
|
||
export const logGameEvent = (action: string, label?: string, value?: number) => { | ||
if (!GA_ID) return; | ||
|
||
try { | ||
ReactGA.event({ | ||
category: 'Game', | ||
action, | ||
label, | ||
value | ||
}); | ||
} catch (error) { | ||
if (!isProduction) { | ||
console.warn('Failed to log game event:', error); | ||
} | ||
} | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.