Skip to content

Commit 70bb0be

Browse files
committed
chore: some more analytics
1 parent c629b00 commit 70bb0be

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

web/api/share.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export function POST(request: Request) {
1212

1313
if (
1414
!origin ||
15-
(!origin.startsWith(AllowedOrigin) && !origin.startsWith(productionOrigin))
15+
(new URL(origin).hostname != new URL(AllowedOrigin).hostname &&
16+
!origin.startsWith(productionOrigin))
1617
) {
1718
return new Response("Unauthorized", { status: 403 });
1819
}

web/src/Playground.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { atomWithHash } from "jotai-location";
1313
import { compress, decompress } from "@/compress";
1414
import { CopyButton } from "@/components/CopyButton";
1515
import { Button } from "@/components/ui/button";
16+
import posthog from "posthog-js";
1617

1718
const originalOpenAPI = atomWithHash("originalOpenAPI", petstore, {
1819
setHash: throttledPushState,
@@ -58,7 +59,7 @@ function Playground() {
5859
const getShareUrl = useCallback(async () => {
5960
try {
6061
setShareUrlLoading(true);
61-
const info = await GetInfo(original);
62+
const info = await GetInfo(original, false);
6263
const start = JSON.stringify({ result, original, info });
6364
const blob = await compress(start);
6465

@@ -79,6 +80,10 @@ function Playground() {
7980

8081
setShareUrl(currentUrl.toString());
8182
history.pushState(null, "", currentUrl.toString());
83+
posthog.capture("overlay.speakeasy.com:share", {
84+
openapi: JSON.parse(info),
85+
currentUrl: currentUrl.toString(),
86+
});
8287
} else {
8388
setError("Failed to create share URL");
8489
}
@@ -108,7 +113,16 @@ function Playground() {
108113
setOriginal(original);
109114
setResult(result);
110115

111-
const changed = await ApplyOverlay(original, result, true);
116+
const changed = await ApplyOverlay(original, result, false);
117+
const info = await GetInfo(original, false);
118+
const bestURL = new URL(window.location.href);
119+
bestURL.searchParams.set("s", hash);
120+
bestURL.hash = "";
121+
posthog.capture("overlay.speakeasy.com:load-shared", {
122+
openapi: JSON.parse(info),
123+
currentUrl: bestURL.toString(),
124+
});
125+
112126
setChanged(changed);
113127
} catch (error: any) {
114128
console.error("invalid share url:", error.message);

0 commit comments

Comments
 (0)