@pernod-ricard-global-cms/jsutils 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/jsutils.mjs +15 -0
  2. package/package.json +1 -1
package/jsutils.mjs CHANGED
@@ -9,6 +9,21 @@ export function isWpAdmin() {
9
9
  return document.body.classList.contains("wp-admin") ? true : false;
10
10
  }
11
11
 
12
+ export function ttfb() {
13
+ new PerformanceObserver((entryList) => {
14
+ const [pageNav] = entryList.getEntriesByType('navigation');
15
+ const time = pageNav.responseStart;
16
+ console.log(`TTFB: ${time} new`);
17
+ pushData(time);
18
+ }).observe({type: 'navigation', buffered: true});
19
+ }
20
+
21
+ function pushData(time) {
22
+ window.dataLayer = window.dataLayer || [];
23
+ window.dataLayer.push({ttfb: time});
24
+ console.log('ttfb sent');
25
+ }
26
+
12
27
  /**
13
28
  * This function accepts an html element and returns the position of that element on the page.
14
29
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pernod-ricard-global-cms/jsutils",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Handy collection of Javascript utility functions",
5
5
  "type": "commonjs",
6
6
  "main": "jsutils.mjs",