{"version":3,"file":"angulartics2-ga.js","sources":["ng://angulartics2/ga/ga.ts","ng://angulartics2/ga/angulartics2-ga.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\nimport {\n Angulartics2,\n GoogleAnalyticsSettings,\n UserTimings,\n} from 'angulartics2';\n\n\ndeclare var _gaq: GoogleAnalyticsCode;\ndeclare var ga: UniversalAnalytics.ga;\ndeclare var location: any;\n\nexport class GoogleAnalyticsDefaults implements GoogleAnalyticsSettings {\n additionalAccountNames = [];\n userId = null;\n transport = '';\n anonymizeIp = false;\n}\n\n@Injectable({ providedIn: 'root' })\nexport class Angulartics2GoogleAnalytics {\n dimensionsAndMetrics = [];\n settings: Partial;\n\n constructor(private angulartics2: Angulartics2) {\n const defaults = new GoogleAnalyticsDefaults();\n // Set the default settings for this module\n this.angulartics2.settings.ga = {\n ...defaults,\n ...this.angulartics2.settings.ga,\n };\n this.settings = this.angulartics2.settings.ga;\n this.angulartics2.setUsername.subscribe((x: string) => this.setUsername(x));\n this.angulartics2.setUserProperties.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.angulartics2.userTimings\n .pipe(this.angulartics2.filterDeveloperMode())\n .subscribe(x => this.userTimings(x));\n }\n\n pageTrack(path: string) {\n if (typeof _gaq !== 'undefined' && _gaq) {\n _gaq.push(['_trackPageview', path]);\n for (const accountName of this.angulartics2.settings.ga.additionalAccountNames) {\n _gaq.push([accountName + '._trackPageview', path]);\n }\n }\n if (typeof ga !== 'undefined' && ga) {\n if (this.angulartics2.settings.ga.userId) {\n ga('set', '&uid', this.angulartics2.settings.ga.userId);\n for (const accountName of this.angulartics2.settings.ga.additionalAccountNames) {\n ga(accountName + '.set', '&uid', this.angulartics2.settings.ga.userId);\n }\n }\n if (this.angulartics2.settings.ga.anonymizeIp) {\n ga('set', 'anonymizeIp', true);\n for (const accountName of this.angulartics2.settings.ga.additionalAccountNames) {\n ga(accountName + '.set', 'anonymizeIp', true);\n }\n }\n ga('send', 'pageview', path);\n for (const accountName of this.angulartics2.settings.ga.additionalAccountNames) {\n ga(accountName + '.send', 'pageview', path);\n }\n }\n }\n\n /**\n * Track Event in GA\n *\n * @param action Associated with the event\n * @param properties Comprised of:\n * - category (string) and optional\n * - label (string)\n * - value (integer)\n * - noninteraction (boolean)\n *\n * @link https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide#SettingUpEventTracking\n * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/events\n */\n eventTrack(action: string, properties: any) {\n // Google Analytics requires an Event Category\n if (!properties || !properties.category) {\n properties = properties || {};\n properties.category = 'Event';\n }\n // GA requires that eventValue be an integer, see:\n // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#eventValue\n // https://github.com/luisfarzati/angulartics/issues/81\n if (properties.value) {\n const parsed = parseInt(properties.value, 10);\n properties.value = isNaN(parsed) ? 0 : parsed;\n }\n\n if (typeof ga !== 'undefined') {\n const eventOptions = {\n eventCategory: properties.category,\n eventAction: action,\n eventLabel: properties.label,\n eventValue: properties.value,\n nonInteraction: properties.noninteraction,\n page: properties.page || location.hash.substring(1) || location.pathname,\n userId: this.angulartics2.settings.ga.userId,\n hitCallback: properties.hitCallback,\n };\n\n // add custom dimensions and metrics\n this.setDimensionsAndMetrics(properties);\n if (this.angulartics2.settings.ga.transport) {\n ga('send', 'event', eventOptions, {\n transport: this.angulartics2.settings.ga.transport,\n });\n } else {\n ga('send', 'event', eventOptions);\n }\n\n for (const accountName of this.angulartics2.settings.ga.additionalAccountNames) {\n ga(accountName + '.send', 'event', eventOptions);\n }\n } else if (typeof _gaq !== 'undefined') {\n _gaq.push([\n '_trackEvent',\n properties.category,\n action,\n properties.label,\n properties.value,\n properties.noninteraction,\n ]);\n }\n }\n\n /**\n * Exception Track Event in GA\n *\n * @param properties Comprised of the optional fields:\n * - fatal (string)\n * - description (string)\n *\n * @https://developers.google.com/analytics/devguides/collection/analyticsjs/exceptions\n *\n * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/events\n */\n exceptionTrack(properties: any) {\n if (properties.fatal === undefined) {\n console.log('No \"fatal\" provided, sending with fatal=true');\n properties.fatal = true;\n }\n\n properties.exDescription = properties.description;\n\n const eventOptions = {\n exFatal: properties.fatal,\n exDescription: properties.description,\n };\n\n ga('send', 'exception', eventOptions);\n for (const accountName of this.angulartics2.settings.ga.additionalAccountNames) {\n ga(accountName + '.send', 'exception', eventOptions);\n }\n }\n\n /**\n * User Timings Event in GA\n *\n * @param properties Comprised of the mandatory fields:\n * - timingCategory (string)\n * - timingVar (string)\n * - timingValue (number)\n * Properties can also have the optional fields:\n * - timingLabel (string)\n *\n * @link https://developers.google.com/analytics/devguides/collection/analyticsjs/user-timings\n */\n userTimings(properties: UserTimings) {\n if (\n !properties ||\n !properties.timingCategory ||\n !properties.timingVar ||\n !properties.timingValue\n ) {\n console.error(\n 'Properties timingCategory, timingVar, and timingValue are required to be set.',\n );\n return;\n }\n\n if (typeof ga !== 'undefined') {\n ga('send', 'timing', properties);\n for (const accountName of this.angulartics2.settings.ga.additionalAccountNames) {\n ga(accountName + '.send', 'timing', properties);\n }\n }\n }\n\n setUsername(userId: string) {\n this.angulartics2.settings.ga.userId = userId;\n if (typeof ga === 'undefined') {\n return;\n }\n ga('set', 'userId', userId);\n }\n\n setUserProperties(properties: any) {\n this.setDimensionsAndMetrics(properties);\n }\n\n private setDimensionsAndMetrics(properties: any) {\n if (typeof ga === 'undefined') {\n return;\n }\n // clean previously used dimensions and metrics that will not be overriden\n this.dimensionsAndMetrics.forEach(elem => {\n if (!properties.hasOwnProperty(elem)) {\n ga('set', elem, undefined);\n\n this.angulartics2.settings.ga.additionalAccountNames.forEach(\n (accountName: string) => {\n ga(`${accountName}.set`, elem, undefined);\n },\n );\n }\n });\n this.dimensionsAndMetrics = [];\n\n // add custom dimensions and metrics\n Object.keys(properties).forEach(key => {\n if (\n key.lastIndexOf('dimension', 0) === 0 ||\n key.lastIndexOf('metric', 0) === 0\n ) {\n ga('set', key, properties[key]);\n\n this.angulartics2.settings.ga.additionalAccountNames.forEach(\n (accountName: string) => {\n ga(`${accountName}.set`, key, properties[key]);\n },\n );\n this.dimensionsAndMetrics.push(key);\n }\n });\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './ga';\n"],"names":[],"mappings":";;;;MAaa,uBAAuB;IAApC;QACE,2BAAsB,GAAG,EAAE,CAAC;QAC5B,WAAM,GAAG,IAAI,CAAC;QACd,cAAS,GAAG,EAAE,CAAC;QACf,gBAAW,GAAG,KAAK,CAAC;KACrB;CAAA;AAGD,IAAa,2BAA2B,GAAxC,MAAa,2BAA2B;IAItC,YAAoB,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;QAH9C,yBAAoB,GAAG,EAAE,CAAC;QAIxB,MAAM,QAAQ,GAAG,IAAI,uBAAuB,EAAE,CAAC;;QAE/C,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,qBACxB,QAAQ,EACR,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CACjC,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9C,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAS,KAAK,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5E,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;KAC/E;IAED,aAAa;QACX,IAAI,CAAC,YA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