-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14439af
commit 6f09ec8
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/app/components/ATIAnalytics/canonical/sendBeaconTranscript.tsx
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,47 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { getEnvConfig } from '#app/lib/utilities/getEnvConfig'; | ||
import isOperaProxy from '#app/lib/utilities/isOperaProxy'; | ||
import sendBeacon from '../../../lib/analyticsUtils/sendBeacon'; | ||
import { ATIAnalyticsProps } from '../types'; | ||
|
||
// some other metric? | ||
const getNoJsATIPageViewUrl = (atiPageViewUrl: string) => | ||
atiPageViewUrl.includes('x8=[simorgh]') | ||
? atiPageViewUrl.replace('x8=[simorgh]', 'x8=[simorgh-nojs]') | ||
: `${atiPageViewUrl}&x8=[BLAH]`; | ||
|
||
const renderNoScriptTrackingPixel = (atiPageViewUrl: string) => { | ||
return ( | ||
<noscript> | ||
<img | ||
height="1px" | ||
width="1px" | ||
alt="" | ||
// This should probably have been a styled component. But the author is | ||
// lazy and didn't want to write a fuzzy matcher for the unit AND e2e | ||
// tests (you can't predict the class names chosen by emotion) | ||
style={{ position: 'absolute' }} | ||
src={getNoJsATIPageViewUrl(atiPageViewUrl)} | ||
/> | ||
</noscript> | ||
); | ||
}; | ||
|
||
const MyAnalytics = ({ pageviewParams }: ATIAnalyticsProps) => { | ||
const atiPageViewUrlString = | ||
getEnvConfig().SIMORGH_ATI_BASE_URL + pageviewParams; | ||
|
||
console.log('atiPageViewUrlString', atiPageViewUrlString); | ||
|
||
const [atiPageViewUrl] = useState(atiPageViewUrlString); | ||
|
||
console.log('atiPageViewUrl', atiPageViewUrl); | ||
|
||
useEffect(() => { | ||
if (!isOperaProxy()) sendBeacon(atiPageViewUrl); | ||
}, [atiPageViewUrl]); | ||
|
||
return <>{renderNoScriptTrackingPixel(atiPageViewUrl)}</>; | ||
}; | ||
|
||
export default MyAnalytics; |
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,22 @@ | ||
import React, { useContext } from 'react'; | ||
import { RequestContext } from '#contexts/RequestContext'; | ||
import { ServiceContext } from '../../contexts/ServiceContext'; | ||
import MyAnalytics from './canonical/sendBeaconTranscript'; | ||
import { ATIProps } from './types'; | ||
import buildATIUrl from './params'; | ||
|
||
const ATIAnalyticsTranscript = ({ data, atiData }: ATIProps) => { | ||
const requestContext = useContext(RequestContext); | ||
const serviceContext = useContext(ServiceContext); | ||
|
||
const pageviewParams = buildATIUrl({ | ||
requestContext, | ||
serviceContext, | ||
data, | ||
atiData, | ||
}) as string; | ||
|
||
return <MyAnalytics pageviewParams={pageviewParams} />; | ||
}; | ||
|
||
export default ATIAnalyticsTranscript; |
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