-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
102 additions
and
12 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,5 +1,48 @@ | ||
/** | ||
* @file Contains global type definitions. | ||
*/ | ||
|
||
/** | ||
* Disable emoji-mart typing warnings. | ||
*/ | ||
// TODO: Remove when https://github.com/missive/emoji-mart/issues/576 is merged. | ||
declare module "@emoji-mart/react"; | ||
|
||
/** | ||
* Extend Navigator with extra types. | ||
* | ||
* @description Define NetworkInformation attribute types. Needed since they are not yet supported (see | ||
* https://stackoverflow.com/a/69676260/8135687). Taken from | ||
* https://github.com/lacolaco/network-information-types/blob/master/index.d.ts | ||
*/ | ||
declare interface Navigator extends NavigatorNetworkInformation {} | ||
|
||
// http://wicg.github.io/netinfo/#navigatornetworkinformation-interface | ||
declare interface NavigatorNetworkInformation { | ||
readonly connection?: NetworkInformation; | ||
} | ||
|
||
// http://wicg.github.io/netinfo/#effectiveconnectiontype-enum | ||
type EffectiveConnectionType = "2g" | "3g" | "4g" | "slow-2g"; | ||
|
||
// http://wicg.github.io/netinfo/#dom-megabit | ||
type Megabit = number; | ||
// http://wicg.github.io/netinfo/#dom-millisecond | ||
type Millisecond = number; | ||
|
||
// http://wicg.github.io/netinfo/#networkinformation-interface | ||
interface NetworkInformation extends EventTarget { | ||
// readonly type?: ConnectionType; // NOTE: Already included in upstream https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts#L10430. | ||
// http://wicg.github.io/netinfo/#effectivetype-attribute | ||
readonly effectiveType?: EffectiveConnectionType; | ||
// http://wicg.github.io/netinfo/#downlinkmax-attribute | ||
readonly downlinkMax?: Megabit; | ||
// http://wicg.github.io/netinfo/#downlink-attribute | ||
readonly downlink?: Megabit; | ||
// http://wicg.github.io/netinfo/#rtt-attribute | ||
readonly rtt?: Millisecond; | ||
// http://wicg.github.io/netinfo/#savedata-attribute | ||
readonly saveData?: boolean; | ||
// http://wicg.github.io/netinfo/#handling-changes-to-the-underlying-connection | ||
onchange?: EventListener; | ||
} |
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,55 @@ | ||
import { Metric } from "web-vitals"; | ||
|
||
const vitalsUrl = "https://vitals.vercel-analytics.com/v1/vitals"; | ||
|
||
/** | ||
* Retrieves user connection speed. | ||
* | ||
* @returns A Vitals object. | ||
*/ | ||
function getConnectionSpeed() { | ||
return "connection" in navigator && | ||
navigator.connection && | ||
"effectiveType" in navigator.connection | ||
? navigator.connection.effectiveType !== undefined | ||
? navigator.connection.effectiveType | ||
: "" | ||
: ""; | ||
} | ||
/** | ||
* Send metrics to Vercel analytics. | ||
* | ||
* @param metric | ||
* @returns | ||
*/ | ||
export function sendToVercelAnalytics(metric: Metric) { | ||
const analyticsId = process.env.REACT_APP_VERCEL_ANALYTICS_ID; | ||
if (!analyticsId) { | ||
getConnectionSpeed(); | ||
return; | ||
} | ||
|
||
const body = { | ||
dsn: analyticsId, | ||
id: metric.id, | ||
page: window.location.pathname, | ||
href: window.location.href, | ||
event_name: metric.name, | ||
value: metric.value.toString(), | ||
speed: getConnectionSpeed(), | ||
}; | ||
|
||
const blob = new Blob([new URLSearchParams(body).toString()], { | ||
// This content type is necessary for `sendBeacon` | ||
type: "application/x-www-form-urlencoded", | ||
}); | ||
if (navigator.sendBeacon) { | ||
navigator.sendBeacon(vitalsUrl, blob); | ||
} else | ||
fetch(vitalsUrl, { | ||
body: blob, | ||
method: "POST", | ||
credentials: "omit", | ||
keepalive: true, | ||
}); | ||
} |
fc74f62
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
github-emoji-picker – ./
github-emoji-picker.vercel.app
github-emoji-picker-git-main-rickstaa.vercel.app
github-emoji-picker-rickstaa.vercel.app