From 086ee331c09d5425ca8dbec76f8042994981ce28 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Tue, 8 Oct 2024 16:22:35 -0700 Subject: [PATCH 1/2] feat: add support for speculative rendering --- README.md | 3 ++- src/index.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 33316bb..e1e0762 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ The AEM MarTech plugin is essentially a wrapper around the Adobe Experience Plat It's key differentiator are: - 🌍 Experience Platform enabled: the library fully integrates with our main Adobe Experience Platform and all the services of our ecosystem - 🚀 extremely fast: the library is optimized to reduce load delay, TBT and CLS, and has minimal impact on your Core Web Vitals -- 👤 privacy-first: the library does not track end users by default, and can easily be integrated with your preferred consent management system to open up more advanced use cases +- 🍪 privacy-first: the library does not track end users by default (i.e. we do not use any cookies), and can easily be integrated with your preferred consent management system to open up more advanced use cases +- 👻 prerender support: the library supports [speculative prerendering](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API) out-of-the-box, and won't fire Analytics events (and artificially inflate your page views) until the page is actually viewed ## Prerequisites diff --git a/src/index.js b/src/index.js index 4504df4..927f82e 100644 --- a/src/index.js +++ b/src/index.js @@ -194,13 +194,21 @@ export async function sendAnalyticsEvent(xdmData, dataMapping = {}, configOverri // eslint-disable-next-line no-console console.assert(config.analytics, 'Analytics tracking is disabled in the martech config'); try { - // eslint-disable-next-line no-undef - return window[config.alloyInstanceName]('sendEvent', { + const fn = () => window[config.alloyInstanceName]('sendEvent', { documentUnloading: true, xdm: xdmData, data: dataMapping, edgeConfigOverrides: configOverrides, }); + if (document.prerendering) { + return new Promise((resolve) => { + document.addEventListener('prerenderingchange', async () => { + await fn(); + resolve(); + }, { once: true }); + }); + } + return fn(); } catch (err) { handleRejectedPromise(new Error(err)); return Promise.reject(new Error(err)); From 5ae68c63535dd9f15b6b10e59e5160fc19ad8b65 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Tue, 8 Oct 2024 16:24:47 -0700 Subject: [PATCH 2/2] feat: add support for speculative rendering --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e1e0762..639f43d 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ The AEM MarTech plugin is essentially a wrapper around the Adobe Experience Plat It's key differentiator are: - 🌍 Experience Platform enabled: the library fully integrates with our main Adobe Experience Platform and all the services of our ecosystem - 🚀 extremely fast: the library is optimized to reduce load delay, TBT and CLS, and has minimal impact on your Core Web Vitals -- 🍪 privacy-first: the library does not track end users by default (i.e. we do not use any cookies), and can easily be integrated with your preferred consent management system to open up more advanced use cases -- 👻 prerender support: the library supports [speculative prerendering](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API) out-of-the-box, and won't fire Analytics events (and artificially inflate your page views) until the page is actually viewed +- 👤 privacy-first: the library does not track end users by default, and can easily be integrated with your preferred consent management system to open up more advanced use cases +- 🔬 prerender support: the library supports [speculative prerendering](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API) out-of-the-box, and won't fire Analytics events (and artificially inflate your page views) until the page is actually viewed ## Prerequisites