diff --git a/lib/constants.ts b/lib/constants.ts index 1ce1a04016..877328afd0 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -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 = "__"; diff --git a/lib/controllers/prepare-controller.ts b/lib/controllers/prepare-controller.ts index eefdef791c..fe0ff9460a 100644 --- a/lib/controllers/prepare-controller.ts +++ b/lib/controllers/prepare-controller.ts @@ -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; @@ -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 { const projectData = this.$projectDataService.getProjectData(prepareData.projectDir); + await this.trackRuntimeVersion(prepareData.platform, projectData); await this.$pluginsService.ensureAllDependenciesAreInstalled(projectData); return this.prepareCore(prepareData, projectData); @@ -199,5 +200,24 @@ export class PrepareController extends EventEmitter { this.persistedData.push(filesChangeEventData); } } + + @cache() + private async trackRuntimeVersion(platform: string, projectData: IProjectData): Promise { + 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); diff --git a/lib/services/platform/add-platform-service.ts b/lib/services/platform/add-platform-service.ts index 9185127290..4f795e3076 100644 --- a/lib/services/platform/add-platform-service.ts +++ b/lib/services/platform/add-platform-service.ts @@ -1,6 +1,6 @@ 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 { @@ -8,7 +8,8 @@ export class AddPlatformService implements IAddPlatformService { 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 { @@ -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); @@ -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 { + await this.$analyticsService.trackEventActionInGoogleAnalytics({ + action: TrackActionNames.AddPlatform, + additionalData: `${platformData.platformNameLowerCase}${AnalyticsEventLabelDelimiter}${frameworkVersion}` + }); + } } $injector.register("addPlatformService", AddPlatformService); diff --git a/test/controllers/add-platform-controller.ts b/test/controllers/add-platform-controller.ts index 4da557ea4c..2af133929d 100644 --- a/test/controllers/add-platform-controller.ts +++ b/test/controllers/add-platform-controller.ts @@ -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 => { extractedPackageFromPacote = name; } diff --git a/test/controllers/prepare-controller.ts b/test/controllers/prepare-controller.ts index c8376c6f16..741da72bdb 100644 --- a/test/controllers/prepare-controller.ts +++ b/test/controllers/prepare-controller.ts @@ -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); diff --git a/test/services/platform/add-platform-service.ts b/test/services/platform/add-platform-service.ts index 8a2dcc9810..6d4945f7ba 100644 --- a/test/services/platform/add-platform-service.ts +++ b/test/services/platform/add-platform-service.ts @@ -19,6 +19,9 @@ function createTestInjector() { } }); injector.register("addPlatformService", AddPlatformService); + injector.register("analyticsService", { + trackEventActionInGoogleAnalytics: () => ({}) + }); const fs = injector.resolve("fs"); fs.exists = () => false;