Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): add analytics for ivy/non-ivy bu…
Browse files Browse the repository at this point in the history
…ilds

Look for `ngComponentDef` or `ngModuleDef` in the webpack analytics plugin
to report back whether the current build is built with Ivy enabled.
  • Loading branch information
vikerman committed Oct 2, 2019
1 parent 3d30b67 commit 4fe3d34
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 2 additions & 3 deletions docs/design/analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ To create a new dimension (tracking a new flag):
defined on GA.
1. Use the ID of the dimension as the `x-user-analytics` value in the `schema.json` file.
1. Add a new row to the table below in the same PR as the one adding the dimension to the code.
1. New dimensions PRs need to be approved by [bradgreen@google.com](mailto:bradgreen@google.com),
[stephenfluin@google.com](mailto:stephenfluin@google.com) and
1. New dimensions PRs need to be approved by [stephenfluin@google.com](mailto:stephenfluin@google.com) and
[iminar@google.com](mailto:iminar@google.com). **This is not negotiable.**

**DO NOT ADD `x-user-analytics` FOR VALUES THAT ARE USER IDENTIFIABLE (PII), FOR EXAMPLE A
Expand All @@ -48,7 +47,7 @@ Note: There's a limit of 20 custom dimensions.
| 5 | `Flag: --style` | `string` |
| 6 | `--collection` | `string` |
| 7 | `--buildEventLog` | `boolean` |
| 8 | `Flag: --enableIvy` | `boolean` |
| 8 | `Ivy Enabled` | `boolean` |
| 9 | `Flag: --inlineStyle` | `boolean` |
| 10 | `Flag: --inlineTemplate` | `boolean` |
| 11 | `Flag: --viewEncapsulation` | `string` |
Expand Down
1 change: 1 addition & 0 deletions etc/api/angular_devkit/core/src/_golden-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ export declare enum NgCliAnalyticsDimensions {
NodeVersion = 4,
NgAddCollection = 6,
NgBuildBuildEventLog = 7,
NgIvyEnabled = 8,
BuildErrors = 20
}

Expand Down
15 changes: 13 additions & 2 deletions packages/angular_devkit/build_angular/plugins/webpack/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function countOccurrences(source: string, match: string, wordBreak = fals
* Holder of statistics related to the build.
*/
class AnalyticsBuildStats {
public isIvy = false;
public errors: string[] = [];
public numberOfNgOnInit = 0;
public numberOfComponents = 0;
Expand Down Expand Up @@ -121,13 +122,15 @@ export class NgBuildAnalyticsPlugin {
return metrics;
}
protected _getDimensions(stats: Stats) {
const dimensions: (string | number)[] = [];
const dimensions: (string | number | boolean)[] = [];

if (this._stats.errors.length) {
// Adding commas before and after so the regex are easier to define filters.
dimensions[analytics.NgCliAnalyticsDimensions.BuildErrors] = `,${this._stats.errors.join()},`;
}

dimensions[analytics.NgCliAnalyticsDimensions.NgIvyEnabled] = this._stats.isIvy;

return dimensions;
}

Expand Down Expand Up @@ -156,7 +159,15 @@ export class NgBuildAnalyticsPlugin {
// This does not include View Engine AOT compilation, we use the ngfactory for it.
this._stats.numberOfComponents += countOccurrences(module._source.source(), ' Component({');
// For Ivy we just count ngComponentDef.
this._stats.numberOfComponents += countOccurrences(module._source.source(), 'ngComponentDef', true);
const numIvyComponents = countOccurrences(module._source.source(), 'ngComponentDef', true);
this._stats.numberOfComponents += numIvyComponents;

// Check whether this is an Ivy app so that it can reported as part of analytics.
if (!this._stats.isIvy) {
if (numIvyComponents > 0 || module._source.source().includes('ngModuleDef')) {
this._stats.isIvy = true;
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/angular_devkit/core/src/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export enum NgCliAnalyticsDimensions {
NodeVersion = 4,
NgAddCollection = 6,
NgBuildBuildEventLog = 7,
NgIvyEnabled = 8,
BuildErrors = 20,
}

Expand Down Expand Up @@ -56,6 +57,7 @@ export const NgCliAnalyticsDimensionsFlagInfo: { [name: string]: [string, string
NodeVersion: ['Node Version', 'number'],
NgAddCollection: ['--collection', 'string'],
NgBuildBuildEventLog: ['--buildEventLog', 'boolean'],
NgIvyEnabled: ['Ivy Enabled', 'boolean'],
BuildErrors: ['Build Errors (comma separated)', 'string'],
};

Expand Down

0 comments on commit 4fe3d34

Please sign in to comment.