Skip to content

Commit

Permalink
Add keys and identify
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcmessias committed Oct 2, 2023
1 parent f823665 commit 34b61cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ steps:
<<: *build_frontend
environment:
ENVIRONMENT: staging
AMPLITUDE_API_KEY: d624f9cc751933b0725858700bb1946e
AMPLITUDE_API_KEY: b46a366c22a2e7fb525ae99c14a693ec

- name: build_frontend_production
<<: *build_frontend
environment:
ENVIRONMENT: production
AMPLITUDE_API_KEY: 'foo'
AMPLITUDE_API_KEY: f0b9cf5c530426c3dbacb91e74f009a5

- name: docker_frontend_staging
<<: *docker_build_config
Expand Down
22 changes: 22 additions & 0 deletions datahub-web-react/src/app/context/UserContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useGetMeLazyQuery } from '../../graphql/me.generated';
import { useGetGlobalViewsSettingsLazyQuery } from '../../graphql/app.generated';
import { CorpUser, PlatformPrivileges } from '../../types.generated';
import { UserContext, LocalState, DEFAULT_STATE, State } from './userContext';
import analytics from '../analytics';

// TODO: Migrate all usage of useAuthenticatedUser to using this provider.

Expand Down Expand Up @@ -41,6 +42,27 @@ const UserContextProvider = ({ children }: { children: React.ReactNode }) => {
const [getMe, { data: meData, refetch }] = useGetMeLazyQuery({ fetchPolicy: 'cache-first' });
useEffect(() => getMe(), [getMe]);

/**
* Identify the user in the analytics tool once on component mount.
*
* This lets Amplitude identify (and thus segment) the users on more attribu
*
* There's likely a more optimal place in the app to do this (ideally immedi
* the user logs in). However, the login flow (particular with SSO) is a bit
* follow, and I don't think these calls are particularly expensive, so here
*/
useEffect(() => {
if (meData?.me?.corpUser) {
const corpUser = meData.me.corpUser as CorpUser;
const info = corpUser.info ?? {};
console.log('v1!');
console.log('Identifying user', corpUser.urn, info);
analytics.identify(corpUser.urn, {
...info,
});
}
}, [meData]);

/**
* Retrieve the Global View settings once on component mount.
*/
Expand Down

0 comments on commit 34b61cf

Please sign in to comment.