const progressBar = document.querySelector("#progress-bar"); const unityStartLoadingTime = performance.now(); createUnityInstance(document.querySelector("#unity-canvas"), settings, (progress) => { progressBar.style.right = 100 * (1 - progress) + "%"; } ).then( (unityInstance) => { progressBar.style.display = "none"; const unityEndLoadingTime = performance.now(); unityInstance.Module.errorHandler = (errorMessage) => { ym(window.yandexMetricaCounterId, 'reachGoal', 'unityGameCrash', { gameCrashError: errorMessage }); } ; ym(window.yandexMetricaCounterId, 'reachGoal', 'unityStart', { unityLoadTime: (unityEndLoadingTime - unityStartLoadingTime) / 1000 }); } ).catch( (errorMessage) => { ym(window.yandexMetricaCounterId, 'reachGoal', 'unityLoadingCrash', { loadingCrashError: errorMessage }); alert(errorMessage); } );