Skip to content

Commit

Permalink
Test shared function for utagView called both manually after a delay …
Browse files Browse the repository at this point in the history
…for initial page load and immediately for subsequent page loads
  • Loading branch information
haworku committed Mar 22, 2024
1 parent 771a075 commit fde120a
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions services/app-web/src/hooks/useTealium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,29 @@ const useTealium = (): {
user: loggedInUser,
})

const callUTagView = () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
const utag = window.utag || { link: () => {}, view: () => {} }
const tagData: TealiumViewDataObject = {
content_language: 'en',
content_type: `${CONTENT_TYPE_BY_ROUTE[currentRoute]}`,
page_name: tealiumPageName,
page_path: pathname,
site_domain: 'cms.gov',
site_environment: `${process.env.REACT_APP_STAGE_NAME}`,
site_section: `${currentRoute}`,
logged_in: `${Boolean(loggedInUser) ?? false}`,
}
utag.view(tagData)
}

// Add Tealium setup
// this effect should only fire on initial app load
useEffect(() => {
// Do not add tealium for local dev or review apps
// if (process.env.REACT_APP_AUTH_MODE !== 'IDM') {
// return
// }
// if (process.env.REACT_APP_AUTH_MODE !== 'IDM') {
// return
// }

const tealiumEnv = getTealiumEnv(
process.env.REACT_APP_STAGE_NAME || 'main'
Expand Down Expand Up @@ -116,22 +132,12 @@ const useTealium = (): {
recordJSException('Analytics did not load in time')
return
} else {
// eslint-disable-next-line @typescript-eslint/no-empty-function
const utag = window.utag || { link: () => {}, view: () => {} }
const tagData: TealiumViewDataObject = {
content_language: 'en',
content_type: `${CONTENT_TYPE_BY_ROUTE[currentRoute]}`,
page_name: tealiumPageName,
page_path: pathname,
site_domain: 'cms.gov',
site_environment: `${process.env.REACT_APP_STAGE_NAME}`,
site_section: `${currentRoute}`,
logged_in: `${Boolean(loggedInUser) ?? false}`,
}
utag.view(tagData)
callUTagView()
}
}
).catch(() => { return })
} else {
callUTagView()
}

}, [currentRoute, loggedInUser, pathname, tealiumPageName])
Expand Down

0 comments on commit fde120a

Please sign in to comment.