Skip to content

Commit

Permalink
fix: missing load RUM event
Browse files Browse the repository at this point in the history
  • Loading branch information
ramboz committed Nov 4, 2022
1 parent f338062 commit 9d5d581
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion scripts/lib-franklin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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"]');
Expand Down
16 changes: 10 additions & 6 deletions scripts/plugins/rum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
Expand Down
3 changes: 2 additions & 1 deletion scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 9d5d581

Please sign in to comment.