Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuity: fix TTFI when EventTiming plugin is missing #340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions plugins/continuity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3348,7 +3348,7 @@
* Analyzes Interactions
*/
function analyze(startTime) {
var fid;
var fid, ttfi, ET;

impl.addToBeacon("c.i.dc", externalMetrics.interactionDelayed());
impl.addToBeacon("c.i.dt", externalMetrics.interactionDelayedTime());
Expand All @@ -3357,9 +3357,10 @@
// Only send FID and TTFI Timers once
if (!sentTimers) {
// defer to EventTiming's FID if available
if (BOOMR.plugins.EventTiming &&
BOOMR.plugins.EventTiming.is_enabled()) {
fid = BOOMR.plugins.EventTiming.metrics.firstInputDelay();
ET = BOOMR.plugins.EventTiming;
if (ET && ET.is_enabled()) {
fid = ET.metrics.firstInputDelay();
ttfi = ET.metrics.timeToFirstInteraction();
}

if (!fid && firstInputDelay !== null) {
Expand All @@ -3369,7 +3370,7 @@
if (fid) {
impl.addToBeacon("c.fid", Math.ceil(fid), true);

impl.addToBeacon("c.ttfi", BOOMR.plugins.EventTiming.metrics.timeToFirstInteraction() ||
impl.addToBeacon("c.ttfi", ttfi ||
externalMetrics.timeToFirstInteraction());

sentTimers = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%= header %>
<!--
Same as 13-interaction but without the EventTiming plugin
-->
<%= boomerangScript %>
<p>45-interaction-no-eventtiming loading...</p>
<script src="45-interaction-no-eventtiming.js" type="text/javascript"></script>
<script>
// test that `c.ttfi` can be set without the EventTiming plugin
delete BOOMR.plugins.EventTiming;

BOOMR_test.init({
testAfterOnBeacon: true,
Continuity: {
enabled: true
}
});

try {
// the event timestamp is set when the object is created
var ev = document.createEvent("Event");
ev.initEvent("keydown", true, true);
ev.keyCode = 27;
}
catch (e) {
window.cannotCreateMouseEvent = true;
}

// click
window.ttfi = BOOMR.now();

// dispatch event is synchronous. Wait 20ms between the event creation and dispatch
BOOMR_test.busy(20);
document.dispatchEvent(ev);

setTimeout(function() {
// click key again
document.dispatchEvent(ev);
document.dispatchEvent(ev);
}, 250);
</script>
<img src="/delay?delay=3000&amp;file=assets/img.jpg" width="200" height="10000" />
<%= footer %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*eslint-env mocha*/
/*global BOOMR_test,assert*/

const {assert} = require("chai");

describe("e2e/21-continuity/45-interaction-no-eventtiming", function() {
var tf = BOOMR.plugins.TestFramework;
var t = BOOMR_test;

it("Should have sent a single beacon validation", function(done) {
t.validateBeaconWasSent(done);
});

it("Should not have the EventTiming plugin", function(done) {
assert.isUndefined(BOOMR.plugins.EventTiming);
});

it("Should have sent the Time to First Interaction (c.ttfi)", function() {
var b = tf.lastBeacon();

assert.isDefined(b["c.ttfi"]);
var ttfi = parseInt(b["c.ttfi"], 10);

if (t.isNavigationTimingSupported()) {
var st = parseInt(b["rt.tstart"], 10);
assert.closeTo(st + ttfi, window.ttfi, 20);
}
else {
assert.operator(ttfi, ">=", 0);
}
});

it("Should have the interaction timeline (c.t.inter)", function() {
var b = tf.lastBeacon();

assert.isDefined(b["c.t.inter"]);
assert.operator(b["c.t.inter"].length, ">=", 1);
});

it("Could have the interaction delay timeline (c.t.interdly)", function() {
var b = tf.lastBeacon();

if (b["c.i.a"]) {
assert.isDefined(b["c.t.interdly"]);
assert.operator(b["c.t.interdly"].length, ">=", 1);
}
});

it("Could have interaction delay metrics (c.i.a, c.i.dc and c.i.dt)", function() {
var b = tf.lastBeacon();

if (!b["c.i.a"]) {
assert.operator(parseInt(b["c.i.a"], 10), ">=", 1);
assert.operator(parseInt(b["c.i.dc"], 10), ">=", 1);
assert.operator(parseInt(b["c.i.dc"], 10), "<=", 10);
assert.operator(parseInt(b["c.i.dt"], 10), ">=", 1);
}
});

it("Should have First Input Delay (c.fid)", function() {
var b = tf.lastBeacon();

assert.isDefined(b["c.fid"]);
assert.operator(parseInt(b["c.fid"], 10), ">=", 19); // we had a 20ms busy wait, allow for some fuzzing
});
});