Skip to content

Commit 3cbde6b

Browse files
committed
Add post re: New Relic PageViewTiming
1 parent 7fcff9f commit 3cbde6b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
layout: blog-single
3+
title: "FACET-ing New Relic PageViewTiming Data By 'Page Type'"
4+
date: November 7, 2024
5+
image:
6+
tags: [Monitoring, Tools, Performance, New Relic]
7+
related_posts:
8+
---
9+
10+
New Relic's [`PageViewTiming`](https://docs.newrelic.com/docs/browser/new-relic-browser/page-load-timing-resources/pageviewtiming-async-or-dynamic-page-details/) data set provides excellent visibility into important performance metrics such as Core Web Vitals. When analyzing this data it can be useful to segment it by "page type" — for example, on an ecommerce website it can be helpful to know LCP or CLS scores for the product detail page, or product listing page individually. While it's possible to view performance metrics for specific page URLs via the default `pageUrl` field, a website can have thousands (or more) of unique URLs for a given page type. Unless a predictable and consistent pattern is used for all URLs of a specific page type, by default it is not possible to segment data this way.
11+
12+
<!-- excerpt_separator -->
13+
14+
### New Relic "Custom Attributes"
15+
16+
This issue can be solved by using New Relic [custom attributes](https://docs.newrelic.com/docs/data-apis/custom-data/custom-events/collect-custom-attributes/), which will be available when querying the `PageViewTiming` data set. The browser agent provides a [`setCustomAttribute`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/) function, which can be used for this purpose.
17+
18+
For example, in the case of Magento / Adobe Commerce, the "page type" can be identified consulting the list of `classList` of the `<body>` element. The below snippet can be used to quickly and easily set the `pageType` attribute for the product and category pages.
19+
20+
```html
21+
<script>
22+
(function() {
23+
if (!window.newrelic) {
24+
return;
25+
}
26+
27+
if (document.body.classList.contains('catalog-category-view')) {
28+
newrelic.setCustomAttribute('pageType', 'catalog/category/view');
29+
return;
30+
}
31+
32+
if (document.body.classList.contains('catalog-product-view')) {
33+
newrelic.setCustomAttribute('pageType', 'catalog/product/view');
34+
return;
35+
}
36+
})();
37+
</script>
38+
```
39+
40+
Once in place, `pageType` can be used for `FACET`-ing and `WHERE` clauses in your NRQL queries.
41+
42+

0 commit comments

Comments
 (0)