Merge pull request #3426 from betagouv/fix-matomo

matomo: fix JS error when timing data are not available
This commit is contained in:
LeSim 2019-02-13 16:15:05 +01:00 committed by GitHub
commit 8239c159b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,11 +22,12 @@
var previousPageUrl = null; var previousPageUrl = null;
addEventListener('turbolinks:load', function(event) { addEventListener('turbolinks:load', function(event) {
if (previousPageUrl) { if (previousPageUrl) {
var loadTimeMs = event.data.timing.visitEnd - event.data.timing.visitStart;
_paq.push(['setReferrerUrl', previousPageUrl]); _paq.push(['setReferrerUrl', previousPageUrl]);
_paq.push(['setCustomUrl', '/' + window.location.href]); _paq.push(['setCustomUrl', '/' + window.location.href]);
_paq.push(['setDocumentTitle', document.title]); _paq.push(['setDocumentTitle', document.title]);
_paq.push(['setGenerationTimeMs', loadTimeMs]); if (event.data && event.data.timing) {
_paq.push(['setGenerationTimeMs', event.data.timing.visitEnd - event.data.timing.visitStart]);
}
_paq.push(['trackPageView']); _paq.push(['trackPageView']);
} }
previousPageUrl = window.location.href; previousPageUrl = window.location.href;