Skip to content

Commit 106a2e8

Browse files
Expose a way to set projectApiKey for analytics (#2859)
1 parent 1cf8440 commit 106a2e8

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

PublicAPI.md

+15
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,21 @@ tns.npm.view(["nativescript"], {}).then(result => {
339339
});
340340
```
341341
342+
## analyticsService
343+
Provides a way to configure analytics.
344+
345+
### startEqatecMonitor
346+
* Definition:
347+
```TypeScript
348+
/**
349+
* Starts analytics monitor with provided key.
350+
* @param {string} projectApiKey API key with which to start analytics monitor.
351+
* @returns {Promise<void>}.
352+
*/
353+
startEqatecMonitor(projectApiKey: string): Promise<void>;
354+
```
355+
356+
342357
## debugService
343358
Provides methods for debugging applications on devices. The service is also event emitter, that raises the following events:
344359
* `connectionError` event - this event is raised when the debug operation cannot start on iOS device. The causes can be:

lib/bootstrap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $injector.require("androidDebugService", "./services/android-debug-service");
2929

3030
$injector.require("userSettingsService", "./services/user-settings-service");
3131
$injector.require("analyticsSettingsService", "./services/analytics-settings-service");
32-
$injector.require("analyticsService", "./services/analytics-service");
32+
$injector.requirePublic("analyticsService", "./services/analytics-service");
3333

3434
$injector.require("emulatorSettingsService", "./services/emulator-settings-service");
3535

lib/common

lib/services/analytics-service.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AnalyticsServiceBase } from "../common/services/analytics-service-base";
2+
import { exported } from "../common/decorators";
23

34
export class AnalyticsService extends AnalyticsServiceBase implements IAnalyticsService {
45
private static ANALYTICS_FEATURE_USAGE_TRACKING_API_KEY = "9912cff308334c6d9ad9c33f76a983e3";
@@ -14,6 +15,13 @@ export class AnalyticsService extends AnalyticsServiceBase implements IAnalytics
1415
super($logger, $options, $staticConfig, $prompter, $userSettingsService, $analyticsSettingsService, $progressIndicator, $osInfo);
1516
}
1617

18+
@exported("analyticsService")
19+
public async startEqatecMonitor(projectApiKey: string): Promise<void> {
20+
if (await this.isEnabled(this.$staticConfig.TRACK_FEATURE_USAGE_SETTING_NAME) || await this.isEnabled(this.$staticConfig.ERROR_REPORT_SETTING_NAME)) {
21+
await this.restartEqatecMonitor(projectApiKey);
22+
}
23+
}
24+
1725
protected async checkConsentCore(trackFeatureUsage: boolean): Promise<void> {
1826
await this.restartEqatecMonitor(AnalyticsService.ANALYTICS_FEATURE_USAGE_TRACKING_API_KEY);
1927
await super.checkConsentCore(trackFeatureUsage);

test/nativescript-cli-lib.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe("nativescript-cli-lib", () => {
2020
deviceLogProvider: null,
2121
npm: ["install", "uninstall", "view", "search"],
2222
extensibilityService: ["loadExtensions", "getInstalledExtensions", "installExtension", "uninstallExtension"],
23+
analyticsService: ["startEqatecMonitor"],
2324
debugService: ["debug"]
2425
};
2526

0 commit comments

Comments
 (0)