Skip to content

Commit 6985f90

Browse files
authored
Merge pull request #5017 from NativeScript/kddimitrov/runtime-version-tracking
feat: implement runtime version tracking
2 parents c6c4214 + 6b46010 commit 6985f90

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

lib/constants.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ export const enum TrackActionNames {
186186
AcceptTracking = "Accept Tracking",
187187
Performance = "Performance",
188188
PreviewAppData = "Preview App Data",
189-
UninstallCLI = "Uninstall CLI"
189+
UninstallCLI = "Uninstall CLI",
190+
UsingRuntimeVersion = "Using Runtime Version",
191+
AddPlatform = "Add Platform"
190192
}
191193

192194
export const AnalyticsEventLabelDelimiter = "__";

lib/controllers/prepare-controller.ts

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as choki from "chokidar";
22
import { hook } from "../common/helpers";
3-
import { performanceLog } from "../common/decorators";
3+
import { performanceLog, cache } from "../common/decorators";
44
import { EventEmitter } from "events";
55
import * as path from "path";
6-
import { PREPARE_READY_EVENT_NAME, WEBPACK_COMPILATION_COMPLETE, PACKAGE_JSON_FILE_NAME, PLATFORMS_DIR_NAME } from "../constants";
7-
6+
import { PREPARE_READY_EVENT_NAME, WEBPACK_COMPILATION_COMPLETE, PACKAGE_JSON_FILE_NAME, PLATFORMS_DIR_NAME, TrackActionNames, AnalyticsEventLabelDelimiter } from "../constants";
87
interface IPlatformWatcherData {
98
hasWebpackCompilerProcess: boolean;
109
nativeFilesWatcher: choki.FSWatcher;
@@ -27,12 +26,14 @@ export class PrepareController extends EventEmitter {
2726
private $projectChangesService: IProjectChangesService,
2827
private $projectDataService: IProjectDataService,
2928
private $webpackCompilerService: IWebpackCompilerService,
30-
private $watchIgnoreListService: IWatchIgnoreListService
29+
private $watchIgnoreListService: IWatchIgnoreListService,
30+
private $analyticsService: IAnalyticsService
3131
) { super(); }
3232

3333
public async prepare(prepareData: IPrepareData): Promise<IPrepareResultData> {
3434
const projectData = this.$projectDataService.getProjectData(prepareData.projectDir);
3535

36+
await this.trackRuntimeVersion(prepareData.platform, projectData);
3637
await this.$pluginsService.ensureAllDependenciesAreInstalled(projectData);
3738

3839
return this.prepareCore(prepareData, projectData);
@@ -199,5 +200,24 @@ export class PrepareController extends EventEmitter {
199200
this.persistedData.push(filesChangeEventData);
200201
}
201202
}
203+
204+
@cache()
205+
private async trackRuntimeVersion(platform: string, projectData: IProjectData): Promise<void> {
206+
let runtimeVersion: string = null;
207+
try {
208+
const platformData = this.$platformsDataService.getPlatformData(platform, projectData);
209+
const runtimeVersionData = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName);
210+
runtimeVersion = runtimeVersionData && runtimeVersionData.version;
211+
} catch (err) {
212+
this.$logger.trace(`Unable to get runtime version for project directory: ${projectData.projectDir} and platform ${platform}. Error is: `, err);
213+
}
214+
215+
if (runtimeVersion) {
216+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
217+
action: TrackActionNames.UsingRuntimeVersion,
218+
additionalData: `${platform.toLowerCase()}${AnalyticsEventLabelDelimiter}${runtimeVersion}`
219+
});
220+
}
221+
}
202222
}
203223
$injector.register("prepareController", PrepareController);

lib/services/platform/add-platform-service.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as path from "path";
22
import * as temp from "temp";
3-
import { PROJECT_FRAMEWORK_FOLDER_NAME } from "../../constants";
3+
import { PROJECT_FRAMEWORK_FOLDER_NAME, TrackActionNames, AnalyticsEventLabelDelimiter } from "../../constants";
44
import { performanceLog } from "../../common/decorators";
55

66
export class AddPlatformService implements IAddPlatformService {
77
constructor(
88
private $fs: IFileSystem,
99
private $pacoteService: IPacoteService,
1010
private $projectDataService: IProjectDataService,
11-
private $terminalSpinnerService: ITerminalSpinnerService
11+
private $terminalSpinnerService: ITerminalSpinnerService,
12+
private $analyticsService: IAnalyticsService
1213
) { }
1314

1415
public async addPlatformSafe(projectData: IProjectData, platformData: IPlatformData, packageToInstall: string, nativePrepare: INativePrepare): Promise<string> {
@@ -22,6 +23,7 @@ export class AddPlatformService implements IAddPlatformService {
2223
const frameworkVersion = frameworkPackageJsonContent.version;
2324

2425
await this.setPlatformVersion(platformData, projectData, frameworkVersion);
26+
await this.trackPlatformVersion(frameworkVersion, platformData);
2527

2628
if (!nativePrepare || !nativePrepare.skipNativePrepare) {
2729
await this.addNativePlatform(platformData, projectData, frameworkDirPath, frameworkVersion);
@@ -61,5 +63,12 @@ export class AddPlatformService implements IAddPlatformService {
6163
await platformData.platformProjectService.interpolateData(projectData);
6264
platformData.platformProjectService.afterCreateProject(platformData.projectRoot, projectData);
6365
}
66+
67+
private async trackPlatformVersion(frameworkVersion: string, platformData: IPlatformData): Promise<void> {
68+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
69+
action: TrackActionNames.AddPlatform,
70+
additionalData: `${platformData.platformNameLowerCase}${AnalyticsEventLabelDelimiter}${frameworkVersion}`
71+
});
72+
}
6473
}
6574
$injector.register("addPlatformService", AddPlatformService);

test/controllers/add-platform-controller.ts

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ function createInjector(data?: { latestFrameworkVersion: string }) {
1616
injector.register("platformController", PlatformController);
1717
injector.register("addPlatformService", AddPlatformService);
1818
injector.register("pacoteService", PacoteServiceStub);
19+
injector.register("analyticsService", {
20+
trackEventActionInGoogleAnalytics: () => ({})
21+
});
1922

2023
injector.register("pacoteService", {
2124
extractPackage: async (name: string): Promise<void> => { extractedPackageFromPacote = name; }

test/controllers/prepare-controller.ts

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ function createTestInjector(data: { hasNativeChanges: boolean }): IInjector {
5555
isFileInIgnoreList: () => false
5656
});
5757

58+
injector.register("analyticsService", {
59+
trackEventActionInGoogleAnalytics: () => ({})
60+
});
61+
5862
const prepareController: PrepareController = injector.resolve("prepareController");
5963
prepareController.emit = (eventName: string, eventData: any) => {
6064
emittedEventNames.push(eventName);

test/services/platform/add-platform-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ function createTestInjector() {
1919
}
2020
});
2121
injector.register("addPlatformService", AddPlatformService);
22+
injector.register("analyticsService", {
23+
trackEventActionInGoogleAnalytics: () => ({})
24+
});
2225

2326
const fs = injector.resolve("fs");
2427
fs.exists = () => false;

0 commit comments

Comments
 (0)