Tracking Heavy Client-Side WebAssembly Computations & CAD File Parsing Events with Matomo MTM

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.

Adding a quick update on custom dimension mapping for WebGL2 / WebAssembly CAD viewers: when benchmarking GPU frame times alongside multi-CAD file parsing (STEP, RVT, SLDPRT, and DWG assemblies), binding the WebGL WEBGL_debug_renderer_info unmasked renderer string to a Matomo Action Dimension makes it easy to correlate parse latency with client GPU tiers. We documented the hardware acceleration metrics and multi-CAD viewer telemetry setup in https://gstarcademy.com/kb/guides/cad-hardware-acceleration-and-gpu-tuning and https://gstarcademy.com/kb/guides/course-17-dwg-fastview-3d-multi-cad-step-rvt-sldprt-review.