For web applications that execute heavy client-side geometry parsing (such as parsing STEP B-Rep topology or DWG binary streams using WebAssembly/Web Workers), traditional pageview tracking leaves a blind spot regarding computation latency and browser resource bottlenecks.
Here is a clean pattern for capturing client-side execution timings and memory pressure events in Matomo without blocking the UI thread:
1. High-Resolution Timing via Performance API:
Instead of relying on `Date.now()`, instrument the Web Worker parser using `performance.mark()` and `performance.measure()`:
```javascript
performance.mark(‘cad_parse_start’);
// Execute WebAssembly / ArrayBuffer decompression
const result = parseBinaryMesh(arrayBuffer);
performance.mark(‘cad_parse_end’);
performance.measure(‘cad_parse_duration’, ‘cad_parse_start’, ‘cad_parse_end’);
const durationMs = Math.round(performance.getEntriesByName(‘cad_parse_duration’)[0].duration);
```
2. Discrete Latency Bucketing for Matomo Custom Events:
To avoid high-cardinality values skewing reports, bucket parsing durations before dispatching to Matomo Tag Manager:
```javascript
function getLatencyBucket(ms) {
if (ms < 500) return ‘<500ms’;
if (ms < 2000) return ‘500ms-2s’;
if (ms < 5000) return ‘2s-5s’;
return ‘>5s (Heavy)’;
}
// Push structured event to Matomo dataLayer
window._paq = window._paq || [];
window._paq.push([
‘trackEvent’,
‘GeometryParser’,
‘ParseDuration’,
getLatencyBucket(durationMs),
durationMs
]);
```
3. Handling WebAssembly Memory Warnings:
If the geometry parser allocates large contiguous memory pools near browser heap limits, catch the threshold early:
```javascript
if (performance.memory && performance.memory.usedJSHeapSize > 500 * 1024 * 1024) {
window._paq.push([‘trackEvent’, ‘Diagnostics’, ‘HighMemoryFootprint’, ‘Over500MB’]);
}
```
This gives full visibility into device performance across different client hardware without introducing tracking overhead.