Skip to content

Commit a177fce

Browse files
authored
Merge pull request #28870 from storybookjs/shilman/fix-save-from-controls-telemetry
Telemetry: Disable save-from-controls logging for example stories
2 parents 763deb5 + c64542e commit a177fce

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

code/core/src/core-server/utils/doTelemetry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getPrecedingUpgrade, telemetry } from '@storybook/core/telemetry';
2-
import type { CoreConfig, Options, StoryIndex } from '@storybook/core/types';
2+
import type { CoreConfig, Options } from '@storybook/core/types';
33

44
import invariant from 'tiny-invariant';
55

code/core/src/core-server/utils/save-story/save-story.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { basename, join } from 'node:path';
44

55
import type { Channel } from '@storybook/core/channels';
66
import { formatFileContent } from '@storybook/core/common';
7-
import { telemetry } from '@storybook/core/telemetry';
7+
import { isExampleStoryId, telemetry } from '@storybook/core/telemetry';
88
import type { CoreConfig, Options } from '@storybook/core/types';
99
import { storyNameFromExport, toId } from '@storybook/csf';
1010

@@ -122,7 +122,9 @@ export function initializeSaveStory(channel: Channel, options: Options, coreConf
122122
error: null,
123123
} satisfies ResponseData<SaveStoryResponsePayload>);
124124

125-
if (!coreConfig.disableTelemetry) {
125+
// don't take credit for save-from-controls actions against CLI example stories
126+
const isCLIExample = isExampleStoryId(newStoryId ?? csfId);
127+
if (!coreConfig.disableTelemetry && !isCLIExample) {
126128
await telemetry('save-story', {
127129
action: name ? 'createStory' : 'updateStory',
128130
success: true,

code/core/src/core-server/utils/summarizeIndex.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isExampleStoryId } from '@storybook/core/telemetry';
12
import type { IndexEntry, StoryIndex } from '@storybook/core/types';
23

34
import { AUTODOCS_TAG, PLAY_FN_TAG, isMdxEntry } from './StoryIndexGenerator';
@@ -25,15 +26,6 @@ const isCLIExampleEntry = (entry: IndexEntry) =>
2526
'example-page--logged-out',
2627
].includes(entry.id);
2728

28-
/**
29-
* Is this story part of the CLI generated examples,
30-
* including user-created stories in those files
31-
*/
32-
const isAnyExampleEntry = (entry: IndexEntry) =>
33-
entry.id.startsWith('example-button--') ||
34-
entry.id.startsWith('example-header--') ||
35-
entry.id.startsWith('example-page--');
36-
3729
export function summarizeIndex(storyIndex: StoryIndex) {
3830
let storyCount = 0;
3931
const componentTitles = new Set<string>();
@@ -49,7 +41,7 @@ export function summarizeIndex(storyIndex: StoryIndex) {
4941
if (isCLIExampleEntry(entry)) {
5042
if (entry.type === 'story') exampleStoryCount += 1;
5143
if (entry.type === 'docs') exampleDocsCount += 1;
52-
} else if (isAnyExampleEntry(entry)) {
44+
} else if (isExampleStoryId(entry.id)) {
5345
if (entry.type === 'story') onboardingStoryCount += 1;
5446
if (entry.type === 'docs') onboardingDocsCount += 1;
5547
} else if (entry.type === 'story') {

code/core/src/telemetry/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ export { getPrecedingUpgrade } from './event-cache';
1616

1717
export { addToGlobalContext } from './telemetry';
1818

19+
/**
20+
* Is this story part of the CLI generated examples,
21+
* including user-created stories in those files
22+
*/
23+
export const isExampleStoryId = (storyId: string) =>
24+
storyId.startsWith('example-button--') ||
25+
storyId.startsWith('example-header--') ||
26+
storyId.startsWith('example-page--');
27+
1928
export const telemetry = async (
2029
eventType: EventType,
2130
payload: Payload = {},

0 commit comments

Comments
 (0)