Skip to content

Instantly share code, notes, and snippets.

@hcodes
Last active May 30, 2019 12:48
Show Gist options
  • Save hcodes/014e345424e5b469c263 to your computer and use it in GitHub Desktop.
Save hcodes/014e345424e5b469c263 to your computer and use it in GitHub Desktop.
Отслеживание js-ошибок с помощью Метрики
window.onerror = function(msg, file, line, col, err) {
if (!window.JSON) {
return;
}
var counterId = 12345,
siteInfo = {},
pointer = siteInfo;
path = [
'JS errors',
msg,
err && err.stack || (file + ':' + line + ':' + col)
];
for (var i = 0; i < path.length - 1; i++) {
var item = path[i];
pointer[item] = {};
pointer = pointer[item];
}
pointer[path[i]] = 1;
new Image().src = 'https://mc.yandex.ru/watch/' + counterId +
'/?site-info=' + encodeURIComponent(JSON.stringify(siteInfo))
'&rnd=' + Math.random();
};
@abaranovskii
Copy link

@hcodes, what this line of code is used for ?

pointer[path[i]] = 1;

@hcodes
Copy link
Author

hcodes commented May 30, 2019

{
   'JS errors': {
         'mgs': {
              'error stack': 1 // Для подсчёта ошибок, вес ошибки, см. отчёты в Метрике.
         }
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment