{"version":3,"file":"angulartics2-gtm.js","sources":["ng://angulartics2/gtm/gtm.ts","ng://angulartics2/gtm/angulartics2-gtm.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\nimport { Angulartics2, GoogleTagManagerSettings } from 'angulartics2';\n\ndeclare var dataLayer: any;\n\nexport class GoogleTagManagerDefaults implements GoogleTagManagerSettings {\n userId = null;\n}\n\n@Injectable({ providedIn: 'root' })\nexport class Angulartics2GoogleTagManager {\n\n constructor(\n protected angulartics2: Angulartics2,\n ) {\n // The dataLayer needs to be initialized\n if (typeof dataLayer !== 'undefined' && dataLayer) {\n dataLayer = (window as any).dataLayer = (window as any).dataLayer || [];\n }\n const defaults = new GoogleTagManagerDefaults();\n // Set the default settings for this module\n this.angulartics2.settings.gtm = { ...defaults, ...this.angulartics2.settings.gtm };\n this.angulartics2.setUsername\n .subscribe((x: string) => this.setUsername(x));\n }\n\n startTracking() {\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: any) => this.exceptionTrack(x));\n }\n\n pageTrack(path: string) {\n this.pushLayer({\n event: 'Page View',\n 'content-name': path,\n userId: this.angulartics2.settings.gtm.userId\n });\n }\n\n /**\n * Send Data Layer\n *\n * @layer data layer object\n */\n pushLayer(layer: any) {\n if (typeof dataLayer !== 'undefined' && dataLayer) {\n dataLayer.push(layer);\n }\n }\n\n /**\n * Send interactions to the dataLayer, i.e. for event tracking in Google Analytics\n *\n * @param action associated with the event\n */\n eventTrack(action: string, properties: any) {\n // TODO: make interface\n // @param {string} properties.category\n // @param {string} [properties.label]\n // @param {number} [properties.value]\n // @param {boolean} [properties.noninteraction]\n // Set a default GTM category\n properties = properties || {};\n\n this.pushLayer({\n event: properties.event || 'interaction',\n target: properties.category || 'Event',\n action,\n label: properties.label,\n value: properties.value,\n interactionType: properties.noninteraction,\n userId: this.angulartics2.settings.gtm.userId,\n ...properties.gtmCustom\n });\n }\n\n /**\n * Exception Track Event in GTM\n *\n */\n exceptionTrack(properties: any) {\n // TODO: make interface\n // @param {Object} properties\n // @param {string} properties.appId\n // @param {string} properties.appName\n // @param {string} properties.appVersion\n // @param {string} [properties.description]\n // @param {boolean} [properties.fatal]\n if (! properties || ! properties.appId || ! properties.appName || ! properties.appVersion) {\n console.error('Must be setted appId, appName and appVersion.');\n return;\n }\n\n if (properties.fatal === undefined) {\n console.log('No \"fatal\" provided, sending with fatal=true');\n properties.exFatal = true;\n }\n\n properties.exDescription = properties.event ? properties.event.stack : properties.description;\n\n this.eventTrack(`Exception thrown for ${properties.appName} <${properties.appId}@${properties.appVersion}>`, {\n category: 'Exception',\n label: properties.exDescription,\n });\n }\n\n /**\n * Set userId for use with Universal Analytics User ID feature\n *\n * @param userId used to identify user cross-device in Google Analytics\n */\n setUsername(userId: string) {\n this.angulartics2.settings.gtm.userId = userId;\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './gtm';\n"],"names":[],"mappings":";;;;;IAMA;QACE,WAAM,GAAG,IAAI,CAAC;KACf;IAAD,+BAAC;CAAA,IAAA;;IAKC,sCACY,YAA0B;QADtC,iBAYC;QAXW,iBAAY,GAAZ,YAAY,CAAc;;QAGpC,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,EAAE;YACjD,SAAS,GAAI,MAAc,CAAC,SAAS,GAAI,MAAc,CAAC,SAAS,IAAI,EAAE,CAAC;SACzE;QACD,IAAM,QAAQ,GAAG,IAAI,wBAAwB,EAAE,CAAC;;QAEhD,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,gBAAQ,QAAQ,EAAK,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAE,CAAC;QACpF,IAAI,CAAC,YAAY,CAAC,WA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