Skip to content

Commit f62d0bc

Browse files
committed
Implement Telerik Analytics tracking
1 parent 8dc5d0f commit f62d0bc

7 files changed

+144
-16
lines changed

package.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"dependencies": {
2828
"node-ipc": "^7.0.0",
2929
"source-map": "^0.5.3",
30+
"xmlhttprequest": "https://github.com/telerik/node-XMLHttpRequest/tarball/master",
3031
"universal-analytics": "^0.3.11",
3132
"vscode-debugadapter": "^1.7.0",
3233
"vscode-debugprotocol": "^1.7.0"
@@ -43,7 +44,7 @@
4344
"scripts": {
4445
"postinstall": "node ./node_modules/vscode/bin/install && cd src && typings install",
4546
"clean": "git clean -fdx",
46-
"build": "tsc -p ./src",
47+
"build": "tsc -p ./src && cp ./src/services/analytics/EqatecMonitor.min.js ./out/services/analytics/EqatecMonitor.min.js",
4748
"package": "vsce package",
4849
"launch-as-server": "node --nolazy ./out/webkit/webKitDebug.js --server=4712",
4950
"test-mac": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/mac.json ./out/tests",
@@ -55,6 +56,17 @@
5556
"*"
5657
],
5758
"contributes": {
59+
"configuration": {
60+
"type": "object",
61+
"title": "NativeScript Extension Configurations",
62+
"properties": {
63+
"nativescript.analytics.enabled": {
64+
"type": "boolean",
65+
"default": true,
66+
"description": "Enables the extension tracking."
67+
}
68+
}
69+
},
5870
"commands": [
5971
{
6072
"command": "nativescript.runIos",

src/services/analytics/AnalyticsBaseInfo.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ export interface AnalyticsBaseInfo {
99
operatingSystem: OperatingSystem,
1010
cliVersion: string,
1111
extensionVersion: string,
12-
userId: string,
13-
hostname: string
12+
userId: string
1413
}

src/services/analytics/AnalyticsService.ts

+28-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as os from 'os';
2+
import * as vscode from 'vscode';
23
import { Version } from '../../common/Version';
34
import { GUAService } from './GUAService';
5+
import { TelerikAnalyticsService } from './TelerikAnalyticsService';
46
import { AnalyticsBaseInfo, OperatingSystem } from './AnalyticsBaseInfo';
57
import { ExtensionVersionInfo } from '../ExtensionVersionInfo';
68
import * as ns from '../NsCliService';
@@ -10,6 +12,8 @@ export class AnalyticsService {
1012

1113
private _baseInfo: AnalyticsBaseInfo;
1214
private _gua: GUAService;
15+
private _ta: TelerikAnalyticsService;
16+
private _analyticsEnabled: boolean;
1317

1418
public static getInstance(): AnalyticsService {
1519
if (!this._instance) {
@@ -34,6 +38,7 @@ export class AnalyticsService {
3438
}
3539

3640
constructor() {
41+
this._analyticsEnabled = vscode.workspace.getConfiguration('nativescript').get('analytics.enabled') as boolean;
3742
let operatingSystem = OperatingSystem.Other;
3843
switch(process.platform) {
3944
case 'win32': { operatingSystem = OperatingSystem.Windows; break; }
@@ -46,22 +51,36 @@ export class AnalyticsService {
4651
cliVersion: Version.stringify(ns.CliVersionInfo.getInstalledCliVersion()),
4752
extensionVersion: Version.stringify(ExtensionVersionInfo.getExtensionVersion()),
4853
operatingSystem: operatingSystem,
49-
userId: AnalyticsService.generateMachineId(),
50-
hostname: 'ns-vs-extension.org'
54+
userId: AnalyticsService.generateMachineId()
5155
};
5256

53-
this._gua = new GUAService('UA-111455-29', this._baseInfo);
57+
if(this._analyticsEnabled) {
58+
this._gua = new GUAService('UA-111455-29', this._baseInfo);
59+
this._ta = new TelerikAnalyticsService('b8b2e51f188f43e9b0dfb899f7b71cc6', this._baseInfo);
60+
}
5461
}
5562

5663
public launchDebugger(request: string, platform: string, emulator: boolean): Promise<any> {
57-
try {
58-
return this._gua.launchDebugger(request, platform, emulator);
59-
} catch(e) {}
64+
if(this._analyticsEnabled) {
65+
try {
66+
return Promise.all([
67+
this._gua.launchDebugger(request, platform, emulator),
68+
this._ta.launchDebugger(request, platform, emulator)
69+
]);
70+
} catch(e) {}
71+
}
72+
return Promise.resolve();
6073
}
6174

6275
public runRunCommand(platform: string, emulator: boolean): Promise<any> {
63-
try {
64-
return this._gua.runRunCommand(platform, emulator);
65-
} catch(e) {}
76+
if(this._analyticsEnabled) {
77+
try {
78+
return Promise.all([
79+
this._gua.runRunCommand(platform, emulator),
80+
this._ta.runRunCommand(platform, emulator)
81+
]);
82+
} catch(e) {}
83+
}
84+
return Promise.resolve();
6685
}
6786
}

src/services/analytics/EqatecMonitor.min.js

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/services/analytics/GUAService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export class GUAService {
99
private _getBasePayload: () => any;
1010

1111
constructor(trackingId: string, baseInfo: AnalyticsBaseInfo) {
12-
this._visitor = ua(trackingId);
12+
this._visitor = ua(trackingId, baseInfo.userId, { requestOptions: {}, strictCidFormat: false });
1313
this._getBasePayload = () => {
1414
return {
1515
uid: baseInfo.userId,
16-
dh: baseInfo.hostname,
16+
dh: 'ns-vs-extension.org',
1717
cd5: baseInfo.cliVersion,
1818
cd6: OperatingSystem[baseInfo.operatingSystem],
1919
cd7: baseInfo.extensionVersion

0 commit comments

Comments
 (0)