{"version":3,"file":"angulartics2-appinsights.js","sources":["ng://angulartics2/appinsights/appinsights.ts","ng://angulartics2/appinsights/angulartics2-appinsights.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { Title } from '@angular/platform-browser';\nimport {\n NavigationEnd,\n NavigationError,\n NavigationStart,\n Router,\n} from '@angular/router';\nimport { filter } from 'rxjs/operators';\n\nimport { Angulartics2, AppInsightsSettings } from 'angulartics2';\n\ndeclare const appInsights: Microsoft.ApplicationInsights.IAppInsights;\n\nexport class AppInsightsDefaults implements AppInsightsSettings {\n userId = null;\n}\n\n@Injectable({ providedIn: 'root' })\nexport class Angulartics2AppInsights {\n loadStartTime: number = null;\n loadTime: number = null;\n\n metrics: { [name: string]: number } = null;\n dimensions: { [name: string]: string } = null;\n measurements: { [name: string]: number } = null;\n\n constructor(\n private angulartics2: Angulartics2,\n private title: Title,\n private router: Router,\n ) {\n if (typeof appInsights === 'undefined') {\n console.warn('appInsights not found');\n }\n\n const defaults = new AppInsightsDefaults();\n // Set the default settings for this module\n this.angulartics2.settings.appInsights = { ...defaults, ...this.angulartics2.settings.appInsights };\n this.angulartics2.setUsername\n .subscribe((x: string) => this.setUsername(x));\n this.angulartics2.setUserProperties\n .subscribe((x) => this.setUserProperties(x));\n }\n\n startTracking(): void {\n this.angulartics2.pageTrack\n .pipe(this.angulartics2.filterDeveloperMode())\n .subscribe((x) => this.pageTrack(x.path));\n this.angulartics2.eventTrack\n .pipe(this.angulartics2.filterDeveloperMode())\n .subscribe((x) => this.eventTrack(x.action, x.properties));\n this.angulartics2.exceptionTrack\n .pipe(this.angulartics2.filterDeveloperMode())\n .subscribe((x) => this.exceptionTrack(x));\n this.router.events\n .pipe(\n this.angulartics2.filterDeveloperMode(),\n filter(event => event instanceof NavigationStart),\n )\n .subscribe(event => this.startTimer());\n\n this.router.events\n .pipe(filter(event => event instanceof NavigationError || event instanceof NavigationEnd))\n .subscribe(error => this.stopTimer());\n }\n\n startTimer() {\n this.loadStartTime = Date.now();\n this.loadTime = null;\n }\n\n stopTimer() {\n this.loadTime = Date.now() - this.loadStartTime;\n this.loadStartTime = null;\n }\n\n /**\n * Page Track in Baidu Analytics\n *\n * @param path - Location 'path'\n *\n * @link https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#trackpageview\n */\n pageTrack(path: string) {\n appInsights.trackPageView(\n this.title.getTitle(),\n path,\n this.dimensions,\n this.metrics,\n this.loadTime,\n );\n }\n\n /**\n * Log a user action or other occurrence.\n *\n * @param name Name to identify this event in the portal.\n * @param properties Additional data used to filter events and metrics in the portal. Defaults to empty.\n *\n * @link https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#trackevent\n */\n eventTrack(name: string, properties: { [name: string]: string }) {\n appInsights.trackEvent(name, properties, this.measurements);\n }\n\n /**\n * Exception Track Event in GA\n *\n * @param properties - Comprised of the mandatory fields 'appId' (string), 'appName' (string) and 'appVersion' (string) and\n * optional fields 'fatal' (boolean) and 'description' (string), error\n *\n * @link https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#trackexception\n */\n exceptionTrack(properties: any) {\n const description = properties.event || properties.description || properties;\n\n appInsights.trackException(description);\n }\n\n /**\n * @link https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#setauthenticatedusercontext\n */\n setUsername(userId: string) {\n this.angulartics2.settings.appInsights.userId = userId;\n appInsights.setAuthenticatedUserContext(userId);\n }\n\n setUserProperties(properties: Partial<{ userId: string, accountId: string }>) {\n if (properties.userId) {\n this.angulartics2.settings.appInsights.userId = properties.userId;\n }\n if (properties.accountId) {\n appInsights.setAuthenticatedUserContext(\n this.angulartics2.settings.appInsights.userId,\n properties.accountId,\n );\n } else {\n appInsights.setAuthenticatedUserContext(\n this.angulartics2.settings.appInsights.userId,\n );\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './appinsights';\n"],"names":[],"mappings":";;;;;;;;IAcA;QACE,WAAM,GAAG,IAAI,CAAC;KACf;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