Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ export const enum TrackActionNames {
AcceptTracking = "Accept Tracking",
Performance = "Performance",
PreviewAppData = "Preview App Data",
UninstallCLI = "Uninstall CLI"
UninstallCLI = "Uninstall CLI",
UsingRuntimeVersion = "Using Runtime Version",
AddPlatform = "Add Platform"
}

export const AnalyticsEventLabelDelimiter = "__";
Expand Down
28 changes: 24 additions & 4 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as choki from "chokidar";
import { hook } from "../common/helpers";
import { performanceLog } from "../common/decorators";
import { performanceLog, cache } from "../common/decorators";
import { EventEmitter } from "events";
import * as path from "path";
import { PREPARE_READY_EVENT_NAME, WEBPACK_COMPILATION_COMPLETE, PACKAGE_JSON_FILE_NAME, PLATFORMS_DIR_NAME } from "../constants";

import { PREPARE_READY_EVENT_NAME, WEBPACK_COMPILATION_COMPLETE, PACKAGE_JSON_FILE_NAME, PLATFORMS_DIR_NAME, TrackActionNames, AnalyticsEventLabelDelimiter } from "../constants";
interface IPlatformWatcherData {
hasWebpackCompilerProcess: boolean;
nativeFilesWatcher: choki.FSWatcher;
Expand All @@ -27,12 +26,14 @@ export class PrepareController extends EventEmitter {
private $projectChangesService: IProjectChangesService,
private $projectDataService: IProjectDataService,
private $webpackCompilerService: IWebpackCompilerService,
private $watchIgnoreListService: IWatchIgnoreListService
private $watchIgnoreListService: IWatchIgnoreListService,
private $analyticsService: IAnalyticsService
) { super(); }

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

await this.trackRuntimeVersion(prepareData.platform, projectData);
await this.$pluginsService.ensureAllDependenciesAreInstalled(projectData);

return this.prepareCore(prepareData, projectData);
Expand Down Expand Up @@ -199,5 +200,24 @@ export class PrepareController extends EventEmitter {
this.persistedData.push(filesChangeEventData);
}
}

@cache()
private async trackRuntimeVersion(platform: string, projectData: IProjectData): Promise<void> {
let runtimeVersion: string = null;
try {
const platformData = this.$platformsDataService.getPlatformData(platform, projectData);
const runtimeVersionData = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName);
runtimeVersion = runtimeVersionData && runtimeVersionData.version;
} catch (err) {
this.$logger.trace(`Unable to get runtime version for project directory: ${projectData.projectDir} and platform ${platform}. Error is: `, err);
}

if (runtimeVersion) {
await this.$analyticsService.trackEventActionInGoogleAnalytics({
action: TrackActionNames.UsingRuntimeVersion,
additionalData: `${platform.toLowerCase()}${AnalyticsEventLabelDelimiter}${runtimeVersion}`
});
}
}
}
$injector.register("prepareController", PrepareController);
13 changes: 11 additions & 2 deletions lib/services/platform/add-platform-service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import * as path from "path";
import * as temp from "temp";
import { PROJECT_FRAMEWORK_FOLDER_NAME } from "../../constants";
import { PROJECT_FRAMEWORK_FOLDER_NAME, TrackActionNames, AnalyticsEventLabelDelimiter } from "../../constants";
import { performanceLog } from "../../common/decorators";

export class AddPlatformService implements IAddPlatformService {
constructor(
private $fs: IFileSystem,
private $pacoteService: IPacoteService,
private $projectDataService: IProjectDataService,
private $terminalSpinnerService: ITerminalSpinnerService
private $terminalSpinnerService: ITerminalSpinnerService,
private $analyticsService: IAnalyticsService
) { }

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

await this.setPlatformVersion(platformData, projectData, frameworkVersion);
await this.trackPlatformVersion(frameworkVersion, platformData);

if (!nativePrepare || !nativePrepare.skipNativePrepare) {
await this.addNativePlatform(platformData, projectData, frameworkDirPath, frameworkVersion);
Expand Down Expand Up @@ -61,5 +63,12 @@ export class AddPlatformService implements IAddPlatformService {
await platformData.platformProjectService.interpolateData(projectData);
platformData.platformProjectService.afterCreateProject(platformData.projectRoot, projectData);
}

private async trackPlatformVersion(frameworkVersion: string, platformData: IPlatformData): Promise<void> {
await this.$analyticsService.trackEventActionInGoogleAnalytics({
action: TrackActionNames.AddPlatform,
additionalData: `${platformData.platformNameLowerCase}${AnalyticsEventLabelDelimiter}${frameworkVersion}`
});
}
}
$injector.register("addPlatformService", AddPlatformService);
3 changes: 3 additions & 0 deletions test/controllers/add-platform-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function createInjector(data?: { latestFrameworkVersion: string }) {
injector.register("platformController", PlatformController);
injector.register("addPlatformService", AddPlatformService);
injector.register("pacoteService", PacoteServiceStub);
injector.register("analyticsService", {
trackEventActionInGoogleAnalytics: () => ({})
});

injector.register("pacoteService", {
extractPackage: async (name: string): Promise<void> => { extractedPackageFromPacote = name; }
Expand Down
4 changes: 4 additions & 0 deletions test/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ function createTestInjector(data: { hasNativeChanges: boolean }): IInjector {
isFileInIgnoreList: () => false
});

injector.register("analyticsService", {
trackEventActionInGoogleAnalytics: () => ({})
});

const prepareController: PrepareController = injector.resolve("prepareController");
prepareController.emit = (eventName: string, eventData: any) => {
emittedEventNames.push(eventName);
Expand Down
3 changes: 3 additions & 0 deletions test/services/platform/add-platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function createTestInjector() {
}
});
injector.register("addPlatformService", AddPlatformService);
injector.register("analyticsService", {
trackEventActionInGoogleAnalytics: () => ({})
});

const fs = injector.resolve("fs");
fs.exists = () => false;
Expand Down