Skip to content

Commit

Permalink
Setup Amplitude in the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcmessias committed Oct 6, 2023
1 parent df69902 commit e543a3c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 8 deletions.
22 changes: 22 additions & 0 deletions .ecr-repository-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ECR Repository Policy",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer"
],
"Condition": {
"StringEquals": {
"aws:PrincipalOrgID": "o-t9bcvmrskg"
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private List<Highlight> getHighlights() {
getEntityMetadataStats("Pipelines", EntityType.DATA_FLOW).ifPresent(highlights::add);
getEntityMetadataStats("Tasks", EntityType.DATA_JOB).ifPresent(highlights::add);
getEntityMetadataStats("Domains", EntityType.DOMAIN).ifPresent(highlights::add);
getEntityMetadataStats("Data Products", EntityType.DATA_PRODUCT).ifPresent(highlights::add);
return highlights;
}

Expand Down
3 changes: 2 additions & 1 deletion datahub-web-react/src/app/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ const { NODE_ENV } = process.env;

export function getMergedTrackingOptions(options?: any) {
const isThirdPartyLoggingEnabled = JSON.parse(localStorage.getItem(THIRD_PARTY_LOGGING_KEY) || 'false');

return {
...options,
plugins: {
mixpanel: isThirdPartyLoggingEnabled,
amplitude: isThirdPartyLoggingEnabled,
amplitude: true, // Only want amplitude so hard-code true. We hard code the API keys too, so 🤷
googleAnalytics: isThirdPartyLoggingEnabled,
},
};
Expand Down
10 changes: 9 additions & 1 deletion datahub-web-react/src/app/analytics/plugin/amplitude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@ const apiKey = isEnabled ? amplitudeConfigs.apiKey : undefined;

export default {
isEnabled,
plugin: apiKey && amplitude({ apiKey, options: {} }),
plugin:
apiKey &&
amplitude({
apiKey,
options: {
apiEndpoint: 'api.eu.amplitude.com',
serverZone: 'EU',
},
}),
};
16 changes: 16 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,21 @@ 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 attributes.
* There may be a more optimal place to put this call, but I'm not sure
*/
useEffect(() => {
if (meData?.me?.corpUser) {
const corpUser = meData.me.corpUser as CorpUser;
const info = corpUser.info ?? {};
analytics.identify(corpUser.urn, {
...info,
});
}
}, [meData]);

/**
* Retrieve the Global View settings once on component mount.
*/
Expand Down
8 changes: 4 additions & 4 deletions datahub-web-react/src/conf/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const config: any = {
// mixpanel: {
// token: 'fad1285da4e618b618973cacf6565e61',
// },
// amplitude: {
// apiKey: 'c5c212632315d19c752ab083bc7c92ff',
// },
// logging: true,
amplitude: {
apiKey: '<AMPLITUDE_API_KEY>',
},
logging: true,
datahub: {
enabled: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class TelemetryConfiguration {
* Whether or not server telemetry should be enabled
*/
public boolean enabledServer;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,4 @@ cache:
search:
lineage:
ttlSeconds: ${CACHE_SEARCH_LINEAGE_TTL_SECONDS:86400} # 1 day
lightningThreshold: ${CACHE_SEARCH_LINEAGE_LIGHTNING_THRESHOLD:300}
lightningThreshold: ${CACHE_SEARCH_LINEAGE_LIGHTNING_THRESHOLD:300}

0 comments on commit e543a3c

Please sign in to comment.