Skip to content

Commit

Permalink
Post event when popup is opened (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdgarcia authored May 3, 2024
1 parent baa0734 commit ff2ec61
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 @@ -175,3 +175,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 @@ -3,6 +3,7 @@
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client';
import React from 'react';
import { createRoot } from 'react-dom/client';
import { postEvent } from '../gkApi';
import { Popup } from './components/Popup';
import { asyncStoragePersister, queryClient } from './queryClient';

Expand All @@ -14,6 +15,8 @@ function main() {
<Popup />
</PersistQueryClientProvider>,
);

void postEvent('browserExtensionPopupOpened');
}

main();

0 comments on commit ff2ec61

Please sign in to comment.