{"version":3,"file":"user-tracking.gGeBGSjb.js","sources":["../../../src/lib/user-tracking.ts"],"sourcesContent":["import { runQuery } from './graphql'\n\nexport const trackUserData = async ({\n email,\n userType,\n stateId,\n childAge,\n emailSource,\n isSavingsCenter,\n source,\n campaign,\n consumerNewsletter\n}: {\n email: string\n userType?: string\n stateId?: string\n childAge?: number\n emailSource?: string\n isSavingsCenter?: boolean\n source?: string\n campaign?: string\n consumerNewsletter?: string\n}) => {\n const fields = [\n `email: \"${email}\"`,\n userType ? `user_type: \"${userType}\"` : null,\n stateId ? `state_id: \"${stateId}\"` : null,\n childAge ? `childage: \"${childAge}\"` : null,\n isSavingsCenter ? `savings_center: true` : null,\n emailSource ? `email_source: \"${emailSource}\"` : null,\n source ? `source: \"${source}\"` : null,\n campaign ? `campaign: \"${campaign}\"` : null,\n consumerNewsletter ? `consumer_newsletter: \"${consumerNewsletter}\"` : null\n ]\n\n if (childAge) {\n const today = new Date()\n const currentYear = today.getFullYear()\n const birthYearYounger = currentYear - childAge\n fields.push(`birth_year_younger_child: \"${birthYearYounger}\"`)\n fields.push(`birth_year_older_child: \"${birthYearYounger}\"`)\n fields.push(`number_of_children: ${1}`)\n }\n\n const query = `\n mutation {\n track_data(${fields.filter((f) => f !== null).join(', ')})\n }\n `\n\n console.log(query)\n try {\n await runQuery(query)\n } catch (e) {\n console.error('trackUserData failed')\n }\n}\n"],"names":["trackUserData","email","userType","stateId","childAge","emailSource","isSavingsCenter","source","campaign","consumerNewsletter","fields","birthYearYounger","query","f","runQuery"],"mappings":"gZAEO,MAAMA,EAAgB,MAAO,CAClC,MAAAC,EACA,SAAAC,EACA,QAAAC,EACA,SAAAC,EACA,YAAAC,EACA,gBAAAC,EACA,OAAAC,EACA,SAAAC,EACA,mBAAAC,CACF,IAUM,CACJ,MAAMC,EAAS,CACb,WAAWT,CAAK,IAChBC,EAAW,eAAeA,CAAQ,IAAM,KACxCC,EAAU,cAAcA,CAAO,IAAM,KACrCC,EAAW,cAAcA,CAAQ,IAAM,KACvCE,EAAkB,uBAAyB,KAC3CD,EAAc,kBAAkBA,CAAW,IAAM,KACjDE,EAAS,YAAYA,CAAM,IAAM,KACjCC,EAAW,cAAcA,CAAQ,IAAM,KACvCC,EAAqB,yBAAyBA,CAAkB,IAAM,IAAA,EAGxE,GAAIL,EAAU,CAGZ,MAAMO,MAFY,OACQ,cACaP,EAChCM,EAAA,KAAK,8BAA8BC,CAAgB,GAAG,EACtDD,EAAA,KAAK,4BAA4BC,CAAgB,GAAG,EACpDD,EAAA,KAAK,uBAA0B,CACxC,CAEA,MAAME,EAAQ;AAAA;AAAA,+BAEeF,EAAO,OAAQG,GAAMA,IAAM,IAAI,EAAE,KAAK,IAAI,CAAC;AAAA;AAAA,gBAIxE,QAAQ,IAAID,CAAK,EACb,GAAA,CACF,MAAME,EAASF,CAAK,OACV,CACV,QAAQ,MAAM,sBAAsB,CACtC,CACF"}