Skip to content

Commit

Permalink
feat(tracking) Add tracking events to our chrome extension page (#7967)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscollins3456 authored May 4, 2023
1 parent 8019d17 commit abeda11
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
18 changes: 17 additions & 1 deletion datahub-web-react/src/app/analytics/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export enum EventType {
SelectAutoCompleteOption,
SelectQuickFilterEvent,
DeselectQuickFilterEvent,
EmbedProfileViewEvent,
EmbedProfileViewInDataHubEvent,
}

/**
Expand Down Expand Up @@ -495,6 +497,18 @@ export interface DeselectQuickFilterEvent extends BaseEvent {
quickFilterValue: string;
}

export interface EmbedProfileViewEvent extends BaseEvent {
type: EventType.EmbedProfileViewEvent;
entityType: string;
entityUrn: string;
}

export interface EmbedProfileViewInDataHubEvent extends BaseEvent {
type: EventType.EmbedProfileViewInDataHubEvent;
entityType: string;
entityUrn: string;
}

/**
* Event consisting of a union of specific event types.
*/
Expand Down Expand Up @@ -557,4 +571,6 @@ export type Event =
| DeleteQueryEvent
| SelectAutoCompleteOption
| SelectQuickFilterEvent
| DeselectQuickFilterEvent;
| DeselectQuickFilterEvent
| EmbedProfileViewEvent
| EmbedProfileViewInDataHubEvent;
12 changes: 11 additions & 1 deletion datahub-web-react/src/app/embed/EmbeddedPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useParams } from 'react-router';
import styled from 'styled-components/macro';
import { useGetGrantedPrivilegesQuery } from '../../graphql/policy.generated';
Expand All @@ -9,6 +9,8 @@ import { decodeUrn } from '../entity/shared/utils';
import CompactContext from '../shared/CompactContext';
import { useEntityRegistry } from '../useEntityRegistry';
import { useGetAuthenticatedUserUrn } from '../useGetAuthenticatedUser';
import analytics from '../analytics/analytics';
import { EventType } from '../analytics';

const EmbeddedPageWrapper = styled.div`
max-height: 100%;
Expand All @@ -29,6 +31,14 @@ export default function EmbeddedPage({ entityType }: Props) {
const { urn: encodedUrn } = useParams<RouteParams>();
const urn = decodeUrn(encodedUrn);

useEffect(() => {
analytics.event({
type: EventType.EmbedProfileViewEvent,
entityType,
entityUrn: urn,
});
}, [entityType, urn]);

const authenticatedUserUrn = useGetAuthenticatedUserUrn();
const { data } = useGetGrantedPrivilegesQuery({
variables: {
Expand Down
11 changes: 11 additions & 0 deletions datahub-web-react/src/app/entity/shared/embed/EmbeddedHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { IconStyleType } from '../../Entity';
import { useEntityData } from '../EntityContext';
import { getDisplayedEntityType } from '../containers/profile/header/PlatformContent/PlatformContentContainer';
import { ANTD_GRAY } from '../constants';
import analytics from '../../../analytics/analytics';
import { EventType } from '../../../analytics';

const HeaderWrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -61,6 +63,14 @@ export default function EmbeddedHeader() {
const appConfig = useAppConfig();
const themeConfig = useTheme();

function trackClickViewInDataHub() {
analytics.event({
type: EventType.EmbedProfileViewInDataHubEvent,
entityType,
entityUrn: entityData?.urn || '',
});
}

const typeIcon = entityRegistry.getIcon(entityType, 12, IconStyleType.ACCENT, ANTD_GRAY[8]);
const displayedEntityType = getDisplayedEntityType(entityData, entityRegistry, entityType);
const entityName = entityRegistry.getDisplayName(entityType, entityData);
Expand All @@ -86,6 +96,7 @@ export default function EmbeddedHeader() {
href={`${window.location.origin}/${entityTypePathName}/${entityData?.urn}`}
target="_blank"
rel="noreferrer noopener"
onClick={trackClickViewInDataHub}
>
view in DataHub <ArrowRightOutlined />
</StyledLink>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public enum DataHubUsageEventType {
UPDATE_QUERY_EVENT("UpdateQueryEvent"),
SELECT_AUTO_COMPLETE_OPTION("SelectAutoCompleteOption"),
SELECT_QUICK_FILTER_EVENT("SelectQuickFilterEvent"),
DESELECT_QUICK_FILTER_EVENT("DeselectQuickFilterEvent");
DESELECT_QUICK_FILTER_EVENT("DeselectQuickFilterEvent"),
EMBED_PROFILE_VIEW_EVENT("EmbedProfileViewEvent"),
EMBED_PROFILE_VIEW_IN_DATAHUB_EVENT("EmbedProfileViewInDataHubEvent");

private final String type;

Expand Down

0 comments on commit abeda11

Please sign in to comment.