-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from supertokens/feat/analytics
chore: Add analytics API call after user list loads
- Loading branch information
Showing
17 changed files
with
139 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ tags: | |
description: APIs for user management features | ||
- name: "User Details" | ||
description: APIs for fetching and modifying information specific to one user | ||
- name: "Telemetry" | ||
description: APIs related to recording telemetry from the dashboard | ||
|
||
paths: | ||
/signin: | ||
|
@@ -1086,6 +1088,64 @@ paths: | |
type: string | ||
enum: | ||
- Not Found | ||
/api/analytics: | ||
post: | ||
tags: | ||
- Telemetry | ||
summary: Signals the backend SDK to send telemetry to SuperTokens | ||
operationId: telemetryAnalyticsPost | ||
parameters: | ||
- name: authorization | ||
in: header | ||
required: true | ||
schema: | ||
type: string | ||
example: "Bearer API_KEY" | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
email: | ||
type: string | ||
example: [email protected] | ||
dashboardVersion: | ||
type: string | ||
example: 0.1.2 | ||
responses: | ||
200: | ||
description: Success | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
status: | ||
type: string | ||
default: "OK" | ||
400: | ||
description: error code 400 | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
401: | ||
description: Unauthorised access | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
enum: | ||
- Unauthorised access | ||
404: | ||
description: error code 404 | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
enum: | ||
- Not Found | ||
servers: | ||
# Added by API Auto Mocking Plugin | ||
- description: SwaggerHub API Auto Mocking | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
|
@@ -20,7 +20,11 @@ import useVerifyEmailService from "../../../api/user/email/verify"; | |
import useVerifyUserTokenService from "../../../api/user/email/verify/token"; | ||
import useFetchUsersService from "../../../api/users"; | ||
import useFetchCount from "../../../api/users/count"; | ||
import { StorageKeys } from "../../../constants"; | ||
import { localStorageHandler } from "../../../services/storage"; | ||
import { AppEnvContextProvider, useAppEnvContext } from "../../../ui/contexts/AppEnvContext"; | ||
import { getApiUrl, getAuthMode, useFetchData } from "../../../utils"; | ||
import { package_version } from "../../../version"; | ||
import { Footer, LOGO_ICON_LIGHT } from "../../components/footer/footer"; | ||
import InfoConnection from "../../components/info-connection/info-connection"; | ||
import NoUsers from "../../components/noUsers/NoUsers"; | ||
|
@@ -53,6 +57,8 @@ type UserListProps = { | |
|
||
type NextPaginationTokenByOffset = Record<number, string | undefined>; | ||
|
||
let isAnalyticsFired = false; | ||
|
||
export const UsersList: React.FC<UserListProps> = ({ | ||
onSelect, | ||
css, | ||
|
@@ -70,6 +76,7 @@ export const UsersList: React.FC<UserListProps> = ({ | |
const { fetchUsers } = useFetchUsersService(); | ||
|
||
const { fetchCount } = useFetchCount(); | ||
const fetchData = useFetchData(); | ||
|
||
const insertUsersAtOffset = useCallback( | ||
(paramUsers: UserWithRecipeId[], paramOffset?: number) => { | ||
|
@@ -120,12 +127,44 @@ export const UsersList: React.FC<UserListProps> = ({ | |
[offset, errorOffsets, limit, paginationTokenByOffset, insertUsersAtOffset, getOffsetByPaginationToken] | ||
); | ||
|
||
const fireAnalyticsEvent = async () => { | ||
if (isAnalyticsFired) { | ||
return; | ||
} | ||
|
||
isAnalyticsFired = true; | ||
|
||
try { | ||
let email: string | undefined = "[email protected]"; | ||
|
||
if (getAuthMode() === "email-password") { | ||
email = localStorageHandler.getItem(StorageKeys.EMAIL); | ||
} | ||
|
||
await fetchData({ | ||
url: getApiUrl("/api/analytics"), | ||
method: "POST", | ||
config: { | ||
body: JSON.stringify({ | ||
email, | ||
dashboardVersion: package_version, | ||
}), | ||
}, | ||
// We dont want to trigger the error boundary if this API fails | ||
ignoreErrors: true, | ||
}); | ||
} catch (_) { | ||
// ignored | ||
} | ||
}; | ||
|
||
const loadCount = useCallback(async () => { | ||
setLoading(true); | ||
const [countResult] = await Promise.all([fetchCount().catch(() => undefined), loadUsers()]); | ||
if (countResult) { | ||
setCount(countResult.count); | ||
} | ||
|
||
setLoading(false); | ||
}, []); | ||
|
||
|
@@ -138,6 +177,7 @@ export const UsersList: React.FC<UserListProps> = ({ | |
|
||
useEffect(() => { | ||
void loadCount(); | ||
void fireAnalyticsEvent(); | ||
}, [loadCount]); | ||
|
||
useEffect(() => { | ||
|
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 |
---|---|---|
|
@@ -13,4 +13,4 @@ | |
* under the License. | ||
*/ | ||
|
||
export const package_version = "0.4.5"; | ||
export const package_version = "0.5.0"; |