diff --git a/code/core/src/core-server/utils/doTelemetry.ts b/code/core/src/core-server/utils/doTelemetry.ts index c7d92c324d86..511616d02f24 100644 --- a/code/core/src/core-server/utils/doTelemetry.ts +++ b/code/core/src/core-server/utils/doTelemetry.ts @@ -1,5 +1,5 @@ import { getPrecedingUpgrade, telemetry } from '@storybook/core/telemetry'; -import type { CoreConfig, Options, StoryIndex } from '@storybook/core/types'; +import type { CoreConfig, Options } from '@storybook/core/types'; import invariant from 'tiny-invariant'; diff --git a/code/core/src/core-server/utils/save-story/save-story.ts b/code/core/src/core-server/utils/save-story/save-story.ts index 3113fd78e987..9131107fdc0c 100644 --- a/code/core/src/core-server/utils/save-story/save-story.ts +++ b/code/core/src/core-server/utils/save-story/save-story.ts @@ -4,7 +4,7 @@ import { basename, join } from 'node:path'; import type { Channel } from '@storybook/core/channels'; import { formatFileContent } from '@storybook/core/common'; -import { telemetry } from '@storybook/core/telemetry'; +import { isExampleStoryId, telemetry } from '@storybook/core/telemetry'; import type { CoreConfig, Options } from '@storybook/core/types'; import { storyNameFromExport, toId } from '@storybook/csf'; @@ -122,7 +122,9 @@ export function initializeSaveStory(channel: Channel, options: Options, coreConf error: null, } satisfies ResponseData); - if (!coreConfig.disableTelemetry) { + // don't take credit for save-from-controls actions against CLI example stories + const isCLIExample = isExampleStoryId(newStoryId ?? csfId); + if (!coreConfig.disableTelemetry && !isCLIExample) { await telemetry('save-story', { action: name ? 'createStory' : 'updateStory', success: true, diff --git a/code/core/src/core-server/utils/summarizeIndex.ts b/code/core/src/core-server/utils/summarizeIndex.ts index fa6ac93bcf51..75a5b09696ee 100644 --- a/code/core/src/core-server/utils/summarizeIndex.ts +++ b/code/core/src/core-server/utils/summarizeIndex.ts @@ -1,3 +1,4 @@ +import { isExampleStoryId } from '@storybook/core/telemetry'; import type { IndexEntry, StoryIndex } from '@storybook/core/types'; import { AUTODOCS_TAG, PLAY_FN_TAG, isMdxEntry } from './StoryIndexGenerator'; @@ -25,15 +26,6 @@ const isCLIExampleEntry = (entry: IndexEntry) => 'example-page--logged-out', ].includes(entry.id); -/** - * Is this story part of the CLI generated examples, - * including user-created stories in those files - */ -const isAnyExampleEntry = (entry: IndexEntry) => - entry.id.startsWith('example-button--') || - entry.id.startsWith('example-header--') || - entry.id.startsWith('example-page--'); - export function summarizeIndex(storyIndex: StoryIndex) { let storyCount = 0; const componentTitles = new Set(); @@ -49,7 +41,7 @@ export function summarizeIndex(storyIndex: StoryIndex) { if (isCLIExampleEntry(entry)) { if (entry.type === 'story') exampleStoryCount += 1; if (entry.type === 'docs') exampleDocsCount += 1; - } else if (isAnyExampleEntry(entry)) { + } else if (isExampleStoryId(entry.id)) { if (entry.type === 'story') onboardingStoryCount += 1; if (entry.type === 'docs') onboardingDocsCount += 1; } else if (entry.type === 'story') { diff --git a/code/core/src/telemetry/index.ts b/code/core/src/telemetry/index.ts index 82d3c0c1dacf..7af6810f6afb 100644 --- a/code/core/src/telemetry/index.ts +++ b/code/core/src/telemetry/index.ts @@ -16,6 +16,15 @@ export { getPrecedingUpgrade } from './event-cache'; export { addToGlobalContext } from './telemetry'; +/** + * Is this story part of the CLI generated examples, + * including user-created stories in those files + */ +export const isExampleStoryId = (storyId: string) => + storyId.startsWith('example-button--') || + storyId.startsWith('example-header--') || + storyId.startsWith('example-page--'); + export const telemetry = async ( eventType: EventType, payload: Payload = {},