{"version":3,"file":"angulartics2-segment.js","sources":["ng://angulartics2/segment/segment.ts","ng://angulartics2/segment/angulartics2-segment.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\nimport { Angulartics2 } from 'angulartics2';\n\ndeclare var analytics: SegmentAnalytics.AnalyticsJS;\n\n@Injectable({ providedIn: 'root' })\nexport class Angulartics2Segment {\n\n constructor(\n private angulartics2: Angulartics2\n ) {\n this.angulartics2.setUserProperties\n .subscribe((x) => this.setUserProperties(x));\n this.angulartics2.setUserPropertiesOnce\n .subscribe((x) => this.setUserProperties(x));\n this.angulartics2.setAlias\n .subscribe((x) => this.setAlias(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 }\n\n /**\n * https://segment.com/docs/libraries/analytics.js/#page\n *\n * analytics.page([category], [name], [properties], [options], [callback]);\n */\n pageTrack(path: string) {\n // TODO : Support optional parameters where the parameter order and type changes their meaning\n try {\n analytics.page(path);\n } catch (e) {\n if (!(e instanceof ReferenceError)) {\n throw e;\n }\n }\n }\n\n /**\n * https://segment.com/docs/libraries/analytics.js/#track\n *\n * analytics.track(event, [properties], [options], [callback]);\n */\n eventTrack(action: string, properties: any) {\n try {\n analytics.track(action, properties);\n } catch (e) {\n if (!(e instanceof ReferenceError)) {\n throw e;\n }\n }\n }\n\n /**\n * https://segment.com/docs/libraries/analytics.js/#identify\n *\n * analytics.identify([userId], [traits], [options], [callback]);\n */\n setUserProperties(properties: any) {\n try {\n if (properties.userId) {\n analytics.identify(properties.userId, properties);\n } else {\n analytics.identify(properties);\n }\n } catch (e) {\n if (!(e instanceof ReferenceError)) {\n throw e;\n }\n }\n }\n\n /**\n * https://segment.com/docs/libraries/analytics.js/#alias\n *\n * analytics.alias(userId, previousId, options, callback);\n */\n setAlias(alias: any) {\n try {\n analytics.alias(alias);\n } catch (e) {\n if (!(e instanceof ReferenceError)) {\n throw e;\n }\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './segment';\n"],"names":[],"mappings":";;;;IAOa,mBAAmB,GAAhC,MAAa,mBAAmB;IAE9B,YACU,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;QAElC,IAAI,CAAC,YAAY,CAAC,iBAAiB;aAChC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,IAAI,CAAC,YAAY,CAAC,qBAAqB;aACpC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,IAAI,CAAC,YAAY,CAAC,QAAQ;aACvB,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;KACvC;IAED,aAAa;QACX,IAAI,CAAC,YAAY,CAAC,SAAS;aACxB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;aAC7C,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,CAAC,UAAU;aACzB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;aAC7C,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;KAC9D;;;;;;IAOD,SAAS,CAAC,IAAY;;QAEpB,IAAI;YACF,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACtB;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,EAAE,CAAC,YAAY,cAAc,CAAC,EAAE;gBAClC,MAAM,CA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