diff --git a/docs/design/analytics.md b/docs/design/analytics.md index 68bbd388295f..d35be19436f3 100644 --- a/docs/design/analytics.md +++ b/docs/design/analytics.md @@ -79,6 +79,9 @@ PROJECT NAME TO BUILD OR A MODULE NAME.** | CssSizeInBytes | `epn.ng_css_size_bytes` | `number` | | JsSizeInBytes | `epn.ng_js_size_bytes` | `number` | | NgComponentCount | `epn.ng_component_count` | `number` | +| AllProjectsCount | `epn.all_projects_count` | `number` | +| LibraryProjectsCount | `epn.libs_projects_count` | `number` | +| ApplicationProjectsCount | `epn.apps_projects_count` | `number` | ## Debugging diff --git a/packages/angular/cli/src/analytics/analytics-collector.ts b/packages/angular/cli/src/analytics/analytics-collector.ts index e80f23814fa6..486aab0f1318 100644 --- a/packages/angular/cli/src/analytics/analytics-collector.ts +++ b/packages/angular/cli/src/analytics/analytics-collector.ts @@ -72,6 +72,12 @@ export class AnalyticsCollector { }; } + reportWorkspaceInfoEvent( + parameters: Partial>, + ): void { + this.event('workspace_info', parameters); + } + reportRebuildRunEvent( parameters: Partial< Record diff --git a/packages/angular/cli/src/analytics/analytics-parameters.ts b/packages/angular/cli/src/analytics/analytics-parameters.ts index 04aa550b8cf0..10683e80a1f7 100644 --- a/packages/angular/cli/src/analytics/analytics-parameters.ts +++ b/packages/angular/cli/src/analytics/analytics-parameters.ts @@ -97,4 +97,7 @@ export enum EventCustomMetric { CssSizeInBytes = 'epn.ng_css_size_bytes', JsSizeInBytes = 'epn.ng_js_size_bytes', NgComponentCount = 'epn.ng_component_count', + AllProjectsCount = 'epn.all_projects_count', + LibraryProjectsCount = 'epn.libs_projects_count', + ApplicationProjectsCount = 'epn.apps_projects_count', } diff --git a/packages/angular/cli/src/command-builder/command-module.ts b/packages/angular/cli/src/command-builder/command-module.ts index 8cb7469fa4a5..3e3a13e3ce38 100644 --- a/packages/angular/cli/src/command-builder/command-module.ts +++ b/packages/angular/cli/src/command-builder/command-module.ts @@ -146,22 +146,9 @@ export abstract class CommandModule implements CommandModuleI let exitCode: number | void | undefined; try { - // Run and time command. if (analytics) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const internalMethods = (yargs as any).getInternalMethods(); - // $0 generate component [name] -> generate_component - // $0 add -> add - const fullCommand = (internalMethods.getUsageInstance().getUsage()[0][0] as string) - .split(' ') - .filter((x) => { - const code = x.charCodeAt(0); - - return code >= 97 && code <= 122; - }) - .join('_'); - - analytics.reportCommandRunEvent(fullCommand); + this.reportCommandRunAnalytics(analytics); + this.reportWorkspaceInfoAnalytics(analytics); } exitCode = await this.run(camelCasedOptions as Options & OtherOptions); @@ -307,6 +294,49 @@ export abstract class CommandModule implements CommandModuleI return parameters; } + + private reportCommandRunAnalytics(analytics: AnalyticsCollector): void { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const internalMethods = (yargs as any).getInternalMethods(); + // $0 generate component [name] -> generate_component + // $0 add -> add + const fullCommand = (internalMethods.getUsageInstance().getUsage()[0][0] as string) + .split(' ') + .filter((x) => { + const code = x.charCodeAt(0); + + return code >= 97 && code <= 122; + }) + .join('_'); + + analytics.reportCommandRunEvent(fullCommand); + } + + private reportWorkspaceInfoAnalytics(analytics: AnalyticsCollector): void { + const { workspace } = this.context; + if (!workspace) { + return; + } + + let applicationProjectsCount = 0; + let librariesProjectsCount = 0; + for (const project of workspace.projects.values()) { + switch (project.extensions['projectType']) { + case 'application': + applicationProjectsCount++; + break; + case 'library': + librariesProjectsCount++; + break; + } + } + + analytics.reportWorkspaceInfoEvent({ + [EventCustomMetric.AllProjectsCount]: librariesProjectsCount + applicationProjectsCount, + [EventCustomMetric.ApplicationProjectsCount]: applicationProjectsCount, + [EventCustomMetric.LibraryProjectsCount]: librariesProjectsCount, + }); + } } /**