mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 11:44:05 +08:00
refactor(@angular/cli): move analytics constants to devkit core
They need to be shared with builders and schematics.
This commit is contained in:
parent
bf52b26219
commit
e9ee58a89e
@ -5,7 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import { tags, terminal } from '@angular-devkit/core';
|
||||
import { analytics, tags, terminal } from '@angular-devkit/core';
|
||||
import { ModuleNotFoundException, resolve } from '@angular-devkit/core/node';
|
||||
import { NodePackageDoesNotSupportSchematics } from '@angular-devkit/schematics/tools';
|
||||
import { dirname } from 'path';
|
||||
@ -150,7 +150,7 @@ export class AddCommand extends SchematicCommand<AddCommandSchema> {
|
||||
|
||||
// Add the collection if it's safe listed.
|
||||
if (collection && isPackageNameSafeForAnalytics(collection)) {
|
||||
dimensions[AnalyticsDimensions.NgAddCollection] = collection;
|
||||
dimensions[analytics.NgCliAnalyticsDimensions.NgAddCollection] = collection;
|
||||
} else {
|
||||
delete dimensions[AnalyticsDimensions.NgAddCollection];
|
||||
}
|
||||
|
@ -5,8 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import { AnalyticsDimensions } from '../models/analytics';
|
||||
import { analytics } from '@angular-devkit/core';
|
||||
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';
|
||||
import { Arguments } from '../models/interface';
|
||||
import { Version } from '../upgrade/version';
|
||||
@ -29,7 +28,7 @@ export class BuildCommand extends ArchitectCommand<BuildCommandSchema> {
|
||||
metrics: (boolean | number | string)[] = [],
|
||||
): Promise<void> {
|
||||
if (options.buildEventLog !== undefined) {
|
||||
dimensions[AnalyticsDimensions.NgBuildBuildEventLog] = true;
|
||||
dimensions[analytics.NgCliAnalyticsDimensions.NgBuildBuildEventLog] = true;
|
||||
}
|
||||
|
||||
return super.reportAnalytics(paths, options, dimensions, metrics);
|
||||
|
@ -5,8 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import { AnalyticsDimensions } from '../models/analytics';
|
||||
import { analytics } from '@angular-devkit/core';
|
||||
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';
|
||||
import { Arguments } from '../models/interface';
|
||||
import { Version } from '../upgrade/version';
|
||||
@ -34,7 +33,7 @@ export class ServeCommand extends ArchitectCommand<ServeCommandSchema> {
|
||||
metrics: (boolean | number | string)[] = [],
|
||||
): Promise<void> {
|
||||
if (options.buildEventLog !== undefined) {
|
||||
dimensions[AnalyticsDimensions.NgBuildBuildEventLog] = true;
|
||||
dimensions[analytics.NgCliAnalyticsDimensions.NgBuildBuildEventLog] = true;
|
||||
}
|
||||
|
||||
return super.reportAnalytics(paths, options, dimensions, metrics);
|
||||
|
@ -241,6 +241,7 @@ function _buildUserAgentString() {
|
||||
export class UniversalAnalytics implements analytics.Analytics {
|
||||
private _ua: ua.Visitor;
|
||||
private _dirty = false;
|
||||
private _metrics: (string | number)[] = [];
|
||||
|
||||
/**
|
||||
* @param trackingId The Google Analytics ID.
|
||||
@ -266,10 +267,10 @@ export class UniversalAnalytics implements analytics.Analytics {
|
||||
this._ua.set('aid', _getNodeVersion());
|
||||
|
||||
// We set custom metrics for values we care about.
|
||||
this._ua.set('cm1', _getCpuCount());
|
||||
this._ua.set('cm2', _getCpuSpeed());
|
||||
this._ua.set('cm3', _getRamSize());
|
||||
this._ua.set('cm4', _getNumericNodeVersion());
|
||||
this._metrics[analytics.NgCliAnalyticsMetrics.CpuCount] = _getCpuCount();
|
||||
this._metrics[analytics.NgCliAnalyticsMetrics.CpuSpeed] = _getCpuSpeed();
|
||||
this._metrics[analytics.NgCliAnalyticsMetrics.RamInMegabytes] = _getRamSize();
|
||||
this._metrics[analytics.NgCliAnalyticsMetrics.NodeVersion] = _getNumericNodeVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -278,6 +279,7 @@ export class UniversalAnalytics implements analytics.Analytics {
|
||||
*/
|
||||
private _customVariables(options: analytics.CustomDimensionsAndMetricsOptions) {
|
||||
const additionals: { [key: string]: boolean | number | string } = {};
|
||||
this._metrics.forEach((v, i) => additionals['cm' + i] = v);
|
||||
(options.dimensions || []).forEach((v, i) => additionals['cd' + i] = v);
|
||||
(options.metrics || []).forEach((v, i) => additionals['cm' + i] = v);
|
||||
|
||||
|
@ -10,3 +10,32 @@ export * from './forwarder';
|
||||
export * from './logging';
|
||||
export * from './multi';
|
||||
export * from './noop';
|
||||
|
||||
|
||||
/**
|
||||
* MAKE SURE TO KEEP THIS IN SYNC WITH THE TABLE AND CONTENT IN `/docs/design/analytics.md`.
|
||||
* WE LIST THOSE DIMENSIONS (AND MORE).
|
||||
*/
|
||||
export enum NgCliAnalyticsDimensions {
|
||||
NgAddCollection = 6,
|
||||
NgBuildBuildEventLog = 7,
|
||||
BuildErrors = 20,
|
||||
}
|
||||
|
||||
export enum NgCliAnalyticsMetrics {
|
||||
CpuCount = 1,
|
||||
CpuSpeed = 2,
|
||||
RamInMegabytes = 3,
|
||||
NodeVersion = 4,
|
||||
BuildTime = 5,
|
||||
NgOnInitCount = 6,
|
||||
InitialChunkSize = 7,
|
||||
TotalChunkCount = 8,
|
||||
TotalChunkSize = 9,
|
||||
LazyChunkCount = 10,
|
||||
LazyChunkSize = 11,
|
||||
AssetCount = 12,
|
||||
AssetSize = 13,
|
||||
PolyfillSize = 12,
|
||||
CssSize = 13,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user