Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert AA error event changes #748

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 2 additions & 51 deletions components/MetaData.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Head from 'next/head'
import { useRouter } from 'next/router'
import Script from 'next/script'
import { useEffect } from 'react'

interface Content {
title: string
Expand All @@ -11,7 +9,6 @@ interface Content {
creator: string
accessRights: string
service: string
statusCode?: string
}

interface Data {
Expand All @@ -24,51 +21,8 @@ interface MetaDataProps {
data: Data
}

// To help prevent double firing of adobe analytics pageLoad event
let appPreviousLocationPathname = ''

/* eslint-disable */
// make typescript happy
declare global {
interface Window {
adobeDataLayer: any
}
}
/* eslint-enable */

const MetaData = ({ language, data }: MetaDataProps) => {
const router = useRouter()
const d = language === 'en' ? data.data_en : data.data_fr
const isErrorPage = typeof d.statusCode !== 'undefined'
/** Web Analytics - taken from Google Analytics example
* @see https://github.com/vercel/next.js/blob/canary/examples/with-google-analytics
* */
useEffect(() => {
const handleRouteChange = () => {
// only push event if pathname is different
if (window.location.pathname !== appPreviousLocationPathname) {
if (isErrorPage) {
window.adobeDataLayer?.push?.({
event: 'error',
error: {
name: d.statusCode,
},
})
} else {
window.adobeDataLayer?.push?.({ event: 'pageLoad' })
}
appPreviousLocationPathname = window.location.pathname
}
}

handleRouteChange()
router.events.on('routeChangeComplete', handleRouteChange)
router.events.on('hashChangeComplete', handleRouteChange)
return () => {
router.events.off('routeChangeComplete', handleRouteChange)
router.events.off('hashChangeComplete', handleRouteChange)
}
}, [router.events])

return (
<>
Expand All @@ -88,11 +42,8 @@ const MetaData = ({ language, data }: MetaDataProps) => {
}
`}
</style>
{isErrorPage ? (
<title data-gc-analytics-error={d.statusCode}>{d.title}</title>
) : (
<title>{d.title}</title>
)}

<title>{d.title}</title>

<meta charSet="utf-8" />
<meta name="description" content={d.desc} />
Expand Down
2 changes: 0 additions & 2 deletions pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
service: 'ESDC-EDSC_MSCA-MSDC-SCH',
creator: 'Employment and Social Development Canada',
accessRights: '1',
statusCode: '404',
},
data_fr: {
title: `Nous ne pouvons trouver cette page Web - 404 - Mon dossier Service Canada`,
Expand All @@ -70,7 +69,6 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
service: 'ESDC-EDSC_MSCA-MSDC-SCH',
creator: 'Emploi et Développement social Canada',
accessRights: '1',
statusCode: '404',
},
}
return {
Expand Down
2 changes: 0 additions & 2 deletions pages/500.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
service: 'ESDC-EDSC_MSCA-MSDC-SCH',
creator: 'Employment and Social Development Canada',
accessRights: '1',
statusCode: '500',
},
data_fr: {
title: `Nous ne pouvons trouver cette page Web - 500 - Mon dossier Service Canada`,
Expand All @@ -70,7 +69,6 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {
service: 'ESDC-EDSC_MSCA-MSDC-SCH',
creator: 'Emploi et Développement social Canada',
accessRights: '1',
statusCode: '500',
},
}
return {
Expand Down
25 changes: 25 additions & 0 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { config } from '@fortawesome/fontawesome-svg-core'
import '@fortawesome/fontawesome-svg-core/styles.css'
import Modal from 'react-modal'
import ErrorBoundary from '../components/ErrorBoundary'
import { useEffect } from 'react'
config.autoAddCss = false

// To help prevent double firing of adobe analytics pageLoad event
let appPreviousLocationPathname = ''

export default function MyApp({ Component, pageProps, router }) {
/* istanbul ignore next */
if (Component.getLayout) {
Expand All @@ -16,6 +20,27 @@ export default function MyApp({ Component, pageProps, router }) {
Modal.setAppElement('#__next')
const display = { hideBanner: pageProps.hideBanner }

/** Web Analytics - taken from Google Analytics example
* @see https://github.com/vercel/next.js/blob/canary/examples/with-google-analytics
* */
useEffect(() => {
const handleRouteChange = () => {
// only push event if pathname is different
if (window.location.pathname !== appPreviousLocationPathname) {
window.adobeDataLayer?.push?.({ event: 'pageLoad' })
appPreviousLocationPathname = window.location.pathname
}
}

handleRouteChange()
router.events.on('routeChangeComplete', handleRouteChange)
router.events.on('hashChangeComplete', handleRouteChange)
return () => {
router.events.off('routeChangeComplete', handleRouteChange)
router.events.off('hashChangeComplete', handleRouteChange)
}
}, [router.events])

/* istanbul ignore next */
return (
<ErrorBoundary>
Expand Down
Loading