Skip to content

Commit

Permalink
Performance timing API as default (#17427)
Browse files Browse the repository at this point in the history
* switch domLoading to responseEnd

* timing API as default

* fix indentation

* rebuilt piwik.js

* Update piwik.js

* rebuilt piwik.js

* fix jslint error

* rebuilt piwik.js

* use isDefined

* rebuilt piwik.js

Co-authored-by: flamisz <[email protected]>
  • Loading branch information
Zoltan Flamis and flamisz authored Apr 14, 2021
1 parent 005528f commit 086874b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 41 deletions.
25 changes: 20 additions & 5 deletions js/piwik.js
Original file line number Diff line number Diff line change
Expand Up @@ -3472,7 +3472,11 @@ if (typeof window.Matomo !== 'object') {
return request;
}

var performanceData = (typeof performanceAlias.getEntriesByType === 'function') && performanceAlias.getEntriesByType('navigation') ? performanceAlias.getEntriesByType('navigation')[0] : performanceAlias.timing;
var performanceData = (typeof performanceAlias.timing === 'object') && performanceAlias.timing ? performanceAlias.timing : undefined;

if (!performanceData) {
performanceData = (typeof performanceAlias.getEntriesByType === 'function') && performanceAlias.getEntriesByType('navigation') ? performanceAlias.getEntriesByType('navigation')[0] : undefined;
}

if (!performanceData) {
return request;
Expand Down Expand Up @@ -3508,13 +3512,24 @@ if (typeof window.Matomo !== 'object') {
timings += '&pf_tfr=' + Math.round(performanceData.responseEnd - performanceData.responseStart);
}

if (performanceData.domInteractive && performanceData.domLoading) {
if (isDefined(performanceData.domLoading)) {
if (performanceData.domInteractive && performanceData.domLoading) {

if (performanceData.domInteractive < performanceData.domLoading) {
return;
if (performanceData.domInteractive < performanceData.domLoading) {
return;
}

timings += '&pf_dm1=' + Math.round(performanceData.domInteractive - performanceData.domLoading);
}
} else {
if (performanceData.domInteractive && performanceData.responseEnd) {

if (performanceData.domInteractive < performanceData.responseEnd) {
return;
}

timings += '&pf_dm1=' + Math.round(performanceData.domInteractive - performanceData.domLoading);
timings += '&pf_dm1=' + Math.round(performanceData.domInteractive - performanceData.responseEnd);
}
}

if (performanceData.domComplete && performanceData.domInteractive) {
Expand Down
Loading

0 comments on commit 086874b

Please sign in to comment.