{"version":3,"file":"Sprinklr.js","names":["Sprinklr","a","setters","ThirdPartyLoader","default","deepMerge","Event","ajax","on","off","debounce","DataLayer","execute","constructor","element","options","arguments","length","analytics","productsUrl","pageInitUrl","clientContextKey","userContextKey","defaultLocation","bubbleLocation","initCache","selectors","chatBtn","document","querySelectorAll","bindEvents","onCartUpdatedDebounced","onCartUpdated","bind","onFormSubmitDebounced","onFormSubmit","onVideoPlayerPlayDebounced","onVideoPlayerPlay","onOpenChat","then","onChatUpdate","catch","e","formIdField","form","querySelector","formId","getAttribute","obj","window","sprChat","videoId","data","state","lastModifiedTime","modifiedTime","productItems","products","purchased","event","target","location","onBeforeScriptLoad","path","scriptEl","sprChatSettings","get","onScriptLoaded","eventHandler","triggerIconObj","eventType","emit","destroy","removeListener"],"sources":["components/integration/Sprinklr.js"],"sourcesContent":["import ThirdPartyLoader from 'components/global/ThirdPartyLoader';\nimport { deepMerge } from 'toolbox/deepMerge';\nimport { Event } from 'services/EventEmitter';\nimport { ajax } from 'toolbox/ajax';\nimport { on, off } from 'toolbox/event';\nimport { debounce } from 'toolbox/debounce';\nimport DataLayer from 'services/DataLayer';\n\n/**\n * Sprinklr Live Chat\n * @class\n * @classdesc Component for Sprinklr Live Chat integration\n * @extends ThirdPartyLoader\n */\nexport default class Sprinklr extends ThirdPartyLoader {\n /**\n * Constructor of the class that mainly merge the options of the components\n * @param {HTMLElement} element HTMLElement of the component\n * @param {Object} options options that belongs to the component\n */\n constructor(element, options = {}) {\n super(element, deepMerge({\n analytics: {}, // analytics data\n productsUrl: null, // url to get products data after cart update\n pageInitUrl: null, // url to get products data on page initialization\n clientContextKey: '_c_65fb06be9cc87c61e1ffcd3a', // client context key\n userContextKey: '_c_65fb07e29cc87c61e101964d', // user context key\n defaultLocation: 'location-onsite', // default location\n bubbleLocation: 'location-bubble', // bubble location\n }, options));\n }\n\n /**\n * All selectors must be cached. Never cache elements that are out of the component scope\n */\n initCache() {\n this.selectors.chatBtn = document.querySelectorAll('.sprinklr-open-chat');\n }\n\n /**\n * Should contain only event listeners and nothing else\n * All the event handlers should be into a separated function. No usage of anonyous function\n */\n bindEvents() {\n this.onCartUpdatedDebounced = debounce(this.onCartUpdated.bind(this), 200);\n this.onFormSubmitDebounced = debounce(this.onFormSubmit.bind(this), 200);\n this.onVideoPlayerPlayDebounced = debounce(this.onVideoPlayerPlay.bind(this), 200);\n\n Event.on('cart.updated', this.onCartUpdatedDebounced, this);\n Event.on('cart.product.added', this.onCartUpdatedDebounced, this);\n Event.on('carticon.update', this.onCartUpdatedDebounced, this);\n Event.on('lineitem.updated', this.onCartUpdatedDebounced, this);\n Event.on('bonus.product.added', this.onCartUpdatedDebounced, this);\n Event.on('registration.success', this.onCartUpdatedDebounced, this);\n Event.on('login.success', this.onCartUpdatedDebounced, this);\n\n Event.on('form.execute.submit', this.onFormSubmitDebounced, this);\n Event.on('videoplayer.play', this.onVideoPlayerPlayDebounced, this);\n\n if (this.selectors.chatBtn) {\n on('click.sprinklr', this.selectors.chatBtn, this.onOpenChat.bind(this));\n }\n }\n\n /**\n * On cart.updated handler\n */\n onCartUpdated() {\n ajax(this.options.productsUrl)\n .then(this.onChatUpdate.bind(this))\n .catch(() => {});\n }\n\n /**\n * On form submit handler\n * @param {Object} e - event data\n */\n onFormSubmit(e) {\n const formIdField = e.form.querySelector('[name=\"form_id\"]');\n\n if (formIdField) {\n const formId = formIdField.getAttribute('value');\n\n if (formId) {\n const obj = {};\n obj[this.options.userContextKey] = [formId];\n window.sprChat('updateUserContext', obj);\n }\n }\n }\n\n /**\n * On video player play handler\n * @param {Object} e - event data\n */\n onVideoPlayerPlay(e) {\n const { videoId } = e;\n\n if (videoId) {\n const obj = {};\n obj[this.options.userContextKey] = [videoId];\n window.sprChat('updateUserContext', obj);\n }\n }\n\n /**\n * Update product chat data\n * @param {Object} data - products data\n */\n onChatUpdate(data) {\n if (this.state.lastModifiedTime !== data.modifiedTime || (!this.state.lastModifiedTime && !data.modifiedTime)) {\n this.state.lastModifiedTime = data.modifiedTime;\n\n window.sprChat('updateCart', {\n productItems: data.products,\n purchased: data.purchased,\n modifiedTime: data.modifiedTime,\n });\n }\n }\n\n /**\n * Open Sprinklr Window Live Chat\n * @param {Object} event - event data\n */\n onOpenChat(event) {\n const obj = {};\n const { target } = event;\n const location = target.getAttribute('data-location');\n obj[this.options.clientContextKey] = [location || this.options.defaultLocation];\n\n window.sprChat('open');\n window.sprChat('updateClientContext', obj);\n }\n\n /**\n * Before load script, set the chat settings, obtained from the DataLayer, into the window object\n * @param {String} path script path\n * @param {Object} scriptEl script dom element\n * @returns {Boolean} callback result\n */\n onBeforeScriptLoad(path, scriptEl) {\n window.sprChatSettings = DataLayer.get('sprinklrChatSettings', {});\n\n return super.onBeforeScriptLoad(path, scriptEl);\n }\n\n /**\n * On script load handler, called when the third-party is loaded\n */\n onScriptLoaded() {\n super.onScriptLoaded();\n window.sprChat('onEvent', this.eventHandler.bind(this));\n\n if (this.options.pageInitUrl) {\n ajax(this.options.pageInitUrl)\n .then(this.onChatUpdate.bind(this))\n .catch(() => {});\n }\n }\n\n /**\n * Sprinklr onEvent handler\n * @param {Object} data - data from Sprinklr SDK\n */\n eventHandler(data) {\n const triggerIconObj = {};\n triggerIconObj[this.options.clientContextKey] = [this.options.bubbleLocation];\n\n switch (data && data.eventType) {\n case 'CONVERSATION_WINDOW_OPENED':\n if (this.options.analytics) {\n Event.emit('analytics.event', this.options.analytics);\n }\n break;\n case 'CHAT_TRIGGER_CLICKED':\n window.sprChat('updateClientContext', triggerIconObj);\n break;\n default:\n break;\n }\n }\n\n /**\n * Destroy is called automatically after the component is being removed from the DOM\n * You must always destroy the listeners attached to an element to avoid any memory leaks\n */\n destroy() {\n Event.removeListener('cart.updated', this.onCartUpdatedDebounced, this);\n Event.removeListener('cart.product.added', this.onCartUpdatedDebounced, this);\n Event.removeListener('carticon.update', this.onCartUpdatedDebounced, this);\n Event.removeListener('lineitem.updated', this.onCartUpdatedDebounced, this);\n Event.removeListener('bonus.product.added', this.onCartUpdatedDebounced, this);\n Event.removeListener('registration.success', this.onCartUpdatedDebounced, this);\n Event.removeListener('login.success', this.onCartUpdatedDebounced, this);\n\n Event.removeListener('form.execute.submit', this.onFormSubmitDebounced, this);\n Event.removeListener('videoplayer.play', this.onVideoPlayerPlayDebounced, this);\n\n if (this.selectors.chatBtn) {\n off('click.sprinklr', this.selectors.chatBtn);\n }\n }\n}\n"],"mappings":"oOAcqBA,CAAQ,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAdtBE,CAAgB,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACdI,CAAS,CAAAJ,CAAA,CAATI,SAAS,WAAAJ,CAAA,EACTK,CAAK,CAAAL,CAAA,CAALK,KAAK,WAAAL,CAAA,EACLM,CAAI,CAAAN,CAAA,CAAJM,IAAI,WAAAN,CAAA,EACJO,CAAE,CAAAP,CAAA,CAAFO,EAAE,CAAEC,CAAG,CAAAR,CAAA,CAAHQ,GAAG,WAAAR,CAAA,EACPS,CAAQ,CAAAT,CAAA,CAARS,QAAQ,WAAAT,CAAA,EACVU,CAAS,CAAAV,CAAA,CAAAG,OAAA,GAAAQ,OAAA,SAAAA,CAAA,EAAAX,CAAA,WAQKD,CAAQ,CAAd,aAAuB,CAAAG,CAAiB,CAMnDU,WAAWA,CAACC,CAAO,CAAgB,IAAd,CAAAC,CAAO,GAAAC,SAAA,CAAAC,MAAA,WAAAD,SAAA,IAAAA,SAAA,IAAG,CAAC,CAAC,CAC7B,KAAK,CAACF,CAAO,CAAET,CAAS,CAAC,CACrBa,SAAS,CAAE,CAAC,CAAC,CACbC,WAAW,CAAE,IAAI,CACjBC,WAAW,CAAE,IAAI,CACjBC,gBAAgB,CAAE,6BAA6B,CAC/CC,cAAc,CAAE,6BAA6B,CAC7CC,eAAe,CAAE,iBAAiB,CAClCC,cAAc,CAAE,iBACpB,CAAC,CAAET,CAAO,CAAC,CACf,CAKAU,SAASA,CAAA,CAAG,CACR,IAAI,CAACC,SAA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