{"version":3,"file":"gtm.slice-ClBSEKec.js","sources":["../../../../../../../../app/frontend/entities/gtm/models/gtm.slice.ts"],"sourcesContent":["import { createSlice } from '@reduxjs/toolkit'\nimport type { PayloadAction } from '@reduxjs/toolkit'\nimport TagManager from 'react-gtm-module'\n\nimport { RegionsType } from '~/shared/types/regions'\n\nexport type Events =\n | 'get_started'\n | 'start_investing'\n | 'country_search'\n | 'search_clicks'\n | 'search_usage'\n | 'no_search_results'\n | 'search'\n | 'search_submit'\n | 'country_district_open'\n | 'city_stat_open'\n | 'country_sub_open'\n\nexport type DataLayerGTMPropsType = {\n Email: string\n Id: string\n Location: string\n country: RegionsType\n propName: string\n searchQuery: string\n suggestedOptions: string\n suggestedOption: string\n optionPosition: number\n city: string\n district: string\n subdistrict: string\n event: Events\n}\n\nexport type GTMPropsType = {\n dataLayer: Partial\n gtmId: string\n}\n\nconst initialState: GTMPropsType = {\n gtmId: 'GTM-P4TW4WFF',\n dataLayer: {\n Email: '',\n Location: '',\n },\n}\n\nexport const gtmSlice = createSlice({\n name: 'gtm',\n initialState,\n reducers: {\n initGTM: (\n state,\n action: PayloadAction<{\n dataLayer: Partial\n }>\n ) => {\n const newGTMParams = { ...state.dataLayer, ...action.payload.dataLayer }\n\n state.dataLayer = newGTMParams\n\n TagManager.initialize({ gtmId: state.gtmId, dataLayer: newGTMParams })\n },\n updateGTMDataLayer: (state, action: PayloadAction>) => {\n state.dataLayer = {\n ...state.dataLayer,\n ...action.payload,\n }\n },\n pushToGTM: (\n state,\n action: PayloadAction<{\n dataLayer: Partial\n widthGlobalProps?: boolean\n }>\n ) => {\n const { widthGlobalProps = false } = action.payload\n const newGTMParams = {\n ...(widthGlobalProps\n ? {\n Email: state.dataLayer.Email,\n Location: state.dataLayer.Location,\n Id: state.dataLayer.Id,\n }\n : {}),\n ...action.payload.dataLayer,\n }\n TagManager.dataLayer({\n dataLayer: newGTMParams,\n })\n if (widthGlobalProps) {\n state.dataLayer = newGTMParams\n }\n },\n },\n})\n\nexport const { pushToGTM, initGTM, updateGTMDataLayer } = gtmSlice.actions\n\nexport default gtmSlice.reducer\n"],"names":["initialState","gtmSlice","createSlice","state","action","newGTMParams","TagManager","widthGlobalProps","pushToGTM","initGTM","updateGTMDataLayer","gtm"],"mappings":"6DAwCA,MAAMA,EAA6B,CACjC,MAAO,eACP,UAAW,CACT,MAAO,GACP,SAAU,EACZ,CACF,EAEaC,EAAWC,EAAY,CAClC,KAAM,MACN,aAAAF,EACA,SAAU,CACR,QAAS,CACPG,EACAC,IAGG,CACG,MAAAC,EAAe,CAAE,GAAGF,EAAM,UAAW,GAAGC,EAAO,QAAQ,WAE7DD,EAAM,UAAYE,EAElBC,EAAW,WAAW,CAAE,MAAOH,EAAM,MAAO,UAAWE,EAAc,CACvE,EACA,mBAAoB,CAACF,EAAOC,IAA0D,CACpFD,EAAM,UAAY,CAChB,GAAGA,EAAM,UACT,GAAGC,EAAO,OAAA,CAEd,EACA,UAAW,CACTD,EACAC,IAIG,CACH,KAAM,CAAE,iBAAAG,EAAmB,IAAUH,EAAO,QACtCC,EAAe,CACnB,GAAIE,EACA,CACE,MAAOJ,EAAM,UAAU,MACvB,SAAUA,EAAM,UAAU,SAC1B,GAAIA,EAAM,UAAU,EAAA,EAEtB,CAAC,EACL,GAAGC,EAAO,QAAQ,SAAA,EAEpBE,EAAW,UAAU,CACnB,UAAWD,CAAA,CACZ,EACGE,IACFJ,EAAM,UAAYE,EAEtB,CACF,CACF,CAAC,EAEY,CAAE,UAAAG,EAAW,QAAAC,EAAS,mBAAAC,GAAuBT,EAAS,QAEpDU,EAAAV,EAAS"}