Skip to content

Commit

Permalink
feat: add the elapsed time to events for debugging (#5868)
Browse files Browse the repository at this point in the history
* feat: add the elapsed time to events for debugging

* naming
  • Loading branch information
gpolaert authored Nov 2, 2020
1 parent 39df31f commit d19f4ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ module.exports = (function () {
eventsFired.push({
eventType: eventString,
args: eventPayload,
id: key
id: key,
elapsedTime: utils.getPerformanceNow(),
});

/** Push each specific callback to the `callbacks` array.
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,14 @@ export function timestamp() {
return new Date().getTime();
}

/**
* The returned value represents the time elapsed since the time origin. @see https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
* @returns {number}
*/
export function getPerformanceNow() {
return (window.performance && window.performance.now && window.performance.now()) || 0;
}

/**
* When the deviceAccess flag config option is false, no cookies should be read or set
* @returns {boolean}
Expand Down

0 comments on commit d19f4ca

Please sign in to comment.