mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
34 lines
725 B
TypeScript
34 lines
725 B
TypeScript
import type { BuildInfoResponse } from "api/typesGenerated";
|
|
|
|
// sendDeploymentEvent sends a CORs payload to coder.com
|
|
// to track a deployment event.
|
|
export const sendDeploymentEvent = (
|
|
buildInfo: BuildInfoResponse,
|
|
payload: {
|
|
type: "deployment_setup" | "deployment_login";
|
|
user_id?: string;
|
|
},
|
|
) => {
|
|
if (typeof navigator === "undefined" || !navigator.sendBeacon) {
|
|
// It's fine if we don't report this, it's not required!
|
|
return;
|
|
}
|
|
if (!buildInfo.telemetry) {
|
|
return;
|
|
}
|
|
navigator.sendBeacon(
|
|
"https://coder.com/api/track-deployment",
|
|
new Blob(
|
|
[
|
|
JSON.stringify({
|
|
...payload,
|
|
deployment_id: buildInfo.deployment_id,
|
|
}),
|
|
],
|
|
{
|
|
type: "application/json",
|
|
},
|
|
),
|
|
);
|
|
};
|