Skip to content

Commit

Permalink
feat: track groups pushed
Browse files Browse the repository at this point in the history
  • Loading branch information
BohdanOne committed Nov 29, 2024
1 parent 07186ba commit 2891d49
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/manager/src/managers/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const SegmentEventType = {
legacySlice_converted: "legacy-slice:converted",
screenshotTaken: "screenshot-taken",
changes_pushed: "changes:pushed",
changes_groupPushed: "changes:group-pushed",
changes_limitReach: "changes:limit-reach",
editor_widgetUsed: "editor:widget-used",
open_page_snippet: "page-type:open-snippet",
Expand Down Expand Up @@ -71,6 +72,7 @@ export const HumanSegmentEventType = {
"SliceMachine Legacy Slice Converted",
[SegmentEventType.screenshotTaken]: "SliceMachine Screenshot Taken",
[SegmentEventType.changes_pushed]: "SliceMachine Changes Pushed",
[SegmentEventType.changes_groupPushed]: "SliceMachine Group Field Pushed",
[SegmentEventType.changes_limitReach]: "SliceMachine Changes Limit Reach",
[SegmentEventType.editor_widgetUsed]: "SliceMachine Editor Widget Used",
[SegmentEventType.open_page_snippet]:
Expand Down Expand Up @@ -294,6 +296,16 @@ type ChangesPushedSegmentEvent = SegmentEvent<
}
>;

type ChangesGroupPushedSegmentEvent = SegmentEvent<
typeof SegmentEventType.changes_groupPushed,
{
isInStaticZone: boolean;
isInSlice: boolean;
} & {
[key in FieldType]?: number;
}
>;

type ChangesLimitReachSegmentEvent = SegmentEvent<
typeof SegmentEventType.changes_limitReach,
{ limitType: PushChangesLimitType }
Expand Down Expand Up @@ -410,6 +422,7 @@ export type SegmentEvents =
| LegacySliceConvertedSegmentEvent
| ScreenshotTakenSegmentEvent
| ChangesPushedSegmentEvent
| ChangesGroupPushedSegmentEvent
| ChangesLimitReachSegmentEvent
| EditorWidgetUsedSegmentEvent
| OpenPageSnippetSegmentEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { FieldType } from "@prismicio/types-internal/lib/customtypes";

import { telemetry } from "@/apiClient";
import { countMissingScreenshots } from "@/domain/slice";
import {
Expand Down Expand Up @@ -94,4 +96,82 @@ export function trackPushChangesSuccess(args: TrackPushChangesSuccessArgs) {
hasDeletedDocuments,
_includeEnvironmentKind: true,
});

trackPushedGroups({ changedCustomTypes, changedSlices });
}

type TrackPushedGroupsArgs = {
changedSlices: ReadonlyArray<ChangedSlice>;
changedCustomTypes: ReadonlyArray<ChangedCustomType>;
};

type FieldStats = {
isInStaticZone: boolean;
isInSlice: boolean;
} & {
[key in FieldType]?: number;
};

function trackPushedGroups(args: TrackPushedGroupsArgs) {
const { changedCustomTypes, changedSlices } = args;

const groupsInStaticZone = changedCustomTypes.reduce<FieldStats[]>(
(acc, customType) => {
if (customType.status !== ModelStatus.New) return acc;

customType.customType.tabs.forEach((tab) => {
tab.value.forEach((field) => {
if (field.value.type === "Group" && field.value.config?.fields) {
const fieldStats: FieldStats = {
isInStaticZone: true,
isInSlice: false,
};
field.value.config.fields.forEach((field) => {
if (typeof fieldStats[field.value.type] !== "number") {
fieldStats[field.value.type] = 1;
} else {
fieldStats[field.value.type]! += 1;
}
});
acc.push(fieldStats);
}
});
});

return acc;
},
[],
);

const groupsInSlices = changedSlices.reduce<FieldStats[]>((acc, slice) => {
if (slice.status !== ModelStatus.New) return acc;

slice.slice.model.variations.forEach((variation) => {
variation.primary?.forEach((field) => {
if (field.value.type === "Group" && field.value.config?.fields) {
const fieldStats: FieldStats = {
isInStaticZone: false,
isInSlice: true,
};
field.value.config.fields.forEach((field) => {
if (typeof fieldStats[field.value.type] !== "number") {
fieldStats[field.value.type] = 1;
} else {
fieldStats[field.value.type]! += 1;
}
});
acc.push(fieldStats);
}
});
});

return acc;
}, []);

[...groupsInSlices, ...groupsInStaticZone].forEach((group) => {
void telemetry.track({
event: "changes:group-pushed",
...group,
});
});
}

0 comments on commit 2891d49

Please sign in to comment.