Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ describe('dotcom-ui-shell/src/components/GTMHead', () => {
const props = {
flags: {
enableGTM: true
}
},
appName: 'next-article'
}

const tree = renderer.create(<GTMHead {...props} />).toJSON()
Expand Down
27 changes: 19 additions & 8 deletions packages/dotcom-ui-shell/src/components/GTMHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@ import React from 'react'
import { TFlagsData } from '@financial-times/dotcom-ui-flags/src/types'

// This component is maintained by the ads team
const GTMHead = ({ flags }: { flags: TFlagsData }) => {
if (!flags.enableGTM) {
return null
}

const src = flags['ads-first-party-gtm']
? 'https://www.ft.com/page-resources/'
: 'https://www.googletagmanager.com/gtm.js?id=GTM-NWQJW68'
type Props = {
flags: TFlagsData
appName?: string
}

// This component is maintained by the ads team
const GTMHead = ({ flags, appName }: Props) => {
if (!flags.enableGTM) return null

// 1) If appName is artcile-partner-content use the PC GTM instance
const PCAppOverride =
appName === 'article-partner-content' ? 'https://www.googletagmanager.com/gtm.js?id=GTM-12345' : null

// 2) If appName is not Partner Content, use the standard FT.com GTM isntance and use the first-party GTM domain if flag is set.
const src =
PCAppOverride ??
(flags['ads-first-party-gtm']
? 'https://www.ft.com/page-resources/'
: 'https://www.googletagmanager.com/gtm.js?id=GTM-NWQJW68')

const tagManager = `(function(w,d,s,l){
w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});
Expand Down
2 changes: 1 addition & 1 deletion packages/dotcom-ui-shell/src/components/Shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Shell(props: TShellProps) {
asyncStylesheets={props.asyncStylesheets}
/>
<Bootstrap {...bootstrapProps} />
<GTMHead flags={props.flags} />
<GTMHead flags={props.flags} appName={props.appContext?.appName} />
</head>
<body {...formatAttributeNames(props.bodyAttributes)}>
<GTMBody flags={props.flags} />
Expand Down