### Initialize Perfume.js Library Source: https://context7.com/zizzamia/perfume.js/llms.txt Initializes the library with configuration options including resource timing and an analytics tracker callback. This setup is required to start observing Web Vitals and device information. ```javascript import { initPerfume } from 'perfume.js'; initPerfume({ resourceTiming: true, elementTiming: true, maxMeasureTime: 30000, analyticsTracker: (options) => { const { metricName, data, navigatorInformation } = options; if (['TTFB', 'FCP', 'LCP', 'FID', 'CLS', 'INP', 'TBT'].includes(metricName)) { console.log(`${metricName}: ${data}`); } } }); ``` -------------------------------- ### Install and Import Perfume.js Source: https://github.com/zizzamia/perfume.js/blob/master/docs/src/index.html Instructions for installing the library via npm and importing it into a project using standard ES modules or UMD bundles. ```bash npm install perfume.js --save ``` ```javascript import Perfume from 'perfume.js'; import Perfume from 'node_modules/perfume.js/perfume.umd.js'; ``` -------------------------------- ### Initialize Perfume.js with Custom Analytics Tracker Source: https://github.com/zizzamia/perfume.js/blob/master/CHANGELOG.md Demonstrates how to initialize Perfume.js using a functional approach, providing a custom analytics tracker function to send performance metrics to an external tool. This setup is suitable for tracking Critical User Journeys. ```javascript import { initPerfume } from 'perfume.js'; initPerfume({ analyticsTracker: ({ metricName, data }) => { myAnalyticsTool.track(metricName, data); }) }); ``` -------------------------------- ### Example Metric Output Formats Source: https://github.com/zizzamia/perfume.js/blob/master/README.md These snippets show the structure of the data reported by Perfume.js for navigation timing and first paint metrics. ```javascript // Perfume.js: navigationTiming { ... timeToFirstByte: 192.65 } // Perfume.js: fp 1482.00 ms ``` -------------------------------- ### Track User Journey Steps with Perfume.js Marks Source: https://github.com/zizzamia/perfume.js/blob/master/README.md This TypeScript example illustrates how to track user journey steps by marking the start and end of specific user actions or system processes. It uses `markStep` to define these boundaries, helping to measure system time during navigation or data loading, distinct from cognitive time. ```typescript // Marking the start of the step const ScreenA = () => { const handleNavigation = () => { ... // Navigation logic // Mark when navigating to screen B markStep('navigate_to_screen_B'); } ... return ( <>