Track in MS ApplicationInsight.
This commit is contained in:
Родитель
df311c4fc6
Коммит
3ded04f1a2
|
@ -1220,6 +1220,135 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"@microsoft/applicationinsights-analytics-js": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/applicationinsights-analytics-js/-/applicationinsights-analytics-js-2.5.4.tgz",
|
||||
"integrity": "sha512-Eda0bcThQJA/zNVzmU3+Vo9WJT/55LzUxpEATOCB6BbN1uGGUp3hGOdlV/hRl652TPutXII/gvhg8Z4uqq+VsA==",
|
||||
"requires": {
|
||||
"@microsoft/applicationinsights-common": "2.5.4",
|
||||
"@microsoft/applicationinsights-core-js": "2.5.4",
|
||||
"@microsoft/dynamicproto-js": "^0.5.2",
|
||||
"tslib": "^1.11.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz",
|
||||
"integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@microsoft/applicationinsights-channel-js": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/applicationinsights-channel-js/-/applicationinsights-channel-js-2.5.4.tgz",
|
||||
"integrity": "sha512-xDgI+7LAT5xPdxbBu/fueufH/j7p+hqfPJkkyG9BYdLa77mp+UfnP1kKjthcsdrhJiVIAbx08hmZpo72espIng==",
|
||||
"requires": {
|
||||
"@microsoft/applicationinsights-common": "2.5.4",
|
||||
"@microsoft/applicationinsights-core-js": "2.5.4",
|
||||
"tslib": "^1.11.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz",
|
||||
"integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@microsoft/applicationinsights-common": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/applicationinsights-common/-/applicationinsights-common-2.5.4.tgz",
|
||||
"integrity": "sha512-lrLwBUKqK4SZq2nCegUs/O8Ew2KPtL+JUCARoo6YdT8vSiUSxVk+XvwnMOViv27+NWsM3HpqOcjMn+C3kwULZQ==",
|
||||
"requires": {
|
||||
"@microsoft/applicationinsights-core-js": "2.5.4",
|
||||
"tslib": "^1.11.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz",
|
||||
"integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@microsoft/applicationinsights-core-js": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/applicationinsights-core-js/-/applicationinsights-core-js-2.5.4.tgz",
|
||||
"integrity": "sha512-U3spLDr99R8X7X7VH49RJhx7KhB8HZpKo7rb3ymFG6z6hB7eWQQyLyMsFnThNJI3sVqwEPCQd7dBs7viheLqjw==",
|
||||
"requires": {
|
||||
"@microsoft/dynamicproto-js": "^0.5.2",
|
||||
"tslib": "^1.11.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz",
|
||||
"integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@microsoft/applicationinsights-dependencies-js": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/applicationinsights-dependencies-js/-/applicationinsights-dependencies-js-2.5.4.tgz",
|
||||
"integrity": "sha512-C01PkF7nQSYFpHiTo4Ltz5VOJqyTaQMHk2fNLBnyxLF2VhSUlfowPhyS6mGU3miscd5sQuktrlYol7LqjiRCXw==",
|
||||
"requires": {
|
||||
"@microsoft/applicationinsights-common": "2.5.4",
|
||||
"@microsoft/applicationinsights-core-js": "2.5.4",
|
||||
"@microsoft/dynamicproto-js": "^0.5.2",
|
||||
"tslib": "^1.11.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz",
|
||||
"integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@microsoft/applicationinsights-properties-js": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/applicationinsights-properties-js/-/applicationinsights-properties-js-2.5.4.tgz",
|
||||
"integrity": "sha512-2ueiQYhMiNIf9Iua7zrUGIDBiO8zPLau1yBePqLvEQ2CewBE9ZrTbdqhzpBrUQUKFbmWlETXYsIWQNz+T2rRfw==",
|
||||
"requires": {
|
||||
"@microsoft/applicationinsights-common": "2.5.4",
|
||||
"@microsoft/applicationinsights-core-js": "2.5.4",
|
||||
"tslib": "^1.11.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz",
|
||||
"integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@microsoft/applicationinsights-web": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/applicationinsights-web/-/applicationinsights-web-2.5.4.tgz",
|
||||
"integrity": "sha512-5nBgxEDkM61E0irdi78DcEwfiLvYueyU5tQsCxovPfhbt5Ub8KzzT8cvmrh6p9Rt9DcpKP/uHD8k6OqMvdgvVg==",
|
||||
"requires": {
|
||||
"@microsoft/applicationinsights-analytics-js": "2.5.4",
|
||||
"@microsoft/applicationinsights-channel-js": "2.5.4",
|
||||
"@microsoft/applicationinsights-common": "2.5.4",
|
||||
"@microsoft/applicationinsights-core-js": "2.5.4",
|
||||
"@microsoft/applicationinsights-dependencies-js": "2.5.4",
|
||||
"@microsoft/applicationinsights-properties-js": "2.5.4",
|
||||
"@microsoft/dynamicproto-js": "^0.5.2",
|
||||
"tslib": "^1.11.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz",
|
||||
"integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@microsoft/dynamicproto-js": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/dynamicproto-js/-/dynamicproto-js-0.5.2.tgz",
|
||||
"integrity": "sha512-tGwZJLtLVK96OKl5/pHeZFgi28rnKJB2DQ0V/28SVQnv9tC/OXCNOrvvvtIZM6wp1YJwqVSFnyp46w3azDjC0Q=="
|
||||
},
|
||||
"@ngtools/webpack": {
|
||||
"version": "8.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-8.2.2.tgz",
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"@angular/platform-browser": "~8.2.0",
|
||||
"@angular/platform-browser-dynamic": "~8.2.0",
|
||||
"@angular/router": "~8.2.0",
|
||||
"@microsoft/applicationinsights-web": "^2.5.4",
|
||||
"chart.js": "^2.9.2",
|
||||
"core-js": "^3.4.1",
|
||||
"hammerjs": "^2.0.8",
|
||||
|
|
|
@ -17,7 +17,7 @@ import { RemoteCommandService } from './services/remote-command.service'
|
|||
import { MediaQueryService } from './services/media-query.service'
|
||||
import { ClusterMetricService } from './services/cluster-metric.service'
|
||||
import { MesssageService } from './services/messsage.service';
|
||||
import { TrackingService, GA_TRACK_ID } from './services/tracking.service';
|
||||
import { TrackingService, GA_TRACK_ID, AI_TRACK_ID } from './services/tracking.service';
|
||||
import { BreadcrumbComponent } from './breadcrumb/breadcrumb.component';
|
||||
import { SharedComponentsModule } from './shared-components/shared-components.module'
|
||||
|
||||
|
@ -92,6 +92,7 @@ const routes: Routes = [{
|
|||
TrackingService,
|
||||
{ provide: UPDATE_URL, useValue: environment.UPDATE_URL },
|
||||
{ provide: GA_TRACK_ID, useValue: environment.GA_TRACK_ID },
|
||||
{ provide: AI_TRACK_ID, useValue: environment.AI_TRACK_ID },
|
||||
{ provide: BASE_PATH, useValue: environment.API_BASE_PATH },
|
||||
{ provide: Configuration, useClass: ApiConfigService },
|
||||
],
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TrackingService, GA_TRACK_ID } from './tracking.service';
|
||||
import { TrackingService, GA_TRACK_ID, AI_TRACK_ID } from './tracking.service';
|
||||
import { UserService } from './user.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { ApiService } from './api.service';
|
||||
|
@ -12,6 +12,7 @@ describe('TrackingService', () => {
|
|||
{ provide: ApiService, useValue: {} },
|
||||
{ provide: UserService, useValue: { AddAuthStateChangeHandler: (x: any) => {} } },
|
||||
{ provide: GA_TRACK_ID, useValue: 'id' },
|
||||
{ provide: AI_TRACK_ID, useValue: 'id' },
|
||||
]
|
||||
}));
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Injectable, InjectionToken, Inject } from '@angular/core';
|
||||
import { UserService, AuthStateChangeHandler } from './user.service';
|
||||
import { Router, Event, NavigationEnd } from '@angular/router';
|
||||
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
|
||||
import { ApiService } from './api.service';
|
||||
import { filter } from 'rxjs/operators';
|
||||
|
||||
|
@ -8,16 +9,28 @@ declare let gtag: Function;
|
|||
|
||||
export const GA_TRACK_ID = new InjectionToken<string>('gaTrackId');
|
||||
|
||||
export const AI_TRACK_ID = new InjectionToken<string>('aiTrackId');
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TrackingService {
|
||||
private ai: ApplicationInsights;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private api: ApiService,
|
||||
private userService: UserService,
|
||||
@Inject(GA_TRACK_ID) private trackId: string,
|
||||
@Inject(GA_TRACK_ID) private gaTrackId: string,
|
||||
@Inject(AI_TRACK_ID) private aiTrackId: string,
|
||||
) {
|
||||
this.ai = new ApplicationInsights({
|
||||
config: {
|
||||
instrumentationKey: this.aiTrackId,
|
||||
//disableAjaxTracking: true,
|
||||
}
|
||||
});
|
||||
this.ai.loadAppInsights();
|
||||
this.router.events.pipe(
|
||||
filter((e: Event) => e instanceof NavigationEnd)
|
||||
).subscribe((e: NavigationEnd) => this.trackRoute());
|
||||
|
@ -27,7 +40,8 @@ export class TrackingService {
|
|||
private authHandler: AuthStateChangeHandler = (authenticated) => {
|
||||
if (authenticated && this.enabled) {
|
||||
this.api.getClusterSummary().subscribe(summary => {
|
||||
this.trackEvent('summary', `${summary.SubscriptionId}:${summary.DeploymentId}`, JSON.stringify(summary));
|
||||
this.trackGaEvent('summary', `${summary.SubscriptionId}:${summary.DeploymentId}`, JSON.stringify(summary));
|
||||
this.trackAiEvent('summary', summary);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -49,19 +63,28 @@ export class TrackingService {
|
|||
}
|
||||
|
||||
trackRoute(): void {
|
||||
if (this.trackId && this.enabled) {
|
||||
console.log(`Tracking route: ${location.href}`);
|
||||
gtag('config', this.trackId, { 'page_location': location.href });
|
||||
//NOTE: Do not change names of GA event action, category and label freely, to avoid polluting existing records.
|
||||
gtag('event', 'browse', { event_category: location.hostname, event_label: location.pathname });
|
||||
if (this.enabled) {
|
||||
if (this.gaTrackId) {
|
||||
gtag('config', this.gaTrackId, { 'page_location': location.href });
|
||||
//NOTE: Do not change names of GA event action, category and label freely, to avoid polluting existing records.
|
||||
gtag('event', 'browse', { event_category: location.hostname, event_label: location.pathname });
|
||||
}
|
||||
if (this.aiTrackId) {
|
||||
this.ai.trackPageView({ name: location.href });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trackEvent(action: string, category: string, label: string): void {
|
||||
if (this.trackId && this.enabled) {
|
||||
console.log(`Tracking event: cat: "${category}", label: "${label}"`);
|
||||
trackGaEvent(action: string, category: string, label: string): void {
|
||||
if (this.gaTrackId && this.enabled) {
|
||||
//NOTE: Do not change names of GA event action, category and label freely, to avoid polluting existing records.
|
||||
gtag('event', action, { event_category: category, event_label: label });
|
||||
}
|
||||
}
|
||||
|
||||
trackAiEvent(name: string, properties: {[key: string]: any}): void {
|
||||
if (this.aiTrackId && this.enabled) {
|
||||
this.ai.trackEvent({ name }, properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,5 +2,6 @@ export const environment = {
|
|||
production: true,
|
||||
API_BASE_PATH: '/hpc',
|
||||
GA_TRACK_ID: 'UA-160643556-1',
|
||||
AI_TRACK_ID: '15996569-847e-4561-b9af-5f255efc5949',
|
||||
UPDATE_URL: 'https://azure.github.io/hpcpack-web-portal/',
|
||||
};
|
||||
|
|
|
@ -2,5 +2,6 @@ export const environment = {
|
|||
production: false,
|
||||
API_BASE_PATH: '/hpc',
|
||||
GA_TRACK_ID: 'id',
|
||||
AI_TRACK_ID: 'id',
|
||||
UPDATE_URL: 'https://azure.github.io/hpcpack-web-portal/',
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@ export const environment = {
|
|||
production: false,
|
||||
API_BASE_PATH: 'https://hpc-32420102-2/hpc',
|
||||
GA_TRACK_ID: 'id',
|
||||
AI_TRACK_ID: 'id',
|
||||
UPDATE_URL: 'http://localhost:4000/hpcpack-web-portal/',
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче