ImagesTable/BlueprintsSideBar: Add Segment tracking (HMS-5989)

Needed so the Intercom team can decide whether or not to display an
onboarding video (first time user with no images or blueprints).
This commit is contained in:
Lucas Garfield 2025-04-16 11:49:44 -05:00 committed by Klara Simickova
parent 561e9d164e
commit e222b13476
3 changed files with 44 additions and 1 deletions

View file

@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import {
Bullseye,
@ -18,6 +18,8 @@ import {
} from '@patternfly/react-core';
import { PlusCircleIcon, SearchIcon } from '@patternfly/react-icons';
import { SVGIconProps } from '@patternfly/react-icons/dist/esm/createIcon';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';
import { ChromeUser } from '@redhat-cloud-services/types';
import debounce from 'lodash/debounce';
import { Link } from 'react-router-dom';
@ -46,6 +48,7 @@ import {
} from '../../store/imageBuilderApi';
import { imageBuilderApi } from '../../store/service/enhancedImageBuilderApi';
import { resolveRelPath } from '../../Utilities/path';
import { useGetEnvironment } from '../../Utilities/useGetEnvironment';
type blueprintSearchProps = {
blueprintsTotal: number;
@ -60,6 +63,10 @@ type emptyBlueprintStateProps = {
};
const BlueprintsSidebar = () => {
const [userData, setUserData] = useState<ChromeUser | void>(undefined);
const { isFedoraEnv } = useGetEnvironment();
const { analytics, auth } = useChrome();
const selectedBlueprintId = useAppSelector(selectSelectedBlueprintId);
const blueprintSearchInput = useAppSelector(selectBlueprintSearchInput);
const blueprintsOffset = useAppSelector(selectOffset) || PAGINATION_OFFSET;
@ -70,6 +77,13 @@ const BlueprintsSidebar = () => {
offset: blueprintsOffset,
};
useEffect(() => {
(async () => {
const data = await auth?.getUser();
setUserData(data);
})();
}, [auth]);
if (blueprintSearchInput) {
searchParams.search = blueprintSearchInput;
}
@ -119,6 +133,14 @@ const BlueprintsSidebar = () => {
dispatch(setBlueprintId(undefined));
};
if (!process.env.IS_ON_PREMISE && !isFedoraEnv) {
const orgId = userData?.identity?.internal?.org_id;
analytics.group(orgId, {
imagebuilder_blueprint_count: blueprintsData?.meta.count,
});
}
return (
<>
<Stack hasGutter>