{"version":3,"sources":["webpack://CoveoForSitecore/./src/ui/analytics/CoveoForSitecoreAnalytics.ts"],"names":["coveo_search_ui_1","__webpack_require__","ContextEvents_1","CoveoForSitecoreAnalytics","_super","element","options","bindings","_this","call","this","ID","ComponentOptions","initComponentOptions","bind","onRootElement","InitializationEvents","afterInitialization","onAfterInitialization","SitecoreContextEvents","onSitecoreContextInitialization","args","__extends","prototype","usageAnalytics","scOriginContext","setOriginContext","sitecoreContext","AnalyticsEvents","changeAnalyticsCustomData","scOverrideCurrentLanguage","currentLanguage","language","scOverrideOriginWithPageName","sitecorePageName","originLevel1","customMetadata","pageFullPath","sitecorePageFullPath","sitename","siteName","userContext","window","handler","context","getContext","key","_","extend","_a","scAnalyticsCustomMetadata","metaObject","buildJsonOption","buildStringOption","defaultValue","buildBooleanOption","Component","exports","Initialization","registerAutoCreateComponent"],"mappings":"4dAAA,IAAAA,EAAAC,EAAA,GAWAC,EAAAD,EAAA,GASAE,EAAA,SAAAC,GAgBI,SAAAD,EAAmBE,EAA6BC,EAAmDC,GAAnG,IAAAC,EACIJ,EAAAK,KAAAC,KAAML,EAASF,EAA0BQ,GAAIJ,IAASG,YADvCF,EAAAH,UAA6BG,EAAAF,UAAmDE,EAAAD,WAG/FC,EAAKF,QAAUN,EAAAY,iBAAiBC,qBAAqBR,EAASF,EAA2BG,GAEzFE,EAAKM,KAAKC,cAAcf,EAAAgB,qBAAqBC,oBAAqB,WAAM,OAAAT,EAAKU,0BAC7EV,EAAKM,KAAKC,cAAuDb,EAAAiB,sBAAsBC,gCAAiC,SAAAC,GAAQ,OAAAb,EAAKY,gCAAgCC,OA8C7K,OApE+CC,EAAAnB,EAAAC,GAyBnCD,EAAAoB,UAAAL,sBAAR,WACQR,KAAKH,SAASiB,gBAAkBd,KAAKJ,QAAQmB,iBAC7Cf,KAAKH,SAASiB,eAAeE,iBAAiBhB,KAAKJ,QAAQmB,kBAI3DtB,EAAAoB,UAAAH,gCAAR,SAAwCO,GAAxC,IAAAnB,EAAAE,KACIA,KAAKI,KAAKC,cAAmDf,EAAA4B,gBAAgBC,0BAA2B,SAACR,SAC/Ff,EAAUE,EAAKF,QACrB,GAAIA,EAAS,CACLA,EAAQwB,2BAA+BH,EAAgBI,kBACvDV,EAAKW,SAAWL,EAAgBI,iBAEhCzB,EAAQ2B,8BAAkCN,EAAgBO,mBAC1Db,EAAKc,aAAeR,EAAgBO,kBAGxC,IAAME,EAAiB,CACnBC,aAAgBV,EAAgBW,qBAChCC,SAAYZ,EAAgBa,SAC5BA,SAAYb,EAAgBa,UAG1BC,EAAcC,OAAoC,4BACxD,GAAMD,GAAiBA,EAAYE,QAAS,CACxC,IAAMC,EAAUH,EAAYE,QAAQE,aACpC,GAAMD,EACF,IAAK,IAAME,KAAOF,EACdG,EAAEC,OAAOZ,IAAca,EAAA,IAClB,WAAaH,GAAMF,EAAQE,OAMxCxC,EAAQ4C,2BACRH,EAAEC,OAAOZ,EAAgB9B,EAAQ4C,2BAGrCH,EAAEC,OAAO3B,EAAK8B,WAAYf,OA/D/BjC,EAAAQ,GAAK,uBAELR,EAAAG,QAA6C,CAChD4C,0BAA2BlD,EAAAY,iBAAiBwC,kBAC5C3B,gBAAiBzB,EAAAY,iBAAiByC,kBAAkB,CAChDC,aAAc,kBAElBrB,6BAA8BjC,EAAAY,iBAAiB2C,mBAAmB,CAC9DD,cAAc,IAElBxB,0BAA2B9B,EAAAY,iBAAiB2C,mBAAmB,CAC3DD,cAAc,KAwD1BnD,EApEA,CAA+CH,EAAAwD,WAAlCC,EAAAtD,4BAsEbH,EAAA0D,eAAeC,4BAA4BxD","file":"CoveoForSitecoreAnalytics.min.js","sourcesContent":["import {\r\n Component,\r\n AnalyticsEvents,\r\n ComponentOptions,\r\n IComponentBindings,\r\n IChangeAnalyticsCustomDataEventArgs,\r\n InitializationEvents,\r\n Initialization,\r\n IStringMap\r\n} from \"coveo-search-ui\";\r\n\r\nimport { ISitecoreContextInitializationEventArgs, SitecoreContextEvents } from \"../../events/ContextEvents\";\r\n\r\nexport interface ICoveoForSitecoreAnalyticsOptions {\r\n scAnalyticsCustomMetadata: IStringMap<string>;\r\n scOriginContext: string;\r\n scOverrideOriginWithPageName: boolean;\r\n scOverrideCurrentLanguage: boolean;\r\n}\r\n\r\nexport class CoveoForSitecoreAnalytics extends Component {\r\n static ID = \"ForSitecoreAnalytics\";\r\n\r\n static options: ICoveoForSitecoreAnalyticsOptions = {\r\n scAnalyticsCustomMetadata: ComponentOptions.buildJsonOption(),\r\n scOriginContext: ComponentOptions.buildStringOption({\r\n defaultValue: \"WebsiteSearch\"\r\n }),\r\n scOverrideOriginWithPageName: ComponentOptions.buildBooleanOption({\r\n defaultValue: false\r\n }),\r\n scOverrideCurrentLanguage: ComponentOptions.buildBooleanOption({\r\n defaultValue: true\r\n })\r\n };\r\n\r\n constructor(public element: HTMLElement, public options: ICoveoForSitecoreAnalyticsOptions, public bindings: IComponentBindings) {\r\n super(element, CoveoForSitecoreAnalytics.ID, bindings);\r\n\r\n this.options = ComponentOptions.initComponentOptions(element, CoveoForSitecoreAnalytics, options);\r\n\r\n this.bind.onRootElement(InitializationEvents.afterInitialization, () => this.onAfterInitialization());\r\n this.bind.onRootElement<ISitecoreContextInitializationEventArgs>(SitecoreContextEvents.onSitecoreContextInitialization, args => this.onSitecoreContextInitialization(args));\r\n }\r\n\r\n private onAfterInitialization(): void {\r\n if (this.bindings.usageAnalytics && this.options.scOriginContext) {\r\n this.bindings.usageAnalytics.setOriginContext(this.options.scOriginContext);\r\n }\r\n }\r\n\r\n private onSitecoreContextInitialization(sitecoreContext: ISitecoreContextInitializationEventArgs): void {\r\n this.bind.onRootElement<IChangeAnalyticsCustomDataEventArgs>(AnalyticsEvents.changeAnalyticsCustomData, (args: IChangeAnalyticsCustomDataEventArgs) => {\r\n const options = this.options;\r\n if (options) {\r\n if (options.scOverrideCurrentLanguage && !!sitecoreContext.currentLanguage) {\r\n args.language = sitecoreContext.currentLanguage;\r\n }\r\n if (options.scOverrideOriginWithPageName && !!sitecoreContext.sitecorePageName) {\r\n args.originLevel1 = sitecoreContext.sitecorePageName;\r\n }\r\n\r\n const customMetadata = {\r\n \"pageFullPath\": sitecoreContext.sitecorePageFullPath,\r\n \"sitename\": sitecoreContext.siteName, // Kept for backward-compatibility with legacy components\r\n \"siteName\": sitecoreContext.siteName\r\n };\r\n\r\n const userContext = window[\"CoveoForSitecoreUserContext\"];\r\n if (!!userContext && !!userContext.handler) {\r\n const context = userContext.handler.getContext();\r\n if (!!context) {\r\n for (const key in context) {\r\n _.extend(customMetadata, {\r\n [\"context_\" + key]: context[key]\r\n });\r\n }\r\n }\r\n }\r\n\r\n if (options.scAnalyticsCustomMetadata) {\r\n _.extend(customMetadata, options.scAnalyticsCustomMetadata);\r\n }\r\n\r\n _.extend(args.metaObject, customMetadata);\r\n }\r\n });\r\n }\r\n}\r\n\r\nInitialization.registerAutoCreateComponent(CoveoForSitecoreAnalytics);\r\n"],"sourceRoot":""}