Skip to content

Commit f5bccbd

Browse files
committed
refactor(@angular/cli): add AI config tool to GA tracking
This commit adds the AI config tool option to GA tracking. Since this option is an array we had to work around a limitation that custom dimensions cannot have an array as value.
1 parent 653b483 commit f5bccbd

File tree

8 files changed

+24
-9
lines changed

8 files changed

+24
-9
lines changed

docs/design/analytics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ PROJECT NAME TO BUILD OR A MODULE NAME.**
5555
| Name | Parameter | Type |
5656
|:---:|:---|:---|
5757
| Command | `ep.ng_command` | `string` |
58+
| AiConfigTool | `ep.ng_ai_config_tool` | `string` |
5859
| SchematicCollectionName | `ep.ng_schematic_collection_name` | `string` |
5960
| SchematicName | `ep.ng_schematic_name` | `string` |
6061
| Standalone | `ep.ng_standalone` | `string` |

packages/angular/cli/src/analytics/analytics-parameters.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export enum UserCustomDimension {
6969
*/
7070
export enum EventCustomDimension {
7171
Command = 'ep.ng_command',
72+
AiConfigTool = 'ep.ng_ai_config_tool',
7273
SchematicCollectionName = 'ep.ng_schematic_collection_name',
7374
SchematicName = 'ep.ng_schematic_name',
7475
Standalone = 'ep.ng_standalone',

packages/angular/cli/src/analytics/analytics-parameters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export enum UserCustomDimension {
7171
*/
7272
export enum EventCustomDimension {
7373
Command = 'ep.ng_command',
74+
AiConfigTool = 'ep.ng_ai_config_tool',
7475
SchematicCollectionName = 'ep.ng_schematic_collection_name',
7576
SchematicName = 'ep.ng_schematic_name',
7677
Standalone = 'ep.ng_standalone',

packages/angular/cli/src/command-builder/command-module.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
8989
protected readonly shouldReportAnalytics: boolean = true;
9090
readonly scope: CommandScope = CommandScope.Both;
9191

92-
private readonly optionsWithAnalytics = new Map<string, string>();
92+
private readonly optionsWithAnalytics = new Map<
93+
string,
94+
EventCustomDimension | EventCustomMetric
95+
>();
9396

9497
constructor(protected readonly context: CommandContext) {}
9598

@@ -236,12 +239,16 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
236239
]);
237240

238241
for (const [name, ua] of this.optionsWithAnalytics) {
242+
if (!validEventCustomDimensionAndMetrics.has(ua)) {
243+
continue;
244+
}
245+
239246
const value = options[name];
240-
if (
241-
(typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') &&
242-
validEventCustomDimensionAndMetrics.has(ua as EventCustomDimension | EventCustomMetric)
243-
) {
244-
parameters[ua as EventCustomDimension | EventCustomMetric] = value;
247+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
248+
parameters[ua] = value;
249+
} else if (Array.isArray(value)) {
250+
// GA doesn't allow array as values.
251+
parameters[ua] = value.sort().join(', ');
245252
}
246253
}
247254

packages/angular/cli/src/command-builder/schematics-command-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,13 @@ export abstract class SchematicsCommandModule
204204
? {
205205
name: item,
206206
value: item,
207+
checked: item === definition.default,
207208
}
208209
: {
209210
...item,
210211
name: item.label,
211212
value: item.value,
213+
checked: item.value === definition.default,
212214
},
213215
),
214216
});

packages/angular/cli/src/command-builder/utilities/json-schema.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { json, strings } from '@angular-devkit/core';
1010
import type { Arguments, Argv, PositionalOptions, Options as YargsOptions } from 'yargs';
11+
import { EventCustomDimension } from '../../analytics/analytics-parameters';
1112

1213
/**
1314
* An option description.
@@ -280,10 +281,10 @@ export function addSchemaOptionsToCommand<T>(
280281
localYargs: Argv<T>,
281282
options: Option[],
282283
includeDefaultValues: boolean,
283-
): Map<string, string> {
284+
): Map<string, EventCustomDimension> {
284285
const booleanOptionsWithNoPrefix = new Set<string>();
285286
const keyValuePairOptions = new Set<string>();
286-
const optionsWithAnalytics = new Map<string, string>();
287+
const optionsWithAnalytics = new Map<string, EventCustomDimension>();
287288

288289
for (const option of options) {
289290
const {
@@ -338,7 +339,7 @@ export function addSchemaOptionsToCommand<T>(
338339

339340
// Record option of analytics.
340341
if (userAnalytics !== undefined) {
341-
optionsWithAnalytics.set(name, userAnalytics);
342+
optionsWithAnalytics.set(name, userAnalytics as EventCustomDimension);
342343
}
343344
}
344345

packages/schematics/angular/ai-config/schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"default": "none",
1313
"x-prompt": "Which AI tools do you want to configure with Angular best practices? https://angular.dev/ai/develop-with-ai",
1414
"description": "Specifies which AI tools to generate configuration files for. These file are used to improve the outputs of AI tools by following the best practices.",
15+
"x-user-analytics": "ep.ng_ai_config_tool",
1516
"items": {
1617
"type": "string",
1718
"enum": ["none", "gemini", "copilot", "claude", "cursor", "jetbrains", "windsurf"]

packages/schematics/angular/ng-new/schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"type": "array",
148148
"uniqueItems": true,
149149
"description": "Specifies which AI tools to generate configuration files for. These file are used to improve the outputs of AI tools by following the best practices.",
150+
"x-user-analytics": "ep.ng_ai_config_tool",
150151
"items": {
151152
"type": "string",
152153
"enum": ["none", "gemini", "copilot", "claude", "cursor", "jetbrains", "windsurf"]

0 commit comments

Comments
 (0)