Skip to content

Commit

Permalink
Update analytics to not depend on debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
drbgfc committed Oct 8, 2024
1 parent f53fbcf commit 07c4a19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ NEXT_PUBLIC_RELEASE_VERSION_URL=https://raw.githubusercontent.com/onc-healthit/s
NEXT_PUBLIC_RELEASE_DATE_URL=https://raw.githubusercontent.com/onc-healthit/site-content/master/site-ui-4/release-date.md

# TODO: Allow for these to be dynamic per environment file and delete from here.
# For now though, these are STATIC as this file is injected in the build,
# and NEXT_PUBLIC env vars are not overridden by other env file definitions
# See: https://phase.dev/blog/nextjs-public-runtime-variables/
NEXT_PUBLIC_IS_DEBUG_MODE=false
NEXT_PUBLIC_IS_EVENT_TRACKING=true
Expand Down
9 changes: 5 additions & 4 deletions src/services/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
'use client'
// Note: Explicitly defining 'use client' as this funciton uses 'window', which is part of the browser
/*
eventType: Describes the type of action being tracked, Button Click Form Submission, Dropdown Selection,
Link Click, Sub Menu Anchor Link Click, etc.
eventCategory: Groups events together, such as by a specific tool name or navigation page
eventLabel: Provides specific details for the event such as what the action and outcome is after the event is fired
*/
const eventTrack = (eventType: string, eventCategory: string, eventLabel: string) => {
if (typeof window.gtag === 'function') {
if (process.env.NEXT_PUBLIC_IS_DEBUG_MODE === 'true') {
if (process.env.NEXT_PUBLIC_IS_EVENT_TRACKING === 'true') {
if (typeof window.gtag === 'function') {
console.info({
event: eventType,
eventCategory: eventCategory,
eventLabel: eventLabel,
})
}
if (process.env.NEXT_PUBLIC_IS_EVENT_TRACKING === 'true') {

window.gtag('event', eventType, {
event_category: eventCategory,
event_label: eventLabel,
Expand Down

0 comments on commit 07c4a19

Please sign in to comment.