Skip to content

Commit

Permalink
Chore: use handViewerMetrics() to log successful/failed preview (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinHoldstock authored Mar 7, 2018
1 parent cc09a61 commit 621ab20
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/lib/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,11 @@ class Preview extends EventEmitter {
file: this.file
});

// Explicit preview failure
this.handleViewerMetrics({
event_name: 'failure'
});

// Hookup for phantom JS health check
if (typeof window.callPhantom === 'function') {
window.callPhantom(0);
Expand All @@ -1209,6 +1214,11 @@ class Preview extends EventEmitter {
file: this.file
});

// Explicit preview success
this.handleViewerMetrics({
event_name: 'success'
});

// If there wasn't an error and event logging is not disabled, use Events API to log a preview
if (!this.options.disableEventLog) {
this.logPreviewEvent(this.file.id, this.options);
Expand Down
21 changes: 21 additions & 0 deletions src/lib/__tests__/Preview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,27 @@ describe('lib/Preview', () => {
expect(preview.count.success).to.equal(1);
});

it('should emit a metrics message for successful preview', () => {
const event_name = 'success';

const handleViewerMetrics = sandbox.stub(preview, 'handleViewerMetrics');

preview.finishLoading();

expect(handleViewerMetrics).to.be.calledWith({ event_name });
});

it('should emit a metrics message for failed preview', () => {
const event_name = 'failure';
const value = false;

const handleViewerMetrics = sandbox.stub(preview, 'handleViewerMetrics');

preview.finishLoading({ error: {} });

expect(handleViewerMetrics).to.be.calledWith({ event_name });
});

it('should emit the load event', () => {
preview.finishLoading();
expect(stubs.emit).to.be.called;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const PREVIEW_ERROR = 'preview_error';
export const PREVIEW_METRIC = 'preview_metric';
// Milestone events for loading performance
export const LOAD_METRIC = {
previewLoadEvent: 'preview_load', // Event name for preview_metric events related to loading times.
previewLoadEvent: 'load', // Event name for preview_metric events related to loading times.
fileInfoTime: 'file_info_time', // Round trip time from file info request to received file info.
convertTime: 'convert_time', // Time it took from receiving file info to being able to request the rep.
downloadResponseTime: 'download_response_time', // Time it took for TTFB when requesting a rep.
Expand Down

0 comments on commit 621ab20

Please sign in to comment.