Wizard: Update Amplitude tracking

This updates snippets used for event tracking in Amplitude, adding `imageBuilder` to the name of the event and as a `module` property.

Two more typed events were also added to track number of created blueprints. Name for both events is the same `blueprintCreated`, the differentiation between Create and Create and build images is captured in the `type` property.

These new events will allow to calculate percentage of users that were shown recommendations and of those who added a recommended package while succesfully finishing blueprint creation.
This commit is contained in:
regexowl 2024-08-22 08:37:42 +02:00 committed by Klara Simickova
parent 568c85066d
commit be8a00d186
3 changed files with 40 additions and 12 deletions

View file

@ -24,7 +24,7 @@ import { useDispatch } from 'react-redux';
import PackageRecommendationDescription from './components/PackageRecommendationDescription'; import PackageRecommendationDescription from './components/PackageRecommendationDescription';
import { RedHatRepository } from './Packages'; import { RedHatRepository } from './Packages';
import { ContentOrigin } from '../../../../constants'; import { AMPLITUDE_MODULE_NAME, ContentOrigin } from '../../../../constants';
import { useListRepositoriesQuery } from '../../../../store/contentSourcesApi'; import { useListRepositoriesQuery } from '../../../../store/contentSourcesApi';
import { useAppSelector } from '../../../../store/hooks'; import { useAppSelector } from '../../../../store/hooks';
import { useRecommendPackageMutation } from '../../../../store/imageBuilderApi'; import { useRecommendPackageMutation } from '../../../../store/imageBuilderApi';
@ -78,10 +78,14 @@ const PackageRecommendations = () => {
}); });
if (response && response.data && response.data.packages.length > 0) { if (response && response.data && response.data.packages.length > 0) {
analytics.track('recommendationsShown', { analytics.track(
shownRecommendations: response.data.packages, `${AMPLITUDE_MODULE_NAME}-packageRecommendationsShown`,
selectedPackages: packages.map((pkg) => pkg.name), {
}); module: AMPLITUDE_MODULE_NAME,
shownRecommendations: response.data.packages,
selectedPackages: packages.map((pkg) => pkg.name),
}
);
} }
})(); })();
} }
@ -224,13 +228,17 @@ const PackageRecommendations = () => {
variant="link" variant="link"
component="a" component="a"
onClick={() => { onClick={() => {
analytics.track('recommendedPackageAdded', { analytics.track(
packageName: pkg, `${AMPLITUDE_MODULE_NAME}-recommendedPackageAdded`,
selectedPackages: packages.map( {
(pkg) => pkg.name module: AMPLITUDE_MODULE_NAME,
), packageName: pkg,
shownRecommendations: data.packages, selectedPackages: packages.map(
}); (pkg) => pkg.name
),
shownRecommendations: data.packages,
}
);
addRecommendedPackage(pkg); addRecommendedPackage(pkg);
}} }}
isInline isInline

View file

@ -10,7 +10,9 @@ import {
Modal, Modal,
Button, Button,
} from '@patternfly/react-core'; } from '@patternfly/react-core';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';
import { AMPLITUDE_MODULE_NAME } from '../../../../../constants';
import { setBlueprintId } from '../../../../../store/BlueprintSlice'; import { setBlueprintId } from '../../../../../store/BlueprintSlice';
import { useAppDispatch } from '../../../../../store/hooks'; import { useAppDispatch } from '../../../../../store/hooks';
import { import {
@ -30,6 +32,8 @@ export const CreateSaveAndBuildBtn = ({
setIsOpen, setIsOpen,
isDisabled, isDisabled,
}: CreateDropdownProps) => { }: CreateDropdownProps) => {
const { analytics } = useChrome();
const [buildBlueprint] = useComposeBlueprintMutation(); const [buildBlueprint] = useComposeBlueprintMutation();
const [createBlueprint] = useCreateBlueprintMutation({ const [createBlueprint] = useCreateBlueprintMutation({
fixedCacheKey: 'createBlueprintKey', fixedCacheKey: 'createBlueprintKey',
@ -38,6 +42,12 @@ export const CreateSaveAndBuildBtn = ({
const onSaveAndBuild = async () => { const onSaveAndBuild = async () => {
const requestBody = await getBlueprintPayload(); const requestBody = await getBlueprintPayload();
setIsOpen(false); setIsOpen(false);
analytics.track(`${AMPLITUDE_MODULE_NAME}-blueprintCreated`, {
module: AMPLITUDE_MODULE_NAME,
type: 'createBlueprintAndBuildImages',
});
const blueprint = const blueprint =
requestBody && requestBody &&
(await createBlueprint({ (await createBlueprint({
@ -68,6 +78,8 @@ export const CreateSaveButton = ({
getBlueprintPayload, getBlueprintPayload,
isDisabled, isDisabled,
}: CreateDropdownProps) => { }: CreateDropdownProps) => {
const { analytics } = useChrome();
const [createBlueprint, { isLoading }] = useCreateBlueprintMutation({ const [createBlueprint, { isLoading }] = useCreateBlueprintMutation({
fixedCacheKey: 'createBlueprintKey', fixedCacheKey: 'createBlueprintKey',
}); });
@ -120,11 +132,17 @@ export const CreateSaveButton = ({
setIsOpen(false); setIsOpen(false);
analytics.track(`${AMPLITUDE_MODULE_NAME}-blueprintCreated`, {
module: AMPLITUDE_MODULE_NAME,
type: 'createBlueprint',
});
const blueprint = const blueprint =
requestBody && requestBody &&
(await createBlueprint({ (await createBlueprint({
createBlueprintRequest: requestBody, createBlueprintRequest: requestBody,
}).unwrap()); }).unwrap());
if (blueprint) { if (blueprint) {
dispatch(setBlueprintId(blueprint?.id)); dispatch(setBlueprintId(blueprint?.id));
} }

View file

@ -227,3 +227,5 @@ export enum ContentOrigin {
'CUSTOM' = 'external,upload', 'CUSTOM' = 'external,upload',
'ALL' = 'red_hat,external,upload', 'ALL' = 'red_hat,external,upload',
} }
export const AMPLITUDE_MODULE_NAME = 'imageBuilder';