From 9d5d581ac60759db54f837d1605627c5a963a0e9 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Wed, 26 Oct 2022 11:26:40 +0200 Subject: [PATCH] fix: missing load RUM event --- scripts/lib-franklin.js | 5 ++++- scripts/plugins/rum.js | 16 ++++++++++------ scripts/scripts.js | 3 ++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/lib-franklin.js b/scripts/lib-franklin.js index be932cf95a..9dca8eccfc 100644 --- a/scripts/lib-franklin.js +++ b/scripts/lib-franklin.js @@ -66,6 +66,9 @@ export async function withPlugin(path, options = {}) { const pluginName = toCamelCase(path.split('/').pop().replace('.js', '')); const plugin = await import(path); plugins[pluginName] = { ...plugin, options }; + if (plugin.init) { + plugin.init(options); + } if (plugin.api) { pluginsApis[pluginName] = plugin.api; } @@ -379,8 +382,8 @@ export async function loadPage(options = {}) { /** * init block utils */ +window.hlx = window.hlx || {}; export async function init(options) { - window.hlx = window.hlx || {}; window.hlx.codeBasePath = ''; const scriptEl = document.querySelector('script[src$="/scripts/scripts.js"]'); diff --git a/scripts/plugins/rum.js b/scripts/plugins/rum.js index 47333d0cc1..313a079a76 100644 --- a/scripts/plugins/rum.js +++ b/scripts/plugins/rum.js @@ -69,15 +69,19 @@ export const api = { sampleRUM, }; +sampleRUM('top'); + /** - * Logic to execute in the pre eager phase + * Logic to execute when the plugin is loaded. */ -export async function preEager(options) { - window.hlx.RUM_GENERATION = options.generation; // add your RUM generation information here - sampleRUM('top'); - - window.addEventListener('load', () => sampleRUM('load')); +export async function init() { + sampleRUM('load'); +} +/** + * Logic to execute in the pre eager phase + */ +export async function preEager() { window.addEventListener('unhandledrejection', (event) => { sampleRUM('error', { source: event.reason.sourceURL, target: event.reason.line }); }); diff --git a/scripts/scripts.js b/scripts/scripts.js index 66582208f4..f89d9880b6 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -8,12 +8,13 @@ import { const LCP_BLOCKS = []; // add your LCP blocks to the list +window.hlx.RUM_GENERATION = 'project-1'; +await withPlugin('./plugins/rum.js'); const { decorateBlock, decorateButtons, decorateIcons, } = await withPlugin('./plugins/decorator.js'); -await withPlugin('./plugins/rum.js', { generation: 'project-1' }); function buildHeroBlock(main) { const h1 = main.querySelector('h1');