-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from MindscapeHQ/kk/cwv/add-library
[Core Web Vitals] Add automatic CWV tracking to the provider
- Loading branch information
Showing
12 changed files
with
138 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "raygun4js", | ||
"version": "2.21.1", | ||
"version": "2.22.0", | ||
"homepage": "http://raygun.io", | ||
"authors": [ | ||
"Mindscape <[email protected]>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
|
||
/* | ||
* raygun4js | ||
* https://github.com/MindscapeHQ/raygun4js | ||
* | ||
* Copyright (c) 2021 MindscapeHQ | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
|
||
function raygunCoreWebVitalFactory(window) { | ||
var WebVitalTimingType = "w"; | ||
var queueTimings = null; | ||
|
||
var CoreWebVitals = function(){ | ||
this.cleanWebVitalData = function (event) { | ||
var res = event; | ||
|
||
if(res.value && res.value.toFixed) { | ||
res.value = res.value.toFixed(3); | ||
} | ||
|
||
return res; | ||
}; | ||
}; | ||
|
||
CoreWebVitals.prototype.attach = function(queueHandler) { | ||
queueTimings = queueHandler; | ||
|
||
if(window.webVitals) { | ||
window.webVitals.getLCP(this.handler); | ||
window.webVitals.getFID(this.handler); | ||
window.webVitals.getCLS(this.handler); | ||
} | ||
}; | ||
|
||
CoreWebVitals.prototype.handler = function(event) { | ||
if(event.value && event.value.toFixed) { | ||
event.value = event.value.toFixed(3); | ||
} | ||
|
||
var webVitalEvent = { | ||
url: event.name, | ||
timing: { | ||
t: WebVitalTimingType, | ||
du: event.value | ||
} | ||
}; | ||
|
||
queueTimings(webVitalEvent); | ||
}; | ||
|
||
return new CoreWebVitals(); | ||
} | ||
|
||
window.raygunCoreWebVitalFactory = raygunCoreWebVitalFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/*jshint esversion: 6 */ | ||
|
||
require('./core-web-vitals'); | ||
|
||
describe("core-web-vitals", () => { | ||
let CoreWebVitals = window.raygunCoreWebVitalFactory({ webVitals: null }), queue = []; | ||
CoreWebVitals.attach(e => queue.push(e)); | ||
|
||
beforeEach(() => { | ||
queue = []; | ||
}); | ||
|
||
describe("handler is called", () => { | ||
it("creates the appropriate payload", () => { | ||
CoreWebVitals.handler({ name: "FID", value: "1" }); | ||
|
||
expect(queue.pop()).toEqual({ | ||
url: "FID", | ||
timing: { | ||
t: "w", | ||
du: "1" | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe("event reports long metric value", () => { | ||
|
||
it('value is rounded to 3dp', () => { | ||
CoreWebVitals.handler({ name: "FID", value: 0.14589 }); | ||
|
||
var res = queue.pop(); | ||
expect(res.timing.du).toBe('0.146'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.