Skip to content

Commit

Permalink
Post event when popup is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
jdgarcia committed May 3, 2024
1 parent b7f47d2 commit 0a645b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/gkApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,22 @@ export const fetchDraftCounts = async (prUniqueIds: string[]) => {
const payload = await res.json();
return payload.data as { counts: PullRequestDraftCounts };
};

export const postEvent = async (event: string, data?: Record<string, unknown>) => {
const token = await getAccessToken();
if (!token) {
return;
}

await fetch(`${gkApiUrl}/events`, {
headers: {
Authorization: `Bearer ${token}`,
},
method: 'POST',
body: JSON.stringify({
source: 'browser_extension',
event: event,
data: data,
}),
});
};
3 changes: 3 additions & 0 deletions src/popup/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import React from 'react';
import { createRoot } from 'react-dom/client';
import { postEvent } from '../gkApi';
import { Popup } from './components/Popup';

function main() {
const mainEl = document.getElementById('popup-container')!;
const root = createRoot(mainEl);
root.render(<Popup />);

void postEvent('browserExtensionPopupOpened');
}

main();

0 comments on commit 0a645b6

Please sign in to comment.