diff --git a/package.json b/package.json index 3ecdf729..db93bc0e 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@storybook/theming": "^7.4.2", "@sveltejs/vite-plugin-svelte": "^2.4.1", "@tsconfig/svelte": "^4.0.1", + "@types/google-publisher-tag": "^1.20240219.0", "@types/gtag.js": "^0.0.12", "@types/mdx": "^2.0.5", "@types/proper-url-join": "^2.1.1", diff --git a/src/components/AdSlot/@types/ads.ts b/src/components/AdSlot/@types/ads.ts new file mode 100644 index 00000000..5f033f2c --- /dev/null +++ b/src/components/AdSlot/@types/ads.ts @@ -0,0 +1,31 @@ +export type AdType = + | 'leaderboard' + | 'sponsorlogo' + | 'native' + | 'mpu' + | 'billboard'; + +export type PlacementName = + | 'reuters_desktop_leaderboard_atf' + | 'reuters_mobile_leaderboard' + | 'reuters_desktop_native_1' + | 'reuters_mobile_mpu_1' + | 'reuters_sponsorlogo' + | 'reuters_billboard_desktop'; + +export type DesktopPlacementName = + | 'reuters_desktop_leaderboard_atf' + | 'reuters_desktop_native_1' + | 'reuters_sponsorlogo' + | 'reuters_billboard_desktop'; + +export type MobilePlacementName = + DesktopPlacementName extends 'reuters_desktop_leaderboard_atf' + ? 'reuters_mobile_leaderboard' + : DesktopPlacementName extends 'reuters_desktop_native_1' + ? 'reuters_mobile_mpu_1' + : DesktopPlacementName extends 'reuters_sponsorlogo' + ? 'reuters_sponsorlogo' + : DesktopPlacementName extends 'reuters_billboard_desktop' + ? 'reuters_mobile_mpu_1' + : never; diff --git a/src/components/AdSlot/AdScripts.svelte b/src/components/AdSlot/AdScripts.svelte index 1e8111f6..3cc1dc39 100644 --- a/src/components/AdSlot/AdScripts.svelte +++ b/src/components/AdSlot/AdScripts.svelte @@ -2,35 +2,7 @@ import { onMount } from 'svelte'; import { loadBootstrap } from './adScripts/bootstrap'; import { loadScript } from './adScripts/loadScript'; - import { throttle } from 'lodash-es'; - - let lastScroll = 0; - let showManagePreferences = true; - - const togglePrefs = (on = true) => { - const btn = document.getElementById('ot-sdk-btn-floating'); - if (!btn) return; - if (on) { - showManagePreferences = true; - btn.style.bottom = ''; - } else { - showManagePreferences = false; - btn.style.bottom = '-5rem'; - } - }; - - const handleScroll = () => { - if (lastScroll > window.scrollY) { - if (!showManagePreferences) { - togglePrefs(true); - } - } else { - if (showManagePreferences && window.scrollY > 250) { - togglePrefs(false); - } - } - lastScroll = window.scrollY; - }; + import OneTrust from './OneTrust.svelte'; onMount(() => { window.graphicsAdQueue = window.graphicsAdQueue || []; @@ -38,9 +10,6 @@ 'https://graphics.thomsonreuters.com/cdn/js/bootstrap.static.js', loadBootstrap ); - window.addEventListener('scroll', throttle(handleScroll, 250), { - passive: true, - }); }); @@ -60,3 +29,5 @@ /> + + diff --git a/src/components/AdSlot/AdSlot.stories.svelte b/src/components/AdSlot/AdSlot.stories.svelte deleted file mode 100644 index 6e9edf18..00000000 --- a/src/components/AdSlot/AdSlot.stories.svelte +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - diff --git a/src/components/AdSlot/AdSlot.svelte b/src/components/AdSlot/AdSlot.svelte index 9828c5ff..c78646f6 100644 --- a/src/components/AdSlot/AdSlot.svelte +++ b/src/components/AdSlot/AdSlot.svelte @@ -1,126 +1,29 @@ - - -
-
Advertisement · Scroll to continue
-
-
-
-
-
-
-
-
-
- - +
diff --git a/src/components/AdSlot/InlineAd.stories.svelte b/src/components/AdSlot/InlineAd.stories.svelte new file mode 100644 index 00000000..a0f04095 --- /dev/null +++ b/src/components/AdSlot/InlineAd.stories.svelte @@ -0,0 +1,29 @@ + + + + + + + diff --git a/src/components/AdSlot/InlineAd.svelte b/src/components/AdSlot/InlineAd.svelte new file mode 100644 index 00000000..f3449009 --- /dev/null +++ b/src/components/AdSlot/InlineAd.svelte @@ -0,0 +1,69 @@ + + + + +
+
Advertisement · Scroll to continue
+
+
+
+ +
+
+
+
+
+ + diff --git a/src/components/AdSlot/OneTrust.svelte b/src/components/AdSlot/OneTrust.svelte new file mode 100644 index 00000000..2c44b3d0 --- /dev/null +++ b/src/components/AdSlot/OneTrust.svelte @@ -0,0 +1,39 @@ + + diff --git a/src/components/AdSlot/ResponsiveAd.svelte b/src/components/AdSlot/ResponsiveAd.svelte new file mode 100644 index 00000000..51541a88 --- /dev/null +++ b/src/components/AdSlot/ResponsiveAd.svelte @@ -0,0 +1,52 @@ + + + + +{#if windowWidth} + {#key placementName} + + {/key} +{/if} diff --git a/src/components/AdSlot/adScripts/bootstrap.ts b/src/components/AdSlot/adScripts/bootstrap.ts index cc8011d2..be41d5ec 100644 --- a/src/components/AdSlot/adScripts/bootstrap.ts +++ b/src/components/AdSlot/adScripts/bootstrap.ts @@ -19,8 +19,7 @@ export const loadBootstrap = () => { freestar.newAdSlots(freestar.config.enabled_slots); }; - // Ask Rachel - freestar.config.channel = '/4735792/reuters.com/home'; + freestar.config.channel = '/4735792/reuters.com/graphics'; (window).initBootstrap( { @@ -31,10 +30,6 @@ export const loadBootstrap = () => { }, (onetrustResponse) => { const iasPromise = Ias(); - - // Ask Thea about Permutive implementation (considering there are no logged in users on Graphics) - // Should we use Permutive at all? - // Should we import ArcP SDK to graphics to get the same user as logged in on RCom? return Promise.all([iasPromise]).then((responses) => { const [iasResponse] = responses; @@ -51,23 +46,15 @@ export const loadBootstrap = () => { loadScript('https://a.pub.network/reuters-com/pubfig.min.js'); // Set GAM - (window).googletag = (window).googletag || { cmd: [] }; - (window).googletag.cmd.push(() => { - (window).googletag.pubads().enableSingleRequest(); - (window).googletag.pubads().enableAsyncRendering(); - (window).googletag.pubads().collapseEmptyDivs(true); - - // Global Ads test targeting - const adstest = new URL(document.location.href).searchParams.get('adstest'); - if (adstest) { - (window).googletag.pubads().setTargeting('adstest', adstest); - } - - // Ask Rachel about targeting - const template = (document.querySelector('meta[name="ad:template"]'))?.content; - if (template) { - (window).googletag.pubads().setTargeting('template', template); - } + window.googletag = (window).googletag || { cmd: [] }; + window.googletag.cmd.push(() => { + window.googletag.pubads().enableSingleRequest(); + /** + * @TODO Property 'enableAsyncRendering' does not exist on type 'PubAdsService'. + */ + // @ts-ignore + window.googletag.pubads().enableAsyncRendering(); + window.googletag.pubads().collapseEmptyDivs(true); }); if (!Array.isArray((window).graphicsAdQueue)) { @@ -75,11 +62,24 @@ export const loadBootstrap = () => { } freestar.queue.push(function() { - freestar.newAdSlots((window).graphicsAdQueue || [], 'foobar'); + freestar.newAdSlots((window).graphicsAdQueue || [], freestar.config.channel); }); + // Set page-level key-values + // cf: https://help.freestar.com/help/using-key-values freestar.queue.push(function() { - (window).googletag.pubads().set('page_url', 'https://www.reuters.com/'); // This line should only be used for testing + // Global Ads test targeting + const adstest = new URL(document.location.href).searchParams.get('adstest'); + if (adstest) { + window.googletag.pubads().setTargeting('adstest', adstest); + } + + // Use the URL path to create a unique ID for the page. + const graphicId = window.location.pathname + .replace(/^\/(.*)\/$/, '$1') + .replaceAll('/', '-'); + window.googletag.pubads().setTargeting('template', 'graphics'); + window.googletag.pubads().setTargeting('graphicId', graphicId); }); }); }; diff --git a/src/components/AdSlot/utils.ts b/src/components/AdSlot/utils.ts new file mode 100644 index 00000000..fd73c936 --- /dev/null +++ b/src/components/AdSlot/utils.ts @@ -0,0 +1,6 @@ +const random4 = () => + Math.floor((1 + Math.random()) * 0x10000) + .toString(16) + .substring(1); + +export const getRandomAdId = () => 'ad-' + random4() + random4(); diff --git a/src/index.js b/src/index.js index 61ab62f9..3e7156d4 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,7 @@ export { } from './components/Analytics/Analytics.svelte'; export { default as Article } from './components/Article/Article.svelte'; export { default as AdScripts } from './components/AdSlot/AdScripts.svelte'; -export { default as AdSlot } from './components/AdSlot/AdSlot.svelte'; +export { default as InlineAd } from './components/AdSlot/InlineAd.svelte'; export { default as BeforeAfter } from './components/BeforeAfter/BeforeAfter.svelte'; export { default as Block } from './components/Block/Block.svelte'; export { default as BodyText } from './components/BodyText/BodyText.svelte'; diff --git a/yarn.lock b/yarn.lock index c3b52536..f8ce92dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2993,6 +2993,11 @@ resolved "https://registry.npmjs.org/@types/find-cache-dir/-/find-cache-dir-3.2.1.tgz" integrity sha512-frsJrz2t/CeGifcu/6uRo4b+SzAwT4NYCVPu1GN8IB9XTzrpPkGuV0tmh9mN+/L0PklAlsC3u5Fxt0ju00LXIw== +"@types/google-publisher-tag@^1.20240219.0": + version "1.20240219.0" + resolved "https://registry.yarnpkg.com/@types/google-publisher-tag/-/google-publisher-tag-1.20240219.0.tgz#4b883f033b923bf161f61942adb58c58a7dbea16" + integrity sha512-CvXeyjN9deEo6+nAqgHsGItPhWKnqkeLOqGlZmrb7inO8KUUQTmk2xfVqUnwIi6YKfBrpV4ZODd1TkgnXaIAjw== + "@types/graceful-fs@^4.1.3": version "4.1.6" resolved "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.6.tgz"