Skip to content

Commit 639a307

Browse files
committed
refactor: migrate analytics collector to use GA4
This change updates the analytics collector collector to use GA4 instead of UA. The motivation behind this change is that UA will stop collecting data in 2023. BREAKING CHANGE: `analyticsSharing` option in the global angular configuration has been removed without replacement. This option was used to configure the Angular CLI to access to your own users' CLI usage data. If this option is used, it can be removed using `ng config --global cli.analyticsSharing undefined`.
1 parent 6c3f281 commit 639a307

File tree

32 files changed

+555
-807
lines changed

32 files changed

+555
-807
lines changed

docs/design/analytics.md

Lines changed: 58 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document list exactly what is gathered and how.
44

55
Any change to analytics should most probably include a change to this document.
66

7-
# Pageview
7+
## Pageview
88

99
Each command creates a pageview with the path `/command/${commandName}/${subcommandName}`. IE.
1010
`ng generate component my-component --dryRun` would create a page view with the path
@@ -16,7 +16,7 @@ Project names and target names will be removed.
1616
The command `ng run some-project:lint:some-configuration` will create a page view with the path
1717
`/command/run`.
1818

19-
# Dimensions
19+
## Dimensions and Metrics
2020

2121
Google Analytics Custom Dimensions are used to track system values and flag values. These
2222
dimensions are aggregated automatically on the backend.
@@ -25,94 +25,83 @@ One dimension per flag, and although technically there can be an overlap between
2525
simplicity it should remain unique across all CLI commands. The dimension is the value of the
2626
`x-user-analytics` field in the `schema.json` files.
2727

28-
To create a new dimension (tracking a new flag):
29-
30-
1. Create the dimension on analytics.google.com first. Dimensions are not tracked if they aren't
31-
defined on GA.
28+
### Adding dimension or metic.
29+
1. Create the dimension or metric in (https://analytics.google.com/)[Google Analytics] first. These are not tracked if they aren't
30+
defined in Google Analytics.
3231
1. Use the ID of the dimension as the `x-user-analytics` value in the `schema.json` file.
33-
1. Add a new row to the table below in the same PR as the one adding the dimension to the code.
34-
1. New dimension PRs need to be approved by the tooling and DevRel leads.
35-
**This is not negotiable.**
32+
1. New dimension and metrics PRs need to be approved by the tooling lead and require a new (http://go/launch)[Launch].
33+
34+
### Deleting a dimension or metic.
35+
1. Archive the dimension and metric in (https://analytics.google.com/)[Google Analytics].
36+
3637

3738
**DO NOT ADD `x-user-analytics` FOR VALUES THAT ARE USER IDENTIFIABLE (PII), FOR EXAMPLE A
3839
PROJECT NAME TO BUILD OR A MODULE NAME.**
3940

40-
Note: There's a limit of 20 custom dimensions.
41+
### Limits
42+
| Item | Standard property limits |
43+
|-------------------------------- |-------------------------- |
44+
| Event-scoped custom dimensions | 50 |
45+
| User-scoped custom dimensions | 25 |
46+
| All custom metrics | 50 |
4147

42-
### List Of All Dimensions
48+
### List Of User Custom Dimensions
49+
50+
<!--USER_DIMENSIONS_TABLE_BEGIN-->
51+
| Name | Parameter | Type |
52+
|:---:|:---|:---|
53+
| Command | `ep.ng_command` | `string` |
54+
| SchematicCollectionName | `ep.ng_schematic_collection_name` | `string` |
55+
| SchematicName | `ep.ng_schematic_name` | `string` |
56+
| Standalone | `ep.ng_standalone` | `string` |
57+
| Style | `ep.ng_style` | `string` |
58+
| Routing | `ep.ng_routing` | `string` |
59+
| InlineTemplate | `ep.ng_inline_template` | `string` |
60+
| InlineStyle | `ep.ng_inline_style` | `string` |
61+
| BuilderTarget | `ep.ng_builder_target` | `string` |
62+
| Aot | `ep.ng_aot` | `string` |
63+
| Optimization | `ep.ng_optimization` | `string` |
64+
<!--USER_DIMENSIONS_TABLE_END-->
65+
66+
### List Of Event Custom Dimensions
4367

4468
<!--DIMENSIONS_TABLE_BEGIN-->
45-
| Id | Flag | Type |
69+
| Name | Parameter | Type |
4670
|:---:|:---|:---|
47-
| 1 | `CPU Count` | `number` |
48-
| 2 | `CPU Speed` | `number` |
49-
| 3 | `RAM (In GB)` | `number` |
50-
| 4 | `Node Version` | `number` |
51-
| 5 | `Flag: --style` | `string` |
52-
| 6 | `--collection` | `string` |
53-
| 7 | `Flag: --strict` | `boolean` |
54-
| 8 | `Angular CLI Major Version` | `string` |
55-
| 9 | `Flag: --inline-style` | `boolean` |
56-
| 10 | `Flag: --inline-template` | `boolean` |
57-
| 11 | `Flag: --view-encapsulation` | `string` |
58-
| 12 | `Flag: --skip-tests` | `boolean` |
59-
| 13 | `Flag: --aot` | `boolean` |
60-
| 14 | `Flag: --minimal` | `boolean` |
61-
| 15 | `Flag: --standalone` | `boolean` |
62-
| 16 | `Flag: --optimization` | `boolean` |
63-
| 17 | `Flag: --routing` | `boolean` |
64-
| 18 | `Flag: --skip-import` | `boolean` |
65-
| 19 | `Flag: --export` | `boolean` |
66-
| 20 | `Build Errors (comma separated)` | `string` |
71+
| Command | `ep.ng_command` | `string` |
72+
| SchematicCollectionName | `ep.ng_schematic_collection_name` | `string` |
73+
| SchematicName | `ep.ng_schematic_name` | `string` |
74+
| Standalone | `ep.ng_standalone` | `string` |
75+
| Style | `ep.ng_style` | `string` |
76+
| Routing | `ep.ng_routing` | `string` |
77+
| InlineTemplate | `ep.ng_inline_template` | `string` |
78+
| InlineStyle | `ep.ng_inline_style` | `string` |
79+
| BuilderTarget | `ep.ng_builder_target` | `string` |
80+
| Aot | `ep.ng_aot` | `string` |
81+
| Optimization | `ep.ng_optimization` | `string` |
6782
<!--DIMENSIONS_TABLE_END-->
6883

69-
# Metrics
70-
71-
### List of All Metrics
84+
### List Of Event Custom Metrics
7285

7386
<!--METRICS_TABLE_BEGIN-->
74-
| Id | Flag | Type |
87+
| Name | Parameter | Type |
7588
|:---:|:---|:---|
76-
| 1 | `NgComponentCount` | `number` |
77-
| 2 | `UNUSED_2` | `none` |
78-
| 3 | `UNUSED_3` | `none` |
79-
| 4 | `UNUSED_4` | `none` |
80-
| 5 | `Build Time` | `number` |
81-
| 6 | `NgOnInit Count` | `number` |
82-
| 7 | `Initial Chunk Size` | `number` |
83-
| 8 | `Total Chunk Count` | `number` |
84-
| 9 | `Total Chunk Size` | `number` |
85-
| 10 | `Lazy Chunk Count` | `number` |
86-
| 11 | `Lazy Chunk Size` | `number` |
87-
| 12 | `Asset Count` | `number` |
88-
| 13 | `Asset Size` | `number` |
89-
| 14 | ` Polyfill Size` | `number` |
90-
| 15 | ` Css Size` | `number` |
89+
| AllChunksCount | `epn.ng_all_chunks_count` | `number` |
90+
| LazyChunksCount | `epn.ng_lazy_chunks_count` | `number` |
91+
| InitialChunksCount | `epn.ng_initial_chunks_count` | `number` |
92+
| ChangedChunksCount | `epn.ng_changed_chunks_count` | `number` |
93+
| DurationInMs | `epn.ng_duration_ms` | `number` |
9194
<!--METRICS_TABLE_END-->
9295

93-
# Operating System and Node Version
94-
95-
A User Agent string is built to "fool" Google Analytics into reading the Operating System and
96-
version fields from it. The base dimensions are used for those.
97-
98-
Node version is our App ID, but a dimension is also used to get the numeric MAJOR.MINOR of node.
99-
100-
# Debugging
101-
102-
Using `DEBUG=ng:analytics` will report additional information regarding initialization and
103-
decisions made during the usage analytics process, e.g. if the user has analytics disabled.
104-
105-
Using `DEBUG=ng:analytics:command` will show the decisions made by the command runner.
106-
107-
Using `DEBUG=ng:analytics:log` will show what we actually send to GA.
96+
## Debugging
10897

109-
See [the `debug` NPM library](https://www.npmjs.com/package/debug) for more information.
98+
Using `NG_DEBUG=1` will enable Google Analytics debug mode, To view the debug events, in Google Analytics go to `Configure > DebugView`.
11099

111-
# Disabling Usage Analytics
100+
## Disabling Usage Analytics
112101

113102
There are 2 ways of disabling usage analytics:
114103

115-
1. using `ng analytics off --global` (or changing the global configuration file yourself). This is the same
104+
1. using `ng analytics disable --global` (or changing the global configuration file yourself). This is the same
116105
as answering "No" to the prompt.
117106
1. There is an `NG_CLI_ANALYTICS` environment variable that overrides the global configuration.
118107
That flag is a string that represents the User ID. If the string `"false"` is used it will

goldens/circular-deps/packages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@
22
[
33
"packages/angular_devkit/build_angular/src/utils/bundle-calculator.ts",
44
"packages/angular_devkit/build_angular/src/webpack/utils/stats.ts"
5+
],
6+
[
7+
"packages/angular/cli/src/analytics/analytics-collector.ts",
8+
"packages/angular/cli/src/command-builder/command-module.ts"
9+
],
10+
[
11+
"packages/angular/cli/src/analytics/analytics.ts",
12+
"packages/angular/cli/src/command-builder/command-module.ts"
513
]
614
]

packages/angular/cli/lib/config/workspace-schema.json

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,6 @@
7474
"type": ["boolean", "string"],
7575
"description": "Share pseudonymous usage data with the Angular Team at Google."
7676
},
77-
"analyticsSharing": {
78-
"type": "object",
79-
"properties": {
80-
"tracking": {
81-
"description": "Analytics sharing info tracking ID.",
82-
"type": "string",
83-
"pattern": "^(GA|UA)?-\\d+-\\d+$"
84-
},
85-
"uuid": {
86-
"description": "Analytics sharing info universally unique identifier.",
87-
"type": "string",
88-
"format": "uuid"
89-
}
90-
},
91-
"additionalProperties": false
92-
},
9377
"cache": {
9478
"description": "Control disk cache.",
9579
"type": "object",
@@ -149,22 +133,6 @@
149133
"type": ["boolean", "string"],
150134
"description": "Share pseudonymous usage data with the Angular Team at Google."
151135
},
152-
"analyticsSharing": {
153-
"type": "object",
154-
"properties": {
155-
"tracking": {
156-
"description": "Analytics sharing info tracking ID.",
157-
"type": "string",
158-
"pattern": "^(GA|UA)?-\\d+-\\d+$"
159-
},
160-
"uuid": {
161-
"description": "Analytics sharing info universally unique identifier.",
162-
"type": "string",
163-
"format": "uuid"
164-
}
165-
},
166-
"additionalProperties": false
167-
},
168136
"completion": {
169137
"type": "object",
170138
"description": "Angular CLI completion settings.",

0 commit comments

Comments
 (0)