Skip to content

Commit cf86f06

Browse files
hanslvikerman
authored andcommitted
feat(@angular/cli): move non-stable version analytics to own property
And refactor it to be put magic strings in a single place.
1 parent 51c30e5 commit cf86f06

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

packages/angular/cli/models/analytics.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@ const analyticsLogDebug = debug('ng:analytics:log'); // Actual logs of events.
2222

2323
const BYTES_PER_MEGABYTES = 1024 * 1024;
2424

25+
let _defaultAngularCliPropertyCache: string;
26+
export const AnalyticsProperties = {
27+
AngularCliProd: 'UA-8594346-29',
28+
AngularCliStaging: 'UA-8594346-32',
29+
get AngularCliDefault(): string {
30+
if (_defaultAngularCliPropertyCache) {
31+
return _defaultAngularCliPropertyCache;
32+
}
33+
34+
const v = require('../package.json').version;
35+
36+
// The logic is if it's a full version then we should use the prod GA property.
37+
if (/^\d+\.\d+\.\d+$/.test(v) && v !== '0.0.0') {
38+
_defaultAngularCliPropertyCache = AnalyticsProperties.AngularCliProd;
39+
} else {
40+
_defaultAngularCliPropertyCache = AnalyticsProperties.AngularCliStaging;
41+
}
42+
43+
return _defaultAngularCliPropertyCache;
44+
},
45+
};
46+
2547
/**
2648
* This is the ultimate safelist for checking if a package name is safe to report to analytics.
2749
*/
@@ -467,7 +489,7 @@ export function hasGlobalAnalyticsConfiguration(): boolean {
467489
*/
468490
export function getGlobalAnalytics(): UniversalAnalytics | undefined {
469491
analyticsDebug('getGlobalAnalytics');
470-
const propertyId = 'UA-8594346-29';
492+
const propertyId = AnalyticsProperties.AngularCliDefault;
471493

472494
if ('NG_CLI_ANALYTICS' in process.env) {
473495
if (process.env['NG_CLI_ANALYTICS'] == 'false' || process.env['NG_CLI_ANALYTICS'] == '') {

0 commit comments

Comments
 (0)