@simplybusiness/services 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/mocks/eventDefinitions.js +5 -21
  3. package/dist/cjs/mocks/eventDefinitions.js.map +1 -1
  4. package/dist/cjs/snowplow/Snowplow.js +41 -28
  5. package/dist/cjs/snowplow/Snowplow.js.map +1 -1
  6. package/dist/cjs/snowplow/contexts.js +52 -12
  7. package/dist/cjs/snowplow/contexts.js.map +1 -1
  8. package/dist/cjs/snowplow/event-definitions/qcp.js +8 -2
  9. package/dist/cjs/snowplow/event-definitions/qcp.js.map +1 -1
  10. package/dist/cjs/snowplow/event-definitions/questionnaire.js +4 -1
  11. package/dist/cjs/snowplow/event-definitions/questionnaire.js.map +1 -1
  12. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  13. package/dist/esm/mocks/eventDefinitions.js +5 -21
  14. package/dist/esm/mocks/eventDefinitions.js.map +1 -1
  15. package/dist/esm/snowplow/Snowplow.js +41 -28
  16. package/dist/esm/snowplow/Snowplow.js.map +1 -1
  17. package/dist/esm/snowplow/contexts.js +38 -9
  18. package/dist/esm/snowplow/contexts.js.map +1 -1
  19. package/dist/esm/snowplow/event-definitions/qcp.js +9 -22
  20. package/dist/esm/snowplow/event-definitions/qcp.js.map +1 -1
  21. package/dist/esm/snowplow/event-definitions/questionnaire.js +4 -1
  22. package/dist/esm/snowplow/event-definitions/questionnaire.js.map +1 -1
  23. package/dist/esm/snowplow/types.js.map +1 -1
  24. package/dist/types/mocks/eventDefinitions.d.ts +4 -19
  25. package/dist/types/snowplow/Snowplow.d.ts +7 -5
  26. package/dist/types/snowplow/contexts.d.ts +4 -3
  27. package/dist/types/snowplow/event-definitions/qcp.d.ts +0 -20
  28. package/dist/types/snowplow/types.d.ts +3 -1
  29. package/package.json +2 -2
  30. package/src/mocks/eventDefinitions.ts +2 -25
  31. package/src/snowplow/Snowplow.ts +46 -29
  32. package/src/snowplow/contexts.test.ts +134 -6
  33. package/src/snowplow/contexts.ts +44 -14
  34. package/src/snowplow/event-definitions/qcp.ts +2 -21
  35. package/src/snowplow/event-definitions/questionnaire.ts +1 -0
  36. package/src/snowplow/index.test.ts +40 -30
  37. package/src/snowplow/types.ts +4 -1
@@ -1,18 +1,47 @@
1
1
  import { snakeCaseKeys } from "../utils";
2
2
  export const getContexts = (config)=>{
3
- const contexts = config && Object.entries(config).filter(([key])=>key.includes("Context") && key !== "includeGAContext").map(([_key, value])=>{
3
+ // Create an object that only contains Context keys
4
+ // and snake_case the keys
5
+ const contextEntries = Object.entries(config || {}).filter(([key])=>key.includes("Context") && key !== "includeGAContext").reduce((acc, [key, value])=>{
4
6
  if (typeof value === "object") {
5
- return snakeCaseKeys({
6
- ...value
7
- });
7
+ return {
8
+ ...acc,
9
+ [key]: snakeCaseKeys({
10
+ ...value
11
+ })
12
+ };
8
13
  }
9
- return snakeCaseKeys({
10
- data: {
11
- service_channel_identifier: value
12
- }
13
- });
14
+ return {
15
+ ...acc,
16
+ [key]: snakeCaseKeys({
17
+ data: {
18
+ service_channel_identifier: value
19
+ }
20
+ })
21
+ };
22
+ }, {});
23
+ return contextEntries;
24
+ };
25
+ export const updateIdentityContext = (contexts, uid)=>{
26
+ const index = Object.keys(contexts).findIndex((ctx)=>{
27
+ var _contexts_ctx_schema;
28
+ return (_contexts_ctx_schema = contexts[ctx].schema) === null || _contexts_ctx_schema === void 0 ? void 0 : _contexts_ctx_schema.includes("identity_context");
14
29
  });
30
+ if (index > -1) {
31
+ const key = Object.keys(contexts)[index];
32
+ return {
33
+ ...contexts,
34
+ [key]: {
35
+ ...contexts[key],
36
+ data: {
37
+ ...contexts[key].data,
38
+ domain_userid: uid
39
+ }
40
+ }
41
+ };
42
+ }
15
43
  return contexts;
16
44
  };
45
+ export const makeContexts = (keys, config)=>(keys || []).map((key)=>config[key]);
17
46
 
18
47
  //# sourceMappingURL=contexts.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/snowplow/contexts.ts"],"sourcesContent":["import { SelfDescribingJson } from \"@snowplow/browser-tracker\";\nimport { TrackingProps } from \"./types\";\nimport { snakeCaseKeys } from \"../utils\";\n\nexport const getContexts = (\n config: TrackingProps,\n): SelfDescribingJson<Record<string, unknown>>[] => {\n const contexts =\n config &&\n Object.entries(config)\n .filter(([key]) => key.includes(\"Context\") && key !== \"includeGAContext\")\n .map(([_key, value]) => {\n if (typeof value === \"object\") {\n return snakeCaseKeys(({ ...value }));\n }\n return snakeCaseKeys({ data: { service_channel_identifier: value } });\n });\n\n return contexts as unknown as SelfDescribingJson<Record<string, unknown>>[];\n};\n"],"names":["snakeCaseKeys","getContexts","config","contexts","Object","entries","filter","key","includes","map","_key","value","data","service_channel_identifier"],"mappings":"AAEA,SAASA,aAAa,QAAQ,WAAW;AAEzC,OAAO,MAAMC,cAAc,CACzBC;IAEA,MAAMC,WACJD,UACAE,OAAOC,OAAO,CAACH,QACZI,MAAM,CAAC,CAAC,CAACC,IAAI,GAAKA,IAAIC,QAAQ,CAAC,cAAcD,QAAQ,oBACrDE,GAAG,CAAC,CAAC,CAACC,MAAMC,MAAM;QACjB,IAAI,OAAOA,UAAU,UAAU;YAC7B,OAAOX,cAAe;gBAAE,GAAGW,KAAK;YAAC;QACnC;QACA,OAAOX,cAAc;YAAEY,MAAM;gBAAEC,4BAA4BF;YAAM;QAAE;IACrE;IAEJ,OAAOR;AACT,EAAE"}
1
+ {"version":3,"sources":["../../../src/snowplow/contexts.ts"],"sourcesContent":["import { snakeCaseKeys } from \"../utils\";\nimport { SerialisedEvent, TrackingProps } from \"./types\";\n\nexport const getContexts = (\n config: TrackingProps,\n): Record<string, SerialisedEvent> => {\n // Create an object that only contains Context keys\n // and snake_case the keys\n const contextEntries = Object.entries(config || {})\n .filter(([key]) => key.includes(\"Context\") && key !== \"includeGAContext\")\n .reduce((acc, [key, value]) => {\n if (typeof value === \"object\") {\n return { ...acc, [key]: snakeCaseKeys({ ...value }) };\n }\n return {\n ...acc,\n [key]: snakeCaseKeys({ data: { service_channel_identifier: value } }),\n };\n }, {});\n\n return contextEntries as Record<string, SerialisedEvent>;\n};\n\nexport const updateIdentityContext = (\n contexts: Record<string, SerialisedEvent>,\n uid: unknown,\n): Record<string, SerialisedEvent> => {\n const index = Object.keys(contexts).findIndex(ctx =>\n contexts[ctx].schema?.includes(\"identity_context\"),\n );\n if (index > -1) {\n const key = Object.keys(contexts)[index];\n return {\n ...contexts,\n [key]: {\n ...contexts[key],\n data: {\n ...contexts[key].data,\n domain_userid: uid,\n },\n },\n };\n }\n return contexts;\n};\n\nexport const makeContexts = (\n keys: string[],\n config: Record<string, SerialisedEvent>,\n): SerialisedEvent[] => (keys || []).map(key => config[key]);\n"],"names":["snakeCaseKeys","getContexts","config","contextEntries","Object","entries","filter","key","includes","reduce","acc","value","data","service_channel_identifier","updateIdentityContext","contexts","uid","index","keys","findIndex","ctx","schema","domain_userid","makeContexts","map"],"mappings":"AAAA,SAASA,aAAa,QAAQ,WAAW;AAGzC,OAAO,MAAMC,cAAc,CACzBC;IAEA,mDAAmD;IACnD,0BAA0B;IAC1B,MAAMC,iBAAiBC,OAAOC,OAAO,CAACH,UAAU,CAAC,GAC9CI,MAAM,CAAC,CAAC,CAACC,IAAI,GAAKA,IAAIC,QAAQ,CAAC,cAAcD,QAAQ,oBACrDE,MAAM,CAAC,CAACC,KAAK,CAACH,KAAKI,MAAM;QACxB,IAAI,OAAOA,UAAU,UAAU;YAC7B,OAAO;gBAAE,GAAGD,GAAG;gBAAE,CAACH,IAAI,EAAEP,cAAc;oBAAE,GAAGW,KAAK;gBAAC;YAAG;QACtD;QACA,OAAO;YACL,GAAGD,GAAG;YACN,CAACH,IAAI,EAAEP,cAAc;gBAAEY,MAAM;oBAAEC,4BAA4BF;gBAAM;YAAE;QACrE;IACF,GAAG,CAAC;IAEN,OAAOR;AACT,EAAE;AAEF,OAAO,MAAMW,wBAAwB,CACnCC,UACAC;IAEA,MAAMC,QAAQb,OAAOc,IAAI,CAACH,UAAUI,SAAS,CAACC,CAAAA;YAC5CL;gBAAAA,uBAAAA,QAAQ,CAACK,IAAI,CAACC,MAAM,cAApBN,2CAAAA,qBAAsBP,QAAQ,CAAC;;IAEjC,IAAIS,QAAQ,CAAC,GAAG;QACd,MAAMV,MAAMH,OAAOc,IAAI,CAACH,SAAS,CAACE,MAAM;QACxC,OAAO;YACL,GAAGF,QAAQ;YACX,CAACR,IAAI,EAAE;gBACL,GAAGQ,QAAQ,CAACR,IAAI;gBAChBK,MAAM;oBACJ,GAAGG,QAAQ,CAACR,IAAI,CAACK,IAAI;oBACrBU,eAAeN;gBACjB;YACF;QACF;IACF;IACA,OAAOD;AACT,EAAE;AAEF,OAAO,MAAMQ,eAAe,CAC1BL,MACAhB,SACsB,AAACgB,CAAAA,QAAQ,EAAE,AAAD,EAAGM,GAAG,CAACjB,CAAAA,MAAOL,MAAM,CAACK,IAAI,EAAE"}
@@ -1,24 +1,5 @@
1
1
  import { snakeCase } from "../../utils";
2
- /**
3
- * Event definitions for Snowplow
4
- * @type {EventDefinition[]}
5
- * @property {string} name - The name of the event, to use when triggering
6
- * @property {string} type - The type of the event (structured | unstructured)
7
- * @property {makePayload} makePayload
8
- * - Function that creates the payload for the event;
9
- * - Allows optional params object to be passed in
10
- *
11
- * @example
12
- * Parent
13
- * import { getSnowplowConfig, SnowplowProvider } from "@simplybusiness/services";
14
- * const snowplowProps = getSnowplowConfig(pageData);
15
- * <SnowplowProvider scripts={snowplowProps!}>{children}</SnowplowProvider>
16
- *
17
- * Child
18
- * import { useSnowplowContext } from "@simplybusiness/services";
19
- * const { snowplow } = useSnowplowContext();
20
- * const handlerFunction = () => snowplow?.trigger("eventNameHere");
21
- */ // QCP page events
2
+ // QCP page events
22
3
  export const qcpEventDefinitions = [
23
4
  {
24
5
  // QDP details button
@@ -128,7 +109,10 @@ export const qcpEventDefinitions = [
128
109
  to_value: toValue
129
110
  }
130
111
  };
131
- }
112
+ },
113
+ contexts: [
114
+ "distributionChannelContext"
115
+ ]
132
116
  },
133
117
  {
134
118
  name: "ratingsModalOpened",
@@ -231,7 +215,10 @@ export const qcpEventDefinitions = [
231
215
  vertical
232
216
  }
233
217
  };
234
- }
218
+ },
219
+ contexts: [
220
+ "serviceChannelContext"
221
+ ]
235
222
  },
236
223
  {
237
224
  name: "helpChatLinkClicked",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/snowplow/event-definitions/qcp.ts"],"sourcesContent":["import { snakeCase } from \"../../utils\";\nimport { EventDefinition, LinkType, ParamsType } from \"../types\";\n\n/**\n * Event definitions for Snowplow\n * @type {EventDefinition[]}\n * @property {string} name - The name of the event, to use when triggering\n * @property {string} type - The type of the event (structured | unstructured)\n * @property {makePayload} makePayload\n * - Function that creates the payload for the event;\n * - Allows optional params object to be passed in\n *\n * @example\n * Parent\n * import { getSnowplowConfig, SnowplowProvider } from \"@simplybusiness/services\";\n * const snowplowProps = getSnowplowConfig(pageData);\n * <SnowplowProvider scripts={snowplowProps!}>{children}</SnowplowProvider>\n *\n * Child\n * import { useSnowplowContext } from \"@simplybusiness/services\";\n * const { snowplow } = useSnowplowContext();\n * const handlerFunction = () => snowplow?.trigger(\"eventNameHere\");\n */\n\n// QCP page events\nexport const qcpEventDefinitions: EventDefinition[] = [\n {\n // QDP details button\n name: \"detailsClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"comparison_cta\",\n action: \"link_click\",\n label: \"Details\",\n }),\n },\n {\n // Buy button\n name: \"selectClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"comparison_cta\",\n action: \"link_click\",\n label: \"Buy\",\n }),\n },\n {\n // Quote Details Slider Next steps button\n name: \"nextStepsClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"quote_details_slider_next_step_cta\",\n action: \"link_click\",\n label: \"Next steps\",\n }),\n },\n {\n // Toggle deductibles accordion\n name: \"deductiblesClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"us-qcp-react\",\n action: \"view_deductables_clicked\",\n label: \"view_deductables_clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"deductiblesClickedUk\",\n type: \"structured\",\n makePayload: params => {\n const { label, deviceType } = params as ParamsType;\n const urlFriendlyLabel = label.replace(/ /g, \"-\").toLowerCase();\n\n return {\n category: `uk-qcp-react-${deviceType}-${urlFriendlyLabel}-view-excess-toggle`,\n action: \"view_excess_clicked\",\n label,\n property: window.location.href,\n };\n },\n },\n {\n // Quote Details Slider opened\n name: \"sliderOpened\",\n type: \"structured\",\n makePayload: params => {\n const { label } = params as ParamsType;\n\n return {\n category: \"comparison_cta\",\n action: \"quote_details_slider_opened\",\n label,\n };\n },\n },\n {\n // Coverage modal opened\n name: \"coverageModalOpened\",\n type: \"structured\",\n makePayload: params => {\n const {\n category,\n product = \"extra_coverage\",\n title,\n } = params as ParamsType;\n const productLabel = snakeCase(product);\n\n return {\n category,\n action: `${productLabel}_${snakeCase(title)}_popup_opened`,\n label: productLabel,\n property: window.location.href,\n };\n },\n },\n {\n // Toggle cover select\n name: \"coverChanged\",\n type: \"unstructured\",\n makePayload: params => {\n const { name = \"\", fromValue = \"\", toValue = \"\" } = params as ParamsType;\n // Derive data\n let action = \"change\";\n\n // This logic is taken directly from Chopin without documentation:\n // If a cover has zero value, then change the action to add or remove\n if (fromValue === \"0\") {\n action = \"add\";\n }\n if (toValue === \"0\") {\n action = \"remove\";\n }\n\n return {\n schema:\n \"iglu:com.simplybusiness/comparison_page_cover_changed/jsonschema/1-0-0\",\n data: {\n name,\n action,\n from_value: fromValue,\n to_value: toValue,\n },\n };\n },\n },\n {\n name: \"ratingsModalOpened\",\n type: \"structured\",\n makePayload: params => {\n const { category, label } = params as ParamsType;\n\n return {\n category,\n action: \"insurer_rating_help_popup_triggered\",\n label,\n property: window.location.href,\n };\n },\n },\n {\n name: \"coverToggleOpened\",\n type: \"structured\",\n makePayload: () => ({\n category: \"qcp_limit_interaction\",\n label: \"limit_interaction\",\n action: \"limit_interaction_clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"paymentToggleClicked\",\n type: \"structured\",\n makePayload: params => {\n const { category, label } = params as ParamsType;\n\n return {\n category,\n action: \"button_click\",\n label,\n property: window.location.href,\n };\n },\n },\n {\n name: \"insurerDetailsAccordionClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"quote_details_slider_insurer_details_description\",\n action: \"accordion_clicked\",\n label: \"accordion_clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"priceDetailsPopUpOpened\",\n type: \"structured\",\n makePayload: () => ({\n category: \"price_details\",\n action: \"price_details_popup_opened\",\n label: \"Price details\",\n property: window.location.href,\n }),\n },\n {\n name: \"editLimitButtonClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"cover_limit_changes\",\n action: \"edit_limit_button_clicked\",\n label: \"Edit Limit\",\n property: window.location.href,\n }),\n },\n {\n name: \"applyButtonClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"cover_limit_changes\",\n action: \"apply_button_clicked\",\n label: \"Apply Button Clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"coverageInfoClicked\",\n type: \"structured\",\n makePayload: params => {\n const { deviceType } = params as ParamsType;\n\n return {\n action: \"show_coverage_info_clicked\",\n category: `uk-qcp-react-${deviceType}-show-coverage-info-toggle`,\n label: \"show_coverage_info_clicked\",\n property: window.location.href,\n };\n },\n },\n {\n name: \"backToApplication\",\n type: \"unstructured\",\n makePayload: params => {\n const { journeyId, vertical } = params as ParamsType;\n\n return {\n schema: \"iglu:com.simplybusiness/back_to_application/jsonschema/1-0-0\",\n data: {\n journey_id: journeyId,\n vertical,\n },\n };\n },\n },\n {\n name: \"helpChatLinkClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"help chat for question\",\n action: \"help_chat_for_question_clicked\",\n property: window.location.href,\n }),\n },\n // No quotes referral\n {\n name: \"coverOptionsLinkClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"uk-qcp-react-cover-options-link\",\n action: \"cover_options_link_clicked\",\n label: \"cover_options_link_clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"referralReasonsVariantBCoverOptionsLinkClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"uk-24-12-qcp-mvt-referral-reasons\",\n action: \"cover_options_link_clicked_variant_b\",\n label: \"cover_options_link_clicked_variant_b\",\n property: window.location.href,\n }),\n },\n {\n name: \"referralReasonsVariantCCoverOptionsLinkClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"uk-24-12-qcp-mvt-referral-reasons\",\n action: \"cover_options_link_clicked_variant_c\",\n label: \"cover_options_link_clicked_variant_c\",\n property: window.location.href,\n }),\n },\n {\n name: \"phoneNumberLinkClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"uk-qcp-react-phone-number-link\",\n action: \"phone_number_link_clicked\",\n label: \"phone_number_link_clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"stickyFooterClick\",\n type: \"structured\",\n makePayload: () => ({\n category: \"marketing\",\n action: \"link-click\",\n label: \"sticky_footer_button\",\n property: window.location.href,\n }),\n },\n {\n name: \"linkClicked\",\n type: \"unstructured\",\n makePayload: params => {\n const { targetUrl, elementContent } = params as LinkType;\n\n return {\n schema:\n \"iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1\",\n data: {\n targetUrl,\n elementContent,\n },\n };\n },\n },\n {\n name: \"qcpUpsellAccordionClicked\",\n type: \"structured\",\n makePayload: params => ({\n category: \"us-qcp-upsells\",\n action: \"accordion_clicked_qcp\",\n label: params?.label as string,\n property: window.location.href,\n }),\n },\n {\n name: \"qdsUpsellAccordionClicked\",\n type: \"structured\",\n makePayload: params => ({\n category: \"us-qcp-upsells\",\n action: \"accordion_clicked_slider\",\n label: params?.label as string,\n property: window.location.href,\n }),\n },\n {\n name: \"qcpUpsellTooltipHelperClicked\",\n type: \"structured\",\n makePayload: params => ({\n category: \"us-qcp-upsells\",\n action: \"tooltip_helper_clicked_qcp\",\n label: params?.label as string,\n property: window.location.href,\n }),\n },\n {\n name: \"qdsUpsellTooltipHelperClicked\",\n type: \"structured\",\n makePayload: params => ({\n category: \"us-qcp-upsells\",\n action: \"tooltip_helper_clicked_slider\",\n label: params?.label as string,\n property: window.location.href,\n }),\n },\n];\n"],"names":["snakeCase","qcpEventDefinitions","name","type","makePayload","category","action","label","property","window","location","href","params","deviceType","urlFriendlyLabel","replace","toLowerCase","product","title","productLabel","fromValue","toValue","schema","data","from_value","to_value","journeyId","vertical","journey_id","targetUrl","elementContent"],"mappings":"AAAA,SAASA,SAAS,QAAQ,cAAc;AAGxC;;;;;;;;;;;;;;;;;;;CAmBC,GAED,kBAAkB;AAClB,OAAO,MAAMC,sBAAyC;IACpD;QACE,qBAAqB;QACrBC,MAAM;QACNC,MAAM;QACNC,aAAa,IAAO,CAAA;gBAClBC,UAAU;gBACVC,QAAQ;gBACRC,OAAO;YACT,CAAA;IACF;IACA;QACE,aAAa;QACbL,MAAM;QACNC,MAAM;QACNC,aAAa,IAAO,CAAA;gBAClBC,UAAU;gBACVC,QAAQ;gBACRC,OAAO;YACT,CAAA;IACF;IACA;QACE,yCAAyC;QACzCL,MAAM;QACNC,MAAM;QACNC,aAAa,IAAO,CAAA;gBAClBC,UAAU;gBACVC,QAAQ;gBACRC,OAAO;YACT,CAAA;IACF;IACA;QACE,+BAA+B;QAC/BL,MAAM;QACNC,MAAM;QACNC,aAAa,IAAO,CAAA;gBAClBC,UAAU;gBACVC,QAAQ;gBACRC,OAAO;gBACPC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;IACA;QACET,MAAM;QACNC,MAAM;QACNC,aAAaQ,CAAAA;YACX,MAAM,EAAEL,KAAK,EAAEM,UAAU,EAAE,GAAGD;YAC9B,MAAME,mBAAmBP,MAAMQ,OAAO,CAAC,MAAM,KAAKC,WAAW;YAE7D,OAAO;gBACLX,UAAU,CAAC,aAAa,EAAEQ,WAAW,CAAC,EAAEC,iB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AM;QACNC,aAAaQ,CAAAA,SAAW,CAAA;gBACtBP,UAAU;gBACVC,QAAQ;gBACRC,KAAK,EAAEK,mBAAAA,6BAAAA,OAAQL,KAAK;gBACpBC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;IACA;QACET,MAAM;QACNC,MAAM;QACNC,aAAaQ,CAAAA,SAAW,CAAA;gBACtBP,UAAU;gBACVC,QAAQ;gBACRC,KAAK,EAAEK,mBAAAA,6BAAAA,OAAQL,KAAK;gBACpBC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;IACA;QACET,MAAM;QACNC,MAAM;QACNC,aAAaQ,CAAAA,SAAW,CAAA;gBACtBP,UAAU;gBACVC,QAAQ;gBACRC,KAAK,EAAEK,mBAAAA,6BAAAA,OAAQL,KAAK;gBACpBC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;IACA;QACET,MAAM;QACNC,MAAM;QACNC,aAAaQ,CAAAA,SAAW,CAAA;gBACtBP,UAAU;gBACVC,QAAQ;gBACRC,KAAK,EAAEK,mBAAAA,6BAAAA,OAAQL,KAAK;gBACpBC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;CACD,CAAC"}
1
+ {"version":3,"sources":["../../../../src/snowplow/event-definitions/qcp.ts"],"sourcesContent":["import { snakeCase } from \"../../utils\";\nimport { EventDefinition, LinkType, ParamsType } from \"../types\";\n\n// QCP page events\nexport const qcpEventDefinitions: EventDefinition[] = [\n {\n // QDP details button\n name: \"detailsClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"comparison_cta\",\n action: \"link_click\",\n label: \"Details\",\n }),\n },\n {\n // Buy button\n name: \"selectClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"comparison_cta\",\n action: \"link_click\",\n label: \"Buy\",\n }),\n },\n {\n // Quote Details Slider Next steps button\n name: \"nextStepsClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"quote_details_slider_next_step_cta\",\n action: \"link_click\",\n label: \"Next steps\",\n }),\n },\n {\n // Toggle deductibles accordion\n name: \"deductiblesClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"us-qcp-react\",\n action: \"view_deductables_clicked\",\n label: \"view_deductables_clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"deductiblesClickedUk\",\n type: \"structured\",\n makePayload: params => {\n const { label, deviceType } = params as ParamsType;\n const urlFriendlyLabel = label.replace(/ /g, \"-\").toLowerCase();\n\n return {\n category: `uk-qcp-react-${deviceType}-${urlFriendlyLabel}-view-excess-toggle`,\n action: \"view_excess_clicked\",\n label,\n property: window.location.href,\n };\n },\n },\n {\n // Quote Details Slider opened\n name: \"sliderOpened\",\n type: \"structured\",\n makePayload: params => {\n const { label } = params as ParamsType;\n\n return {\n category: \"comparison_cta\",\n action: \"quote_details_slider_opened\",\n label,\n };\n },\n },\n {\n // Coverage modal opened\n name: \"coverageModalOpened\",\n type: \"structured\",\n makePayload: params => {\n const {\n category,\n product = \"extra_coverage\",\n title,\n } = params as ParamsType;\n const productLabel = snakeCase(product);\n\n return {\n category,\n action: `${productLabel}_${snakeCase(title)}_popup_opened`,\n label: productLabel,\n property: window.location.href,\n };\n },\n },\n {\n // Toggle cover select\n name: \"coverChanged\",\n type: \"unstructured\",\n makePayload: params => {\n const { name = \"\", fromValue = \"\", toValue = \"\" } = params as ParamsType;\n // Derive data\n let action = \"change\";\n\n // This logic is taken directly from Chopin without documentation:\n // If a cover has zero value, then change the action to add or remove\n if (fromValue === \"0\") {\n action = \"add\";\n }\n if (toValue === \"0\") {\n action = \"remove\";\n }\n\n return {\n schema:\n \"iglu:com.simplybusiness/comparison_page_cover_changed/jsonschema/1-0-0\",\n data: {\n name,\n action,\n from_value: fromValue,\n to_value: toValue,\n },\n };\n },\n contexts: [\"distributionChannelContext\"],\n },\n {\n name: \"ratingsModalOpened\",\n type: \"structured\",\n makePayload: params => {\n const { category, label } = params as ParamsType;\n\n return {\n category,\n action: \"insurer_rating_help_popup_triggered\",\n label,\n property: window.location.href,\n };\n },\n },\n {\n name: \"coverToggleOpened\",\n type: \"structured\",\n makePayload: () => ({\n category: \"qcp_limit_interaction\",\n label: \"limit_interaction\",\n action: \"limit_interaction_clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"paymentToggleClicked\",\n type: \"structured\",\n makePayload: params => {\n const { category, label } = params as ParamsType;\n\n return {\n category,\n action: \"button_click\",\n label,\n property: window.location.href,\n };\n },\n },\n {\n name: \"insurerDetailsAccordionClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"quote_details_slider_insurer_details_description\",\n action: \"accordion_clicked\",\n label: \"accordion_clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"priceDetailsPopUpOpened\",\n type: \"structured\",\n makePayload: () => ({\n category: \"price_details\",\n action: \"price_details_popup_opened\",\n label: \"Price details\",\n property: window.location.href,\n }),\n },\n {\n name: \"editLimitButtonClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"cover_limit_changes\",\n action: \"edit_limit_button_clicked\",\n label: \"Edit Limit\",\n property: window.location.href,\n }),\n },\n {\n name: \"applyButtonClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"cover_limit_changes\",\n action: \"apply_button_clicked\",\n label: \"Apply Button Clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"coverageInfoClicked\",\n type: \"structured\",\n makePayload: params => {\n const { deviceType } = params as ParamsType;\n\n return {\n action: \"show_coverage_info_clicked\",\n category: `uk-qcp-react-${deviceType}-show-coverage-info-toggle`,\n label: \"show_coverage_info_clicked\",\n property: window.location.href,\n };\n },\n },\n {\n name: \"backToApplication\",\n type: \"unstructured\",\n makePayload: params => {\n const { journeyId, vertical } = params as ParamsType;\n\n return {\n schema: \"iglu:com.simplybusiness/back_to_application/jsonschema/1-0-0\",\n data: {\n journey_id: journeyId,\n vertical,\n },\n };\n },\n contexts: [\"serviceChannelContext\"],\n },\n {\n name: \"helpChatLinkClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"help chat for question\",\n action: \"help_chat_for_question_clicked\",\n property: window.location.href,\n }),\n },\n // No quotes referral\n {\n name: \"coverOptionsLinkClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"uk-qcp-react-cover-options-link\",\n action: \"cover_options_link_clicked\",\n label: \"cover_options_link_clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"referralReasonsVariantBCoverOptionsLinkClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"uk-24-12-qcp-mvt-referral-reasons\",\n action: \"cover_options_link_clicked_variant_b\",\n label: \"cover_options_link_clicked_variant_b\",\n property: window.location.href,\n }),\n },\n {\n name: \"referralReasonsVariantCCoverOptionsLinkClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"uk-24-12-qcp-mvt-referral-reasons\",\n action: \"cover_options_link_clicked_variant_c\",\n label: \"cover_options_link_clicked_variant_c\",\n property: window.location.href,\n }),\n },\n {\n name: \"phoneNumberLinkClicked\",\n type: \"structured\",\n makePayload: () => ({\n category: \"uk-qcp-react-phone-number-link\",\n action: \"phone_number_link_clicked\",\n label: \"phone_number_link_clicked\",\n property: window.location.href,\n }),\n },\n {\n name: \"stickyFooterClick\",\n type: \"structured\",\n makePayload: () => ({\n category: \"marketing\",\n action: \"link-click\",\n label: \"sticky_footer_button\",\n property: window.location.href,\n }),\n },\n {\n name: \"linkClicked\",\n type: \"unstructured\",\n makePayload: params => {\n const { targetUrl, elementContent } = params as LinkType;\n\n return {\n schema:\n \"iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1\",\n data: {\n targetUrl,\n elementContent,\n },\n };\n },\n },\n {\n name: \"qcpUpsellAccordionClicked\",\n type: \"structured\",\n makePayload: params => ({\n category: \"us-qcp-upsells\",\n action: \"accordion_clicked_qcp\",\n label: params?.label as string,\n property: window.location.href,\n }),\n },\n {\n name: \"qdsUpsellAccordionClicked\",\n type: \"structured\",\n makePayload: params => ({\n category: \"us-qcp-upsells\",\n action: \"accordion_clicked_slider\",\n label: params?.label as string,\n property: window.location.href,\n }),\n },\n {\n name: \"qcpUpsellTooltipHelperClicked\",\n type: \"structured\",\n makePayload: params => ({\n category: \"us-qcp-upsells\",\n action: \"tooltip_helper_clicked_qcp\",\n label: params?.label as string,\n property: window.location.href,\n }),\n },\n {\n name: \"qdsUpsellTooltipHelperClicked\",\n type: \"structured\",\n makePayload: params => ({\n category: \"us-qcp-upsells\",\n action: \"tooltip_helper_clicked_slider\",\n label: params?.label as string,\n property: window.location.href,\n }),\n },\n];\n"],"names":["snakeCase","qcpEventDefinitions","name","type","makePayload","category","action","label","property","window","location","href","params","deviceType","urlFriendlyLabel","replace","toLowerCase","product","title","productLabel","fromValue","toValue","schema","data","from_value","to_value","contexts","journeyId","vertical","journey_id","targetUrl","elementContent"],"mappings":"AAAA,SAASA,SAAS,QAAQ,cAAc;AAGxC,kBAAkB;AAClB,OAAO,MAAMC,sBAAyC;IACpD;QACE,qBAAqB;QACrBC,MAAM;QACNC,MAAM;QACNC,aAAa,IAAO,CAAA;gBAClBC,UAAU;gBACVC,QAAQ;gBACRC,OAAO;YACT,CAAA;IACF;IACA;QACE,aAAa;QACbL,MAAM;QACNC,MAAM;QACNC,aAAa,IAAO,CAAA;gBAClBC,UAAU;gBACVC,QAAQ;gBACRC,OAAO;YACT,CAAA;IACF;IACA;QACE,yCAAyC;QACzCL,MAAM;QACNC,MAAM;QACNC,aAAa,IAAO,CAAA;gBAClBC,UAAU;gBACVC,QAAQ;gBACRC,OAAO;YACT,CAAA;IACF;IACA;QACE,+BAA+B;QAC/BL,MAAM;QACNC,MAAM;QACNC,aAAa,IAAO,CAAA;gBAClBC,UAAU;gBACVC,QAAQ;gBACRC,OAAO;gBACPC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;IACA;QACET,MAAM;QACNC,MAAM;QACNC,aAAaQ,CAAAA;YACX,MAAM,EAAEL,KAAK,EAAEM,UAAU,EAAE,GAAGD;YA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,MAAM;QACNC,aAAaQ,CAAAA;YACX,MAAM,EAAEkB,SAAS,EAAEC,cAAc,EAAE,GAAGnB;YAEtC,OAAO;gBACLU,QACE;gBACFC,MAAM;oBACJO;oBACAC;gBACF;YACF;QACF;IACF;IACA;QACE7B,MAAM;QACNC,MAAM;QACNC,aAAaQ,CAAAA,SAAW,CAAA;gBACtBP,UAAU;gBACVC,QAAQ;gBACRC,KAAK,EAAEK,mBAAAA,6BAAAA,OAAQL,KAAK;gBACpBC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;IACA;QACET,MAAM;QACNC,MAAM;QACNC,aAAaQ,CAAAA,SAAW,CAAA;gBACtBP,UAAU;gBACVC,QAAQ;gBACRC,KAAK,EAAEK,mBAAAA,6BAAAA,OAAQL,KAAK;gBACpBC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;IACA;QACET,MAAM;QACNC,MAAM;QACNC,aAAaQ,CAAAA,SAAW,CAAA;gBACtBP,UAAU;gBACVC,QAAQ;gBACRC,KAAK,EAAEK,mBAAAA,6BAAAA,OAAQL,KAAK;gBACpBC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;IACA;QACET,MAAM;QACNC,MAAM;QACNC,aAAaQ,CAAAA,SAAW,CAAA;gBACtBP,UAAU;gBACVC,QAAQ;gBACRC,KAAK,EAAEK,mBAAAA,6BAAAA,OAAQL,KAAK;gBACpBC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;CACD,CAAC"}
@@ -43,7 +43,10 @@ export const questionnaireEventDefinitions = [
43
43
  primary_detail: answer
44
44
  }
45
45
  };
46
- }
46
+ },
47
+ contexts: [
48
+ "distributionChannelContext"
49
+ ]
47
50
  },
48
51
  {
49
52
  name: "helpTextOpened",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/snowplow/event-definitions/questionnaire.ts"],"sourcesContent":["import { DELIMITER } from \"../constants\";\nimport { EventDefinition, ParamsType } from \"../types\";\nimport { redact } from \"./redaction\";\n\n// Questionnaire events\nexport const questionnaireEventDefinitions: EventDefinition[] = [\n {\n name: \"questionAnswered\",\n type: \"unstructured\",\n makePayload: params => {\n const { section, context } = params as ParamsType;\n const { question, answer } = redact(params as ParamsType);\n // Flatten the answer to a delimited string\n const flatAnswer = Array.isArray(answer)\n ? answer.join(DELIMITER)\n : answer;\n\n return {\n schema:\n \"iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-3\",\n data: {\n site: context.site,\n page_index: 1,\n page_name: \"quick_to_quote\",\n submitted_from: \"quick_to_quote_experiment\",\n section_name: section,\n question,\n answer: flatAnswer,\n vertical: context.vertical,\n },\n };\n },\n },\n {\n name: \"primaryDetailSelected\",\n type: \"unstructured\",\n makePayload: params => {\n const { context, answer, vertical } = params as ParamsType;\n const { site } = context;\n let verticalName = vertical || context.vertical;\n\n if (verticalName.toLowerCase().indexOf(\"landlord\") > -1) {\n verticalName =\n answer === \"residential\" ? \"Landlord\" : \"Commercial landlord\";\n }\n\n return {\n schema:\n \"iglu:com.simplybusiness/primary_detail_selected/jsonschema/1-3-0\",\n data: {\n site,\n vertical: verticalName,\n primary_detail: answer,\n },\n };\n },\n },\n {\n name: \"helpTextOpened\",\n type: \"unstructured\",\n makePayload: params => {\n const { primaryText, label, context, helpText } = params as ParamsType;\n\n return {\n schema: \"iglu:com.simplybusiness/help_text_opened/jsonschema/1-1-0\",\n data: {\n vertical: context.vertical,\n site: context.site,\n primary_text: primaryText,\n help_text: helpText,\n label,\n page_name: \"quick_to_quote\",\n },\n };\n },\n },\n {\n name: \"assumptionsButtonClicked\",\n type: \"structured\",\n makePayload: params => {\n const { source, presentationGroup } = params as ParamsType;\n\n return {\n action: source,\n category: presentationGroup,\n };\n },\n },\n {\n name: \"navButtonClicked\",\n type: \"structured\",\n makePayload: params => {\n const { label, category } = params as ParamsType;\n\n return {\n label,\n action: \"link_click\",\n category,\n };\n },\n },\n {\n name: \"manualAddressClicked\",\n type: \"structured\",\n makePayload: params => {\n const { category } = params as ParamsType;\n\n return {\n action: \"link_click\",\n category,\n label: \"Enter address manually\",\n };\n },\n },\n];\n"],"names":["DELIMITER","redact","questionnaireEventDefinitions","name","type","makePayload","params","section","context","question","answer","flatAnswer","Array","isArray","join","schema","data","site","page_index","page_name","submitted_from","section_name","vertical","verticalName","toLowerCase","indexOf","primary_detail","primaryText","label","helpText","primary_text","help_text","source","presentationGroup","action","category"],"mappings":"AAAA,SAASA,SAAS,QAAQ,eAAe;AAEzC,SAASC,MAAM,QAAQ,cAAc;AAErC,uBAAuB;AACvB,OAAO,MAAMC,gCAAmD;IAC9D;QACEC,MAAM;QACNC,MAAM;QACNC,aAAaC,CAAAA;YACX,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGF;YAC7B,MAAM,EAAEG,QAAQ,EAAEC,MAAM,EAAE,GAAGT,OAAOK;YACpC,2CAA2C;YAC3C,MAAMK,aAAaC,MAAMC,OAAO,CAACH,UAC7BA,OAAOI,IAAI,CAACd,aACZU;YAEJ,OAAO;gBACLK,QACE;gBACFC,MAAM;oBACJC,MAAMT,QAAQS,IAAI;oBAClBC,YAAY;oBACZC,WAAW;oBACXC,gBAAgB;oBAChBC,cAAcd;oBACdE;oBACAC,QAAQC;oBACRW,UAAUd,QAAQc,QAAQ;gBAC5B;YACF;QACF;IACF;IACA;QACEnB,MAAM;QACNC,MAAM;QACNC,aAAaC,CAAAA;YACX,MAAM,EAAEE,OAAO,EAAEE,MAAM,EAAEY,QAAQ,EAAE,GAAGhB;YACtC,MAAM,EAAEW,IAAI,EAAE,GAAGT;YACjB,IAAIe,eAAeD,YAAYd,QAAQc,QAAQ;YAE/C,IAAIC,aAAaC,WAAW,GAAGC,OAAO,CAAC,cAAc,CAAC,GAAG;gBACvDF,eACEb,WAAW,gBAAgB,aAAa;YAC5C;YAEA,OAAO;gBACLK,QACE;gBACFC,MAAM;oBACJC;oBACAK,UAAUC;oBACVG,gBAAgBhB;gBAClB;YACF;QACF;IACF;IACA;QACEP,MAAM;QACNC,MAAM;QACNC,aAAaC,CAAAA;YACX,MAAM,EAAEqB,WAAW,EAAEC,KAAK,EAAEpB,OAAO,EAAEqB,QAAQ,EAAE,GAAGvB;YAElD,OAAO;gBACLS,QAAQ;gBACRC,MAAM;oBACJM,UAAUd,QAAQc,QAAQ;oBAC1BL,MAAMT,QAAQS,IAAI;oBAClBa,cAAcH;oBACdI,WAAWF;oBACXD;oBACAT,WAAW;gBACb;YACF;QACF;IACF;IACA;QACEhB,MAAM;QACNC,MAAM;QACNC,aAAaC,CAAAA;YACX,MAAM,EAAE0B,MAAM,EAAEC,iBAAiB,EAAE,GAAG3B;YAEtC,OAAO;gBACL4B,QAAQF;gBACRG,UAAUF;YACZ;QACF;IACF;IACA;QACE9B,MAAM;QACNC,MAAM;QACNC,aAAaC,CAAAA;YACX,MAAM,EAAEsB,KAAK,EAAEO,QAAQ,EAAE,GAAG7B;YAE5B,OAAO;gBACLsB;gBACAM,QAAQ;gBACRC;YACF;QACF;IACF;IACA;QACEhC,MAAM;QACNC,MAAM;QACNC,aAAaC,CAAAA;YACX,MAAM,EAAE6B,QAAQ,EAAE,GAAG7B;YAErB,OAAO;gBACL4B,QAAQ;gBACRC;gBACAP,OAAO;YACT;QACF;IACF;CACD,CAAC"}
1
+ {"version":3,"sources":["../../../../src/snowplow/event-definitions/questionnaire.ts"],"sourcesContent":["import { DELIMITER } from \"../constants\";\nimport { EventDefinition, ParamsType } from \"../types\";\nimport { redact } from \"./redaction\";\n\n// Questionnaire events\nexport const questionnaireEventDefinitions: EventDefinition[] = [\n {\n name: \"questionAnswered\",\n type: \"unstructured\",\n makePayload: params => {\n const { section, context } = params as ParamsType;\n const { question, answer } = redact(params as ParamsType);\n // Flatten the answer to a delimited string\n const flatAnswer = Array.isArray(answer)\n ? answer.join(DELIMITER)\n : answer;\n\n return {\n schema:\n \"iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-3\",\n data: {\n site: context.site,\n page_index: 1,\n page_name: \"quick_to_quote\",\n submitted_from: \"quick_to_quote_experiment\",\n section_name: section,\n question,\n answer: flatAnswer,\n vertical: context.vertical,\n },\n };\n },\n },\n {\n name: \"primaryDetailSelected\",\n type: \"unstructured\",\n makePayload: params => {\n const { context, answer, vertical } = params as ParamsType;\n const { site } = context;\n let verticalName = vertical || context.vertical;\n\n if (verticalName.toLowerCase().indexOf(\"landlord\") > -1) {\n verticalName =\n answer === \"residential\" ? \"Landlord\" : \"Commercial landlord\";\n }\n\n return {\n schema:\n \"iglu:com.simplybusiness/primary_detail_selected/jsonschema/1-3-0\",\n data: {\n site,\n vertical: verticalName,\n primary_detail: answer,\n },\n };\n },\n contexts: [\"distributionChannelContext\"],\n },\n {\n name: \"helpTextOpened\",\n type: \"unstructured\",\n makePayload: params => {\n const { primaryText, label, context, helpText } = params as ParamsType;\n\n return {\n schema: \"iglu:com.simplybusiness/help_text_opened/jsonschema/1-1-0\",\n data: {\n vertical: context.vertical,\n site: context.site,\n primary_text: primaryText,\n help_text: helpText,\n label,\n page_name: \"quick_to_quote\",\n },\n };\n },\n },\n {\n name: \"assumptionsButtonClicked\",\n type: \"structured\",\n makePayload: params => {\n const { source, presentationGroup } = params as ParamsType;\n\n return {\n action: source,\n category: presentationGroup,\n };\n },\n },\n {\n name: \"navButtonClicked\",\n type: \"structured\",\n makePayload: params => {\n const { label, category } = params as ParamsType;\n\n return {\n label,\n action: \"link_click\",\n category,\n };\n },\n },\n {\n name: \"manualAddressClicked\",\n type: \"structured\",\n makePayload: params => {\n const { category } = params as ParamsType;\n\n return {\n action: \"link_click\",\n category,\n label: \"Enter address manually\",\n };\n },\n },\n];\n"],"names":["DELIMITER","redact","questionnaireEventDefinitions","name","type","makePayload","params","section","context","question","answer","flatAnswer","Array","isArray","join","schema","data","site","page_index","page_name","submitted_from","section_name","vertical","verticalName","toLowerCase","indexOf","primary_detail","contexts","primaryText","label","helpText","primary_text","help_text","source","presentationGroup","action","category"],"mappings":"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H;oBACdI,WAAWF;oBACXD;oBACAV,WAAW;gBACb;YACF;QACF;IACF;IACA;QACEhB,MAAM;QACNC,MAAM;QACNC,aAAaC,CAAAA;YACX,MAAM,EAAE2B,MAAM,EAAEC,iBAAiB,EAAE,GAAG5B;YAEtC,OAAO;gBACL6B,QAAQF;gBACRG,UAAUF;YACZ;QACF;IACF;IACA;QACE/B,MAAM;QACNC,MAAM;QACNC,aAAaC,CAAAA;YACX,MAAM,EAAEuB,KAAK,EAAEO,QAAQ,EAAE,GAAG9B;YAE5B,OAAO;gBACLuB;gBACAM,QAAQ;gBACRC;YACF;QACF;IACF;IACA;QACEjC,MAAM;QACNC,MAAM;QACNC,aAAaC,CAAAA;YACX,MAAM,EAAE8B,QAAQ,EAAE,GAAG9B;YAErB,OAAO;gBACL6B,QAAQ;gBACRC;gBACAP,OAAO;YACT;QACF;IACF;CACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/snowplow/types.ts"],"sourcesContent":["import {\n EventMethod,\n SelfDescribingJson,\n StructuredEvent,\n} from \"@snowplow/browser-tracker\";\n\ntype BaseConfig = {\n appId: string;\n avalancheCollector: string;\n eventMethod: EventMethod;\n trackPageView: boolean;\n includeGAContext: boolean;\n uid?: string;\n postPath?: string;\n};\n\nexport type EnvConfig = BaseConfig & {\n cookieDomain: Record<string, string>;\n};\n\nexport type TrackingProps = BaseConfig & {\n eventMethod: EventMethod;\n cookieDomain?: string;\n pageViewContext?: ChannelContext;\n};\n\nexport type ChannelContext = {\n schema: string;\n data: Record<string, string | number>;\n};\n\nexport type ChannelContexts = Record<string, ChannelContext>;\n\nexport type ArrayOneOrMore<T> = [T, ...T[]];\n\nexport type ParamsType = Record<string, string> & {\n context: ServerContext;\n};\n\ntype ServerContext = {\n site: string;\n vertical: string;\n primary_detail: string;\n journey_name: string;\n journey_id: string;\n};\n\nexport type LinkType = Record<string, string> & {\n targetUrl: string;\n elementContent: string;\n};\n\nexport type EventDefinition = {\n name: string;\n type: \"structured\" | \"unstructured\";\n makePayload: (\n params?: Record<string, unknown>,\n ) => StructuredEvent | SelfDescribingJson<Record<string, unknown>>;\n};\n\nexport interface PageDataProps\n extends Partial<\n Record<\n \"scripts\",\n Array<{\n metadata: { name: string };\n props?: Record<string, unknown>;\n }>\n >\n > {}\n"],"names":[],"mappings":"AA4DA,WASM"}
1
+ {"version":3,"sources":["../../../src/snowplow/types.ts"],"sourcesContent":["import {\n EventMethod,\n SelfDescribingJson,\n StructuredEvent,\n} from \"@snowplow/browser-tracker\";\n\ntype BaseConfig = {\n appId: string;\n avalancheCollector: string;\n eventMethod: EventMethod;\n trackPageView: boolean;\n includeGAContext: boolean;\n uid?: string;\n postPath?: string;\n};\n\nexport type EnvConfig = BaseConfig & {\n cookieDomain: Record<string, string>;\n};\n\nexport type TrackingProps = BaseConfig & {\n eventMethod: EventMethod;\n cookieDomain?: string;\n pageViewContext?: ChannelContext;\n};\n\nexport type ChannelContext = {\n schema: string;\n data: Record<string, string | number>;\n};\n\nexport type ChannelContexts = Record<string, ChannelContext>;\n\nexport type ArrayOneOrMore<T> = [T, ...T[]];\n\nexport type ParamsType = Record<string, string> & {\n context: ServerContext;\n};\n\ntype ServerContext = {\n site: string;\n vertical: string;\n primary_detail: string;\n journey_name: string;\n journey_id: string;\n};\n\nexport type LinkType = Record<string, string> & {\n targetUrl: string;\n elementContent: string;\n};\n\nexport type SerialisedEvent = SelfDescribingJson<Record<string, unknown>>;\n\nexport type EventDefinition = {\n name: string;\n type: \"structured\" | \"unstructured\";\n makePayload: (\n params?: Record<string, unknown>,\n ) => StructuredEvent | SerialisedEvent;\n contexts?: string[];\n};\n\nexport interface PageDataProps\n extends Partial<\n Record<\n \"scripts\",\n Array<{\n metadata: { name: string };\n props?: Record<string, unknown>;\n }>\n >\n > {}\n"],"names":[],"mappings":"AA+DA,WASM"}
@@ -10,25 +10,7 @@ declare const _default: ({
10
10
  label: "next" | "back" | "redirect";
11
11
  property: string;
12
12
  };
13
- } | {
14
- name: string;
15
- type: string;
16
- makePayload: (params: {
17
- vertical?: string;
18
- question: string;
19
- answer?: string;
20
- }) => {
21
- schema: string;
22
- data: {
23
- site: string;
24
- vertical: string;
25
- page_index: number;
26
- page_name: string;
27
- section_name: string;
28
- question: string;
29
- answer: string | undefined;
30
- };
31
- };
13
+ contexts?: undefined;
32
14
  } | {
33
15
  name: string;
34
16
  type: string;
@@ -45,6 +27,7 @@ declare const _default: ({
45
27
  vertical: string;
46
28
  };
47
29
  };
30
+ contexts: string[];
48
31
  } | {
49
32
  name: string;
50
33
  type: string;
@@ -56,6 +39,7 @@ declare const _default: ({
56
39
  primary_detail: string;
57
40
  };
58
41
  };
42
+ contexts?: undefined;
59
43
  } | {
60
44
  name: string;
61
45
  type: string;
@@ -70,5 +54,6 @@ declare const _default: ({
70
54
  page_name: string;
71
55
  };
72
56
  };
57
+ contexts?: undefined;
73
58
  })[];
74
59
  export default _default;
@@ -1,5 +1,5 @@
1
- import { SelfDescribingJson, StructuredEvent, PageViewEvent } from "@snowplow/browser-tracker";
2
- import { EventDefinition, TrackingProps } from "./types";
1
+ import { PageViewEvent, StructuredEvent } from "@snowplow/browser-tracker";
2
+ import { EventDefinition, SerialisedEvent, TrackingProps } from "./types";
3
3
  export type FrontOfficeStructuredEvent = StructuredEvent & {
4
4
  serviceChannelIdentifier: string;
5
5
  };
@@ -15,15 +15,17 @@ export declare class Snowplow {
15
15
  pvAvalancheTrackerName: string;
16
16
  uid: unknown;
17
17
  trackPageView: boolean;
18
- contexts: SelfDescribingJson<Record<string, unknown>>[];
18
+ contexts: Record<string, SerialisedEvent>;
19
+ pvContext: SerialisedEvent[];
20
+ structContext: SerialisedEvent[];
19
21
  serverData: Record<string, unknown>;
20
22
  eventHandlers: Record<string, (params?: Record<string, unknown>) => void>;
21
23
  static instance: Snowplow | undefined;
22
24
  constructor(props?: TrackingProps);
23
- setContexts(contexts: SelfDescribingJson<Record<string, unknown>>[]): this;
25
+ setContexts(contexts: Record<string, SerialisedEvent>): this;
24
26
  trackView(event?: PageViewEvent): Promise<this>;
25
27
  trackEvent(event: StructuredEvent): Promise<this>;
26
- trackUnstructEvent(event: SelfDescribingJson<Record<string, unknown>>): Promise<this>;
28
+ trackUnstructEvent(event: SerialisedEvent, contexts?: string[]): Promise<this>;
27
29
  addEventHandlers(eventDefinitions: EventDefinition[]): this;
28
30
  private addEventHandler;
29
31
  private removeEventHandler;
@@ -1,3 +1,4 @@
1
- import { SelfDescribingJson } from "@snowplow/browser-tracker";
2
- import { TrackingProps } from "./types";
3
- export declare const getContexts: (config: TrackingProps) => SelfDescribingJson<Record<string, unknown>>[];
1
+ import { SerialisedEvent, TrackingProps } from "./types";
2
+ export declare const getContexts: (config: TrackingProps) => Record<string, SerialisedEvent>;
3
+ export declare const updateIdentityContext: (contexts: Record<string, SerialisedEvent>, uid: unknown) => Record<string, SerialisedEvent>;
4
+ export declare const makeContexts: (keys: string[], config: Record<string, SerialisedEvent>) => SerialisedEvent[];
@@ -1,22 +1,2 @@
1
1
  import { EventDefinition } from "../types";
2
- /**
3
- * Event definitions for Snowplow
4
- * @type {EventDefinition[]}
5
- * @property {string} name - The name of the event, to use when triggering
6
- * @property {string} type - The type of the event (structured | unstructured)
7
- * @property {makePayload} makePayload
8
- * - Function that creates the payload for the event;
9
- * - Allows optional params object to be passed in
10
- *
11
- * @example
12
- * Parent
13
- * import { getSnowplowConfig, SnowplowProvider } from "@simplybusiness/services";
14
- * const snowplowProps = getSnowplowConfig(pageData);
15
- * <SnowplowProvider scripts={snowplowProps!}>{children}</SnowplowProvider>
16
- *
17
- * Child
18
- * import { useSnowplowContext } from "@simplybusiness/services";
19
- * const { snowplow } = useSnowplowContext();
20
- * const handlerFunction = () => snowplow?.trigger("eventNameHere");
21
- */
22
2
  export declare const qcpEventDefinitions: EventDefinition[];
@@ -36,10 +36,12 @@ export type LinkType = Record<string, string> & {
36
36
  targetUrl: string;
37
37
  elementContent: string;
38
38
  };
39
+ export type SerialisedEvent = SelfDescribingJson<Record<string, unknown>>;
39
40
  export type EventDefinition = {
40
41
  name: string;
41
42
  type: "structured" | "unstructured";
42
- makePayload: (params?: Record<string, unknown>) => StructuredEvent | SelfDescribingJson<Record<string, unknown>>;
43
+ makePayload: (params?: Record<string, unknown>) => StructuredEvent | SerialisedEvent;
44
+ contexts?: string[];
43
45
  };
44
46
  export interface PageDataProps extends Partial<Record<"scripts", Array<{
45
47
  metadata: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simplybusiness/services",
3
3
  "license": "UNLICENSED",
4
- "version": "0.20.0",
4
+ "version": "0.21.0",
5
5
  "description": "Internal library for services",
6
6
  "repository": {
7
7
  "type": "git",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@airbrake/browser": "^2.1.8",
78
- "@simplybusiness/mobius": "^5.24.1",
78
+ "@simplybusiness/mobius": "^5.24.2",
79
79
  "@snowplow/browser-tracker": "^3.24.6",
80
80
  "classnames": "^2.5.1"
81
81
  },
@@ -15,30 +15,6 @@ export default [
15
15
  };
16
16
  },
17
17
  },
18
- {
19
- name: "questionAnswered",
20
- type: "unstructured",
21
- makePayload: (params: {
22
- vertical?: string;
23
- question: string;
24
- answer?: string;
25
- }) => {
26
- const { vertical, question, answer } = params;
27
- return {
28
- schema:
29
- "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-1",
30
- data: {
31
- site: "",
32
- vertical: vertical || "business",
33
- page_index: 1,
34
- page_name: "Coverage diagnosis questionnaire",
35
- section_name: "Coverage diagnosis questionnaire",
36
- question,
37
- answer,
38
- },
39
- };
40
- },
41
- },
42
18
  {
43
19
  name: "questionAnswered",
44
20
  type: "unstructured",
@@ -61,6 +37,7 @@ export default [
61
37
  },
62
38
  };
63
39
  },
40
+ contexts: ["distributionChannelContext"],
64
41
  },
65
42
  {
66
43
  name: "primaryDetailSelected",
@@ -68,7 +45,7 @@ export default [
68
45
  makePayload: (params: ParamsType) => {
69
46
  const { context, answer, vertical } = params as ParamsType;
70
47
  const { site } = context;
71
- let verticalName = vertical ? vertical : context.vertical;
48
+ let verticalName = vertical || context.vertical;
72
49
 
73
50
  if (verticalName.toLowerCase().indexOf("landlord") > -1) {
74
51
  verticalName =
@@ -1,5 +1,5 @@
1
1
  import {
2
- SelfDescribingJson,
2
+ PageViewEvent,
3
3
  StructuredEvent,
4
4
  TrackerConfiguration,
5
5
  newTracker,
@@ -8,9 +8,9 @@ import {
8
8
  trackPageView,
9
9
  trackSelfDescribingEvent,
10
10
  trackStructEvent,
11
- PageViewEvent,
12
11
  } from "@snowplow/browser-tracker";
13
- import { EventDefinition, TrackingProps } from "./types";
12
+ import { makeContexts, updateIdentityContext } from "./contexts";
13
+ import { EventDefinition, SerialisedEvent, TrackingProps } from "./types";
14
14
 
15
15
  export type FrontOfficeStructuredEvent = StructuredEvent & {
16
16
  serviceChannelIdentifier: string;
@@ -33,7 +33,11 @@ export class Snowplow {
33
33
 
34
34
  trackPageView: boolean = false;
35
35
 
36
- contexts: SelfDescribingJson<Record<string, unknown>>[] = [];
36
+ contexts: Record<string, SerialisedEvent> = {};
37
+
38
+ pvContext: SerialisedEvent[] = [];
39
+
40
+ structContext: SerialisedEvent[] = [];
37
41
 
38
42
  serverData: Record<string, unknown> = {};
39
43
 
@@ -52,8 +56,6 @@ export class Snowplow {
52
56
  eventMethod,
53
57
  uid,
54
58
  postPath,
55
- // includeGAContext,
56
- // trackActivity,
57
59
  trackPageView: tpv,
58
60
  } = props;
59
61
  this.uid = uid;
@@ -92,22 +94,20 @@ export class Snowplow {
92
94
  Snowplow.instance = this;
93
95
  }
94
96
 
95
- setContexts(contexts: SelfDescribingJson<Record<string, unknown>>[]) {
96
- this.contexts = contexts;
97
- // Update identity context
98
- const index = this.contexts?.findIndex(ctx =>
99
- ctx.schema?.includes("identity_context"),
97
+ setContexts(contexts: Record<string, SerialisedEvent>) {
98
+ this.contexts = updateIdentityContext(contexts, this.uid);
99
+ this.pvContext = Object.values(this.contexts);
100
+ this.structContext = makeContexts(
101
+ ["distributionChannelContext", "serviceChannelContext"],
102
+ this.contexts,
100
103
  );
101
- if (index > -1) {
102
- this.contexts[index].data.domain_userid = this.uid;
103
- }
104
104
  return this;
105
105
  }
106
106
 
107
107
  // Send a page view event
108
108
  async trackView(event?: PageViewEvent) {
109
109
  if (this.trackPageView) {
110
- await trackPageView({ ...event, context: this.contexts }, [
110
+ await trackPageView({ ...event, context: this.pvContext }, [
111
111
  this.avalancheTrackerName,
112
112
  ]);
113
113
  }
@@ -116,20 +116,28 @@ export class Snowplow {
116
116
 
117
117
  // Send a structured event with contexts
118
118
  async trackEvent(event: StructuredEvent) {
119
- await trackStructEvent({ ...event, context: this.contexts }, [
119
+ await trackStructEvent({ ...event, context: this.structContext }, [
120
120
  this.bronzeAvalancheTrackerName,
121
121
  ]);
122
122
  return this;
123
123
  }
124
124
 
125
125
  // Send a custom event with defined schema and optional contexts
126
- async trackUnstructEvent(event: SelfDescribingJson<Record<string, unknown>>) {
126
+ async trackUnstructEvent(event: SerialisedEvent, contexts?: string[]) {
127
127
  if (!event) {
128
128
  return this;
129
129
  }
130
- await trackSelfDescribingEvent({ event, context: this.contexts }, [
131
- this.avalancheTrackerName,
132
- ]);
130
+
131
+ if (contexts && Array.isArray(contexts) && contexts.length > 0) {
132
+ // Add context to the event
133
+ const context = makeContexts(contexts!, this.contexts);
134
+
135
+ await trackSelfDescribingEvent({ event, context }, [
136
+ this.avalancheTrackerName,
137
+ ]);
138
+ } else {
139
+ await trackSelfDescribingEvent({ event }, [this.avalancheTrackerName]);
140
+ }
133
141
  return this;
134
142
  }
135
143
 
@@ -137,7 +145,7 @@ export class Snowplow {
137
145
  // Add server context to makePayload functions
138
146
  const context = this.serverData;
139
147
 
140
- eventDefinitions.forEach(({ name, type, makePayload }) => {
148
+ eventDefinitions.forEach(({ name, type, makePayload, contexts }) => {
141
149
  // Convert type into relevant function
142
150
  if (type === "structured") {
143
151
  this.addEventHandler(name, (params?: Record<string, unknown>) => {
@@ -150,12 +158,16 @@ export class Snowplow {
150
158
  });
151
159
  } else {
152
160
  this.addEventHandler(name, (params?: Record<string, unknown>) => {
153
- this.trackUnstructEvent(
154
- makePayload({
155
- ...params,
156
- context,
157
- }) as SelfDescribingJson<Record<string, unknown>>,
158
- );
161
+ const payload = makePayload({
162
+ ...params,
163
+ context,
164
+ }) as SerialisedEvent;
165
+
166
+ if (contexts && Array.isArray(contexts) && contexts.length > 0) {
167
+ this.trackUnstructEvent(payload, contexts);
168
+ } else {
169
+ this.trackUnstructEvent(payload);
170
+ }
159
171
  });
160
172
  }
161
173
  });
@@ -176,8 +188,13 @@ export class Snowplow {
176
188
  }
177
189
 
178
190
  trigger(name: string, params?: Record<string, unknown>) {
179
- if (this.eventHandlers[name]) {
180
- this.eventHandlers[name](params);
191
+ const handler = this.eventHandlers[name];
192
+
193
+ if (
194
+ Object.prototype.hasOwnProperty.call(this.eventHandlers, name) &&
195
+ typeof handler === "function"
196
+ ) {
197
+ handler(params);
181
198
  }
182
199
  return this;
183
200
  }