(function () { try { window.ebay = window.ebay || {}; if (window.ebay._csMonitoring?.ready) return; const sendMetric = ( csmEndpoint, metricName = "", logLevel = "info", message = "", ) => { navigator.sendBeacon( csmEndpoint, JSON.stringify({ metricName, logLevel, message, value: 1, pageName: "homepage", originalGuid: "bf9efe981970a6ba89749b2cffff7495", }), ); }; // Handle any uncaught error on the client side. If code rollout triggers any unexpected error, // it should trigger a spike on the backend and cause the canary to rollback, which should be debuggable // given the message we send here. window.addEventListener("error", (e) => { sendMetric( "/vlp/vlp-csm", "unexpected_client_side_error", "info", `${e.message} at ${e.source}:${e.lineno}:${e.colno}`, ); }); // Flush queue if (window.ebay._csMonitoring?.length) { window.ebay._csMonitoring.forEach((item) => sendMetric(...item)); } // Replace the simple array queue with an array-like object that actually dispatches the metrics window.ebay._csMonitoring = { push: (...metrics) => metrics.map((m) => sendMetric(...m)), ready: true, }; } catch (error) { console.error("Error in client side monitoring", error); } })();