Skip to content

Commit 8d2d289

Browse files
committed
Fix issue in getEntriesByType
1 parent 9f42521 commit 8d2d289

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

src/default.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,24 @@
476476
var collectDataOnLeave =
477477
collectMetricByString("t") || collectMetricByString("scro");
478478

479-
var payload = {
479+
var basePayload = {
480480
version: version,
481+
hostname: definedHostname,
482+
};
483+
484+
if (bot) basePayload.bot = trueVar;
485+
486+
var payload = assign(basePayload, {
481487
// us = useragent
482488
ua: collectMetricByString("us") ? userAgent : undefinedVar,
489+
483490
https: loc.protocol == https,
484491
timezone: timezone,
485-
hostname: definedHostname,
486492
page_id: collectDataOnLeave ? uuid() : undefinedVar,
493+
487494
// se = sessions
488495
session_id: collectMetricByString("se") ? uuid() : undefinedVar,
489-
};
490-
if (bot) payload.bot = trueVar;
496+
});
491497

492498
/** if sri **/
493499
payload.sri = trueVar;
@@ -581,11 +587,10 @@
581587
var sendOnLeave = function (id, push) {
582588
if (!collectDataOnLeave) return;
583589

584-
var append = {
590+
var append = assign(basePayload, {
585591
type: "append",
586-
hostname: definedHostname,
587592
original_id: push ? id : payload.page_id,
588-
};
593+
});
589594

590595
/** if duration **/
591596
// t = timeonpage
@@ -770,19 +775,20 @@
770775
var navigationText = "navigation";
771776

772777
// Check if back, forward or reload buttons are being used in modern browsers
773-
var userNavigated =
774-
perf &&
775-
perf.getEntriesByType &&
776-
perf.getEntriesByType(navigationText)[0] &&
777-
perf.getEntriesByType(navigationText)[0].type
778-
? ["reload", "back_forward"].indexOf(
779-
perf.getEntriesByType(navigationText)[0].type
780-
) > -1
781-
: // Check if back, forward or reload buttons are being use in older browsers
782-
// 1: TYPE_RELOAD, 2: TYPE_BACK_FORWARD
783-
perf &&
784-
perf[navigationText] &&
785-
[1, 2].indexOf(perf[navigationText].type) > -1;
778+
var performaceEntryType;
779+
try {
780+
performaceEntryType = perf.getEntriesByType(navigationText)[0].type;
781+
} catch (error) {
782+
// Do nothing
783+
}
784+
785+
var userNavigated = performaceEntryType
786+
? ["reload", "back_forward"].indexOf(performaceEntryType) > -1
787+
: // Check if back, forward or reload buttons are being use in older browsers
788+
// 1: TYPE_RELOAD, 2: TYPE_BACK_FORWARD
789+
perf &&
790+
perf[navigationText] &&
791+
[1, 2].indexOf(perf[navigationText].type) > -1;
786792

787793
// Check if referrer is the same as current real hostname (not the defined hostname!)
788794
/** if nonuniquehostnames **/

0 commit comments

Comments
 (0)