Skip to content

Commit

Permalink
Merge pull request #111 from adobe/no-blog-ff-main
Browse files Browse the repository at this point in the history
feat(observer): enable tracking of JSON loading for all browsers that have a PerformanceObserver implementation (2.x)
  • Loading branch information
trieloff authored Jan 22, 2024
2 parents 1f0b25b + 0be8de7 commit c0086dc
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
/* eslint-env browser */
const KNOWN_PROPERTIES = ['weight', 'id', 'referer', 'checkpoint', 't', 'source', 'target', 'cwv', 'CLS', 'FID', 'LCP', 'INP', 'TTFB'];
const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia'];
const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource'];
const SESSION_STORAGE_KEY = 'aem-rum';
const { sampleRUM, queue, isSelected } = window.hlx.rum;

Expand Down Expand Up @@ -67,10 +67,6 @@ function optedIn(checkpoint, data) {
}
// Gets configured collection from the config service for the current domain
function getCollectionConfig() {
if (window.location.hostname === 'blog.adobe.com') {
return ['loadresource', ...DEFAULT_TRACKING_EVENTS];
}
// TODO: configured collection should come from config service
return DEFAULT_TRACKING_EVENTS;
}

Expand Down Expand Up @@ -157,18 +153,16 @@ function addEnterLeaveTracking() {
}

function addLoadResourceTracking() {
if (window.location.hostname === 'blog.adobe.com') {
const observer = new PerformanceObserver((list) => {
list.getEntries()
.filter((entry) => !entry.responseStatus || entry.responseStatus < 400)
.filter((entry) => window.location.hostname === new URL(entry.name).hostname)
.filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html|\\.json)$'))
.forEach((entry) => {
sampleRUM('loadresource', { source: entry.name, target: Math.round(entry.duration) });
});
});
observer.observe({ type: 'resource', buffered: true });
}
const observer = new PerformanceObserver((list) => {
list.getEntries()
.filter((entry) => !entry.responseStatus || entry.responseStatus < 400)
.filter((entry) => window.location.hostname === new URL(entry.name).hostname)
.filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html|\\.json)$'))
.forEach((entry) => {
sampleRUM('loadresource', { source: entry.name, target: Math.round(entry.duration) });
});
});
observer.observe({ type: 'resource', buffered: true });
}

function activateBlocksMutationObserver() {
Expand Down

0 comments on commit c0086dc

Please sign in to comment.