diff --git a/code/core/src/core-server/utils/doTelemetry.ts b/code/core/src/core-server/utils/doTelemetry.ts index be9479cf3348..5738f1aad560 100644 --- a/code/core/src/core-server/utils/doTelemetry.ts +++ b/code/core/src/core-server/utils/doTelemetry.ts @@ -1,5 +1,5 @@ import invariant from 'tiny-invariant'; -import type { CoreConfig, Options, StoryIndex } from '@storybook/core/types'; +import type { CoreConfig, Options } from '@storybook/core/types'; import { telemetry, getPrecedingUpgrade } from '@storybook/core/telemetry'; import { useStorybookMetadata } from './metadata'; import type { StoryIndexGenerator } from './StoryIndexGenerator'; 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 5369d99a4cba..d7e59d2eb766 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 @@ -16,7 +16,7 @@ import { storyNameFromExport, toId } from '@storybook/csf'; import { printCsf, readCsf } from '@storybook/core/csf-tools'; import { logger } from '@storybook/core/node-logger'; import type { CoreConfig, Options } from '@storybook/core/types'; -import { telemetry } from '@storybook/core/telemetry'; +import { isExampleStoryId, telemetry } from '@storybook/core/telemetry'; import { basename, join } from 'node:path'; import { updateArgsInCsfFile } from './update-args-in-csf-file'; @@ -120,7 +120,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 56b4b27ad929..2a1382f7c4f4 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 { isMdxEntry, AUTODOCS_TAG, PLAY_FN_TAG } 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 d8286d0b7535..8fe61e441011 100644 --- a/code/core/src/telemetry/index.ts +++ b/code/core/src/telemetry/index.ts @@ -15,6 +15,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 = {},