{"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":";;;;;IASE,6BACU,YAA0B;QADpC,iBASC;QARS,iBAAY,GAAZ,YAAY,CAAc;QAElC,IAAI,CAAC,YAAY,CAAC,iBAAiB;aAChC,SAAS,CAAC,UAAC,CAAC,IAAK,OAAA,KAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAA,CAAC,CAAC;QAC/C,IAAI,CAAC,YAAY,CAAC,qBAAqB;aACpC,SAAS,CAAC,UAAC,CAAC,IAAK,OAAA,KAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAA,CAAC,CAAC;QAC/C,IAAI,CAAC,YAAY,CAAC,QAAQ;aACvB,SAAS,CAAC,UAAC,CAAC,IAAK,OAAA,KAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAA,CAAC,CAAC;KACvC;IAED,2CAAa,GAAb;QAAA,iBAOC;QANC,IAAI,CAAC,YAAY,CAAC,SAAS;aACxB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;aAC7C,SAAS,CAAC,UAAC,CAAC,IAAK,OAAA,KAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAA,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,CAAC,UAAU;aACzB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;aAC7C,SAAS,CAAC,UAAC,CAAC,IAAK,OAAA,KAAI,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,GAAA,CAAC,CAAC;KAC9D;;;;;;IAOD,uCAAS,GAAT,UAAU,IAAY;;QAEpB,IAAI;YACF,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACtB;QAAC,OAAO,CAAC,EAAE;Y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