-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add fronts banner ads to UK front under AB test
- Loading branch information
Showing
7 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
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
68 changes: 68 additions & 0 deletions
68
bundle/src/projects/commercial/modules/fronts-banner-adverts.ts
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,68 @@ | ||
import { createAdSlot, slotSizeMappings } from '@guardian/commercial-core'; | ||
import fastdom from '../../../lib/fastdom-promise'; | ||
import { addSlot } from './dfp/add-slot'; | ||
|
||
/** | ||
* A fronts banner advert will be inserted above each of the following sections. | ||
*/ | ||
const sections = [ | ||
'opinion', | ||
'sport', | ||
'around-the-world', | ||
'lifestyle', | ||
'in-pictures', | ||
]; | ||
|
||
const insertAdvertAboveSection = async (section: string, advertNum: number) => { | ||
await fastdom.measure(() => { | ||
const sectionNode = document.querySelector(`section#${section}`); | ||
if (!sectionNode) return; | ||
|
||
const ad = createAdSlot('fronts-banner', { | ||
name: `fronts-banner-${advertNum}`, | ||
classes: 'fronts-banner', | ||
}); | ||
|
||
const adContainer = document.createElement('div'); | ||
adContainer.className = 'ad-slot-container fronts-banner-container'; | ||
adContainer.appendChild(ad); | ||
|
||
void fastdom | ||
.mutate(() => { | ||
sectionNode.parentElement?.insertBefore( | ||
adContainer, | ||
sectionNode, | ||
); | ||
}) | ||
.then(async () => { | ||
await addSlot(ad, false, slotSizeMappings['fronts-banner']); | ||
}); | ||
}); | ||
}; | ||
|
||
export const init = async (): Promise<void> => { | ||
const { switches, tests } = window.guardian.config; | ||
if ( | ||
!switches.frontsBannerAds || | ||
tests?.frontsBannerAdsVariant !== 'variant' | ||
) { | ||
return Promise.resolve(); | ||
} | ||
|
||
const { | ||
isDotcomRendering, | ||
page: { contentType, edition }, | ||
} = window.guardian.config; | ||
|
||
const isUkNetworkFront = | ||
contentType === 'Network Front' && edition === 'UK'; | ||
if (!isUkNetworkFront || isDotcomRendering) { | ||
return Promise.resolve(); | ||
} | ||
|
||
sections.map(async (section, index) => { | ||
await insertAdvertAboveSection(section, index + 1); | ||
}); | ||
|
||
return Promise.resolve(); | ||
}; |
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
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