{"version":3,"file":"ActiveData.js","names":["ActiveData","a","setters","Component","default","Event","deepMerge","execute","constructor","element","options","arguments","length","activeDataContext","bindEvents","on","onEvent","afterInit","setPageContext","window","dw","ac","applyContext","eventName","data","eventType","sfb2ccAnalyticsData","pid","impressionType","sku","recommenderName","placement","sfb2cc","captureActiveDataImpression","handleViewSearchActivity","captureEinsteinImpression","getDefaultCQuotientParams","cq","instanceType","realm","siteId","cookieId","getCQCookieId","userId","getCQUserId","accumulate","CQuotient","params","emailId","getCQHashedEmail","loginId","getCQHashedLogin","locale","searchText","personalized","sortingRule","refinements","queryLocale","products","id","showProducts","JSON","stringify","sendActivity","clientId","activities","push","activityType","parameters","e","items","type","indexOf","capture","alt_id","destroy","removeListener"],"sources":["components/analytics/ActiveData.js"],"sourcesContent":["import Component from 'core/Component';\nimport { Event } from 'services/EventEmitter';\nimport { deepMerge } from 'toolbox/deepMerge';\n\n/**\n * Class which handles SFCC Data Collection tracking. It listens to the two main events\n * dw.ac.capture(Object) used to collect analytics information for products\n * aw.ac.applyContext(Object) used to change the analytics context\n * @class\n * @classdesc It manages SFCC Data Collection events\n * @extends Component\n */\nexport default class ActiveData extends Component {\n /**\n * @constructor\n * @param {HTMLElement} element - ActiveData HTML container\n * @param {object} options - Options of the component\n */\n constructor(element, options = {}) {\n super(element, deepMerge({\n activeDataContext: null,\n }, options));\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 // All the analytics tracking action should call this event.\n Event.on('analytics.event', this.onEvent, this);\n }\n\n /**\n * After init\n * Run any script after the component is fully initialized\n */\n afterInit() {\n this.setPageContext();\n }\n\n /**\n * Set analytics cotext for data collection.\n * Each time the dw.ac.applyContext function is called,\n * it affects all subsequent calls to dw.ac.capture until the next call to dw.ac.applyContext.\n */\n setPageContext() {\n // Collect SFCC analytics information for product (alternative of tag)\n if (this.options.activeDataContext) {\n window.dw.ac.applyContext(this.options.activeDataContext);\n }\n }\n\n /**\n * Handler called when sending basic events\n * @param { String } eventName - of the event\n * @param { Object } data - Data that needs to be passed in the event\n */\n onEvent(eventName, data = {}) {\n if (typeof eventName === 'object') {\n // if first argument is an object then we don't pass the eventName and use the default\n // The first param become the data object\n data = eventName;\n }\n\n if (data.eventType !== 'productImpression' || !data.sfb2ccAnalyticsData || !data.sfb2ccAnalyticsData.pid) {\n return;\n }\n\n const {\n impressionType, pid, sku, recommenderName, placement, sfb2cc,\n } = data.sfb2ccAnalyticsData;\n\n this.captureActiveDataImpression(sku, pid, impressionType);\n\n this.handleViewSearchActivity({\n pid, sku, placement, impressionType, sfb2cc,\n });\n\n if (recommenderName) {\n this.captureEinsteinImpression(pid, sku, recommenderName);\n }\n }\n\n /**\n * Returns some default CQuotient params\n * @param {Object} cq window.CQuotient object\n * @return {Object} CQuotient params data\n */\n getDefaultCQuotientParams(cq) {\n return {\n instanceType: cq.instanceType,\n realm: cq.realm,\n siteId: cq.siteId,\n cookieId: cq.getCQCookieId(),\n userId: cq.getCQUserId(),\n accumulate: true,\n };\n }\n\n /**\n * simulates sfb2cc viewSearch activity\n * @private\n * @param {Object} data object\n * @property {String} pid - product id\n * @property {String} sku - if the product is a variant, id of the variant\n * @property {String} placement - the placement of the tile, to be checked against known type for Search page\n * @property {String} impressionType - one of ['recommendation', 'searchhit', 'none']\n * @property {Object} sfb2cc - object with search related properties\n * @property {String} searchText - searched text\n * @property {Boolean} personalized - if the search is personalized or not\n * @property {String} sortingRule - ID of the effective sorting rule used\n * @property {Array} refinements - Array with refinements applied\n * @property {String} queryLocale - the query locale\n */\n handleViewSearchActivity(data) {\n const {\n pid, sku, placement, impressionType, sfb2cc,\n } = data;\n\n // early return if CQuotient is not defined or if the user is not on a search page\n if (!window.CQuotient || placement !== 'list-result-search') {\n return;\n }\n\n // current retrofit implementation is only for tiles.\n // detail and setproduct are still using isobject in isml through their container templates\n if (!!pid && !!impressionType && impressionType === 'searchhit') {\n const cq = window.CQuotient;\n const params = this.getDefaultCQuotientParams(cq);\n\n params.emailId = cq.getCQHashedEmail();\n params.loginId = cq.getCQHashedLogin();\n params.locale = cq.locale;\n\n const {\n searchText, personalized, sortingRule, refinements, queryLocale,\n } = sfb2cc;\n\n params.queryLocale = queryLocale;\n\n params.products = [{ id: pid, sku }];\n params.showProducts = 'true';\n params.personalized = personalized;\n params.searchText = searchText;\n params.sortingRule = sortingRule;\n params.refinements = JSON.stringify(refinements);\n\n // this is not ideal but that's what sfb2cc injects\n try {\n if (cq.sendActivity) {\n cq.sendActivity(cq.clientId, 'viewSearch', params);\n } else {\n cq.activities.push({ activityType: 'viewSearch', parameters: params });\n }\n } catch (e) {\n\n }\n }\n }\n\n /**\n * simulates sfb2cc active data capture for product impression\n * @private\n * @param { String } sku - product sku\n * @param { String } pid - product id\n * @param { String } impressionType - one of ['recommendation', 'searchhit', 'none']\n */\n captureActiveDataImpression(sku, pid, impressionType) {\n // current retrofit implementation is only for tiles.\n // detail and setproduct are still using isobject in isml through their container templates\n const allowedImpressionTypes = ['recommendation', 'searchhit', 'none'];\n const items = [];\n // we track both sku and pid to initialise master products active data\n if (sku) {\n items.push({ id: sku, type: impressionType });\n }\n if (pid) {\n items.push({ id: pid, type: impressionType });\n }\n // a productId + impression type used by a tile should trigger dw.ac.capture for active data\n if (!!items.length && !!impressionType && allowedImpressionTypes.indexOf(impressionType) !== -1) {\n window.dw.ac.capture(items);\n }\n }\n\n /**\n * simulates sfb2cc einstein data capture for recommendation impression\n * @private\n * @param { String } pid - product id of the master product\n * @param { String } sku - if the product is a variant, id of the variant\n * @param { String } recommenderName - the name of the recommender used to get the recommendation\n */\n captureEinsteinImpression(pid, sku, recommenderName) {\n if (!pid || !window.CQuotient) {\n return;\n }\n // if the type is 'recommendation' and the context is einstein\n // we'll need to emulate the correct call to CQuotient viewReco\n const cq = window.CQuotient;\n const params = this.getDefaultCQuotientParams(cq);\n params.products = [{\n id: pid, sku, type: '', alt_id: '',\n }];\n params.recommenderName = recommenderName;\n\n // this is not ideal but that's what sfb2cc injects\n try {\n if (cq.sendActivity) {\n cq.sendActivity(cq.clientId, 'viewReco', params);\n } else {\n cq.activities.push({ activityType: 'viewReco', parameters: params });\n }\n } catch (e) {\n\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('analytics.event', this.onEvent, this);\n }\n}\n"],"mappings":"+HAYqBA,CAAU,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAZxBE,CAAS,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACPI,CAAK,CAAAJ,CAAA,CAALI,KAAK,WAAAJ,CAAA,EACLK,CAAS,CAAAL,CAAA,CAATK,SAAS,GAAAC,OAAA,SAAAA,CAAA,EAAAN,CAAA,WAUGD,CAAU,CAAhB,aAAyB,CAAAG,CAAU,CAM9CK,WAAWA,CAACC,CAAO,CAAgB,IAAd,CAAAC,CAAO,GAAAC,SAAA,CAAAC,MAAA,WAAAD,SAAA,IAAAA,SAAA,IAAG,CAAC,CAAC,CAC7B,KAAK,CAACF,CAAO,CAAEH,CAAS,CAAC,CACrBO,iBAAiB,CAAE,IACvB,CAAC,CAAEH,CAAO,CAAC,CACf,CAMAI,UAAUA,CAAA,CAAG,CAETT,CAAK,CAACU,EAAE,CAAC,iBAAiB,CAAE,IAAI,CAACC,OAAO,CAAE,IAAI,CAClD,CAMAC,SAASA,CAAA,CAAG,CACR,IAAI,CAACC,cAAc,CAAC,CACxB,CAOAA,cAAcA,CAAA,CAAG,CAET,IAAI,CAACR,OAAO,CAACG,iBAAiB,EAC9BM,MAAM,CAACC,EAAE,CAACC,EAAE,CAACC,YAAY,CAAC,IAAI,CAACZ,OAAO,CAACG,iBAAiB,CAEhE,CAOAG,OAAOA,CAACO,CAAS,CAAa,IAAX,CAAAC,CAAI,GAAAb,SAAA,CAAAC,MAAA,WAAAD,SAAA,IAAAA,SAAA,IAAG,CAAC,CAAC,CAOxB,GANy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