@simplybusiness/services 0.1.1
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.
- package/CHANGELOG.md +9 -0
- package/dist/cjs/data/scripts-mock.js +59 -0
- package/dist/cjs/data/scripts-mock.js.map +1 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/mocks/eventDefinitions.js +46 -0
- package/dist/cjs/mocks/eventDefinitions.js.map +1 -0
- package/dist/cjs/services/airbrake/index.js +23 -0
- package/dist/cjs/services/airbrake/index.js.map +1 -0
- package/dist/cjs/services/index.js +25 -0
- package/dist/cjs/services/index.js.map +1 -0
- package/dist/cjs/services/snowplow/SnowplowContext.js +61 -0
- package/dist/cjs/services/snowplow/SnowplowContext.js.map +1 -0
- package/dist/cjs/services/snowplow/contexts.js +18 -0
- package/dist/cjs/services/snowplow/contexts.js.map +1 -0
- package/dist/cjs/services/snowplow/event-definitions.js +235 -0
- package/dist/cjs/services/snowplow/event-definitions.js.map +1 -0
- package/dist/cjs/services/snowplow/getSnowplowConfig.js +16 -0
- package/dist/cjs/services/snowplow/getSnowplowConfig.js.map +1 -0
- package/dist/cjs/services/snowplow/index.js +138 -0
- package/dist/cjs/services/snowplow/index.js.map +1 -0
- package/dist/cjs/services/snowplow/types.js +6 -0
- package/dist/cjs/services/snowplow/types.js.map +1 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -0
- package/dist/cjs/utils/index.js +20 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/testUtils.js +43 -0
- package/dist/cjs/utils/testUtils.js.map +1 -0
- package/dist/cjs/utils/text.js +13 -0
- package/dist/cjs/utils/text.js.map +1 -0
- package/dist/esm/data/scripts-mock.js +49 -0
- package/dist/esm/data/scripts-mock.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/mocks/eventDefinitions.js +36 -0
- package/dist/esm/mocks/eventDefinitions.js.map +1 -0
- package/dist/esm/services/airbrake/index.js +13 -0
- package/dist/esm/services/airbrake/index.js.map +1 -0
- package/dist/esm/services/index.js +8 -0
- package/dist/esm/services/index.js.map +1 -0
- package/dist/esm/services/snowplow/SnowplowContext.js +43 -0
- package/dist/esm/services/snowplow/SnowplowContext.js.map +1 -0
- package/dist/esm/services/snowplow/contexts.js +8 -0
- package/dist/esm/services/snowplow/contexts.js.map +1 -0
- package/dist/esm/services/snowplow/event-definitions.js +240 -0
- package/dist/esm/services/snowplow/event-definitions.js.map +1 -0
- package/dist/esm/services/snowplow/getSnowplowConfig.js +7 -0
- package/dist/esm/services/snowplow/getSnowplowConfig.js.map +1 -0
- package/dist/esm/services/snowplow/index.js +133 -0
- package/dist/esm/services/snowplow/index.js.map +1 -0
- package/dist/esm/services/snowplow/types.js +3 -0
- package/dist/esm/services/snowplow/types.js.map +1 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/testUtils.js +26 -0
- package/dist/esm/utils/testUtils.js.map +1 -0
- package/dist/esm/utils/text.js +3 -0
- package/dist/esm/utils/text.js.map +1 -0
- package/dist/types/data/scripts-mock.d.ts +44 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mocks/eventDefinitions.d.ts +32 -0
- package/dist/types/services/airbrake/index.d.ts +2 -0
- package/dist/types/services/index.d.ts +5 -0
- package/dist/types/services/snowplow/SnowplowContext.d.ts +14 -0
- package/dist/types/services/snowplow/SnowplowContext.test.d.ts +1 -0
- package/dist/types/services/snowplow/contexts.d.ts +3 -0
- package/dist/types/services/snowplow/contexts.test.d.ts +1 -0
- package/dist/types/services/snowplow/event-definitions.d.ts +18 -0
- package/dist/types/services/snowplow/getSnowplowConfig.d.ts +2 -0
- package/dist/types/services/snowplow/index.d.ts +29 -0
- package/dist/types/services/snowplow/index.test.d.ts +1 -0
- package/dist/types/services/snowplow/types.d.ts +37 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/testUtils.d.ts +7 -0
- package/dist/types/utils/text.d.ts +1 -0
- package/dist/types/utils/text.test.d.ts +1 -0
- package/package.json +86 -0
- package/src/__mocks__/snowplowBrowserTrackerMock.js +6 -0
- package/src/data/scripts-mock.ts +44 -0
- package/src/index.tsx +1 -0
- package/src/mocks/eventDefinitions.ts +39 -0
- package/src/services/airbrake/index.ts +16 -0
- package/src/services/index.tsx +6 -0
- package/src/services/snowplow/SnowplowContext.test.tsx +32 -0
- package/src/services/snowplow/SnowplowContext.tsx +68 -0
- package/src/services/snowplow/contexts.test.ts +42 -0
- package/src/services/snowplow/contexts.ts +14 -0
- package/src/services/snowplow/event-definitions.ts +256 -0
- package/src/services/snowplow/getSnowplowConfig.ts +8 -0
- package/src/services/snowplow/index.test.ts +194 -0
- package/src/services/snowplow/index.ts +163 -0
- package/src/services/snowplow/types.ts +65 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/testUtils.tsx +36 -0
- package/src/utils/text.test.ts +9 -0
- package/src/utils/text.ts +2 -0
|
@@ -0,0 +1,240 @@
|
|
|
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
|
+
* import { Snowplow } from "./Snowplow";
|
|
13
|
+
* import { eventDefinitions } from "./event-definitions";
|
|
14
|
+
*
|
|
15
|
+
* const snowplow = new Snowplow();
|
|
16
|
+
* snowplow.addEventHandlers(eventDefinitions);
|
|
17
|
+
*/ export const eventDefinitions = [
|
|
18
|
+
{
|
|
19
|
+
name: "mobileLinkClick",
|
|
20
|
+
type: "structured",
|
|
21
|
+
makePayload: ()=>({
|
|
22
|
+
category: "marketing",
|
|
23
|
+
action: "link-click",
|
|
24
|
+
label: "mobile_call_button",
|
|
25
|
+
property: window.location.href
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "operatingHoursClick",
|
|
30
|
+
type: "unstructured",
|
|
31
|
+
makePayload: ()=>({
|
|
32
|
+
schema: "iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",
|
|
33
|
+
data: {
|
|
34
|
+
schema: "iglu:com.simplybusiness/operating_hours_clicked/jsonschema/1-0-2",
|
|
35
|
+
data: {}
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
// QDP details button
|
|
41
|
+
name: "detailsClicked",
|
|
42
|
+
type: "structured",
|
|
43
|
+
makePayload: ()=>({
|
|
44
|
+
category: "comparison_cta",
|
|
45
|
+
action: "link_click",
|
|
46
|
+
label: "Details"
|
|
47
|
+
})
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
// Buy button
|
|
51
|
+
name: "selectClicked",
|
|
52
|
+
type: "structured",
|
|
53
|
+
makePayload: ()=>({
|
|
54
|
+
category: "comparison_cta",
|
|
55
|
+
action: "link_click",
|
|
56
|
+
label: "Select"
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
// Quote Details Slider Next steps button
|
|
61
|
+
name: "nextStepsClicked",
|
|
62
|
+
type: "structured",
|
|
63
|
+
makePayload: ()=>({
|
|
64
|
+
category: "quote_details_slider_next_step_cta",
|
|
65
|
+
action: "link_click",
|
|
66
|
+
label: "Next steps"
|
|
67
|
+
})
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
// Toggle deductibles accordion
|
|
71
|
+
name: "deductiblesClicked",
|
|
72
|
+
type: "structured",
|
|
73
|
+
makePayload: ()=>({
|
|
74
|
+
category: "us-qcp-react",
|
|
75
|
+
action: "view_deductables_clicked",
|
|
76
|
+
label: "view_deductables_clicked",
|
|
77
|
+
property: window.location.href
|
|
78
|
+
})
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "deductiblesClickedUk",
|
|
82
|
+
type: "structured",
|
|
83
|
+
makePayload: (params)=>{
|
|
84
|
+
const { label, deviceType } = params;
|
|
85
|
+
const urlFriendlyLabel = label.replace(/ /g, "-").toLowerCase();
|
|
86
|
+
return {
|
|
87
|
+
category: `uk-qcp-react-${deviceType}-${urlFriendlyLabel}-view-excess-toggle`,
|
|
88
|
+
action: "view_excess_clicked",
|
|
89
|
+
label,
|
|
90
|
+
property: window.location.href
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
// Quote Details Slider opened
|
|
96
|
+
name: "sliderOpened",
|
|
97
|
+
type: "structured",
|
|
98
|
+
makePayload: (params)=>{
|
|
99
|
+
const { label } = params;
|
|
100
|
+
return {
|
|
101
|
+
category: "comparison_cta",
|
|
102
|
+
action: "quote_details_slider_opened",
|
|
103
|
+
label
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
// Coverage modal opened
|
|
109
|
+
name: "coverageModalOpened",
|
|
110
|
+
type: "structured",
|
|
111
|
+
makePayload: (params)=>{
|
|
112
|
+
const { category, product = "extra_coverage", title } = params;
|
|
113
|
+
const productLabel = snakeCase(product);
|
|
114
|
+
return {
|
|
115
|
+
category,
|
|
116
|
+
action: `${productLabel}_${snakeCase(title)}_popup_opened`,
|
|
117
|
+
label: productLabel,
|
|
118
|
+
property: window.location.href
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
// Toggle cover select
|
|
124
|
+
name: "coverChanged",
|
|
125
|
+
type: "unstructured",
|
|
126
|
+
makePayload: (params)=>{
|
|
127
|
+
const { name = "", fromValue = "", toValue = "" } = params;
|
|
128
|
+
// Derive data
|
|
129
|
+
let action = "change";
|
|
130
|
+
// This logic is taken directly from Chopin without documentation:
|
|
131
|
+
// If a cover has zero value, then change the action to add or remove
|
|
132
|
+
if (fromValue === "0") {
|
|
133
|
+
action = "add";
|
|
134
|
+
}
|
|
135
|
+
if (toValue === "0") {
|
|
136
|
+
action = "remove";
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
schema: "iglu:com.simplybusiness/comparison_page_cover_changed/jsonschema/1-0-0",
|
|
140
|
+
data: {
|
|
141
|
+
name,
|
|
142
|
+
action,
|
|
143
|
+
from_value: fromValue,
|
|
144
|
+
to_value: toValue
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "ratingsModalOpened",
|
|
151
|
+
type: "structured",
|
|
152
|
+
makePayload: (params)=>{
|
|
153
|
+
const { category, label } = params;
|
|
154
|
+
return {
|
|
155
|
+
category,
|
|
156
|
+
action: "insurer_rating_help_popup_triggered",
|
|
157
|
+
label,
|
|
158
|
+
property: window.location.href
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "coverToggleOpened",
|
|
164
|
+
type: "structured",
|
|
165
|
+
makePayload: ()=>({
|
|
166
|
+
category: "qcp_limit_interaction",
|
|
167
|
+
label: "limit_interaction",
|
|
168
|
+
action: "limit_interaction_clicked",
|
|
169
|
+
property: window.location.href
|
|
170
|
+
})
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: "paymentToggleClicked",
|
|
174
|
+
type: "structured",
|
|
175
|
+
makePayload: (params)=>{
|
|
176
|
+
const { category, label } = params;
|
|
177
|
+
return {
|
|
178
|
+
category,
|
|
179
|
+
action: "button_click",
|
|
180
|
+
label,
|
|
181
|
+
property: window.location.href
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: "insurerDetailsAccordionClicked",
|
|
187
|
+
type: "structured",
|
|
188
|
+
makePayload: ()=>({
|
|
189
|
+
category: "quote_details_slider_insurer_details_description",
|
|
190
|
+
action: "accordion_clicked",
|
|
191
|
+
label: "accordion_clicked",
|
|
192
|
+
property: window.location.href
|
|
193
|
+
})
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: "priceDetailsPopUpOpened",
|
|
197
|
+
type: "structured",
|
|
198
|
+
makePayload: ()=>({
|
|
199
|
+
category: "price_details",
|
|
200
|
+
action: "price_details_popup_opened",
|
|
201
|
+
label: "Price details",
|
|
202
|
+
property: window.location.href
|
|
203
|
+
})
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name: "editLimitButtonClicked",
|
|
207
|
+
type: "structured",
|
|
208
|
+
makePayload: ()=>({
|
|
209
|
+
category: "cover_limit_changes",
|
|
210
|
+
action: "edit_limit_button_clicked",
|
|
211
|
+
label: "Edit Limit",
|
|
212
|
+
property: window.location.href
|
|
213
|
+
})
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
name: "applyButtonClicked",
|
|
217
|
+
type: "structured",
|
|
218
|
+
makePayload: ()=>({
|
|
219
|
+
category: "cover_limit_changes",
|
|
220
|
+
action: "apply_button_clicked",
|
|
221
|
+
label: "Apply Button Clicked",
|
|
222
|
+
property: window.location.href
|
|
223
|
+
})
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: "coverageInfoClicked",
|
|
227
|
+
type: "structured",
|
|
228
|
+
makePayload: (params)=>{
|
|
229
|
+
const { deviceType } = params;
|
|
230
|
+
return {
|
|
231
|
+
action: "show_coverage_info_clicked",
|
|
232
|
+
category: `uk-qcp-react-${deviceType}-show-coverage-info-toggle`,
|
|
233
|
+
label: "show_coverage_info_clicked",
|
|
234
|
+
property: window.location.href
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
//# sourceMappingURL=event-definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/services/snowplow/event-definitions.ts"],"sourcesContent":["import { EventDefinition, ParamsType } from \"./types\";\nimport { snakeCase } from \"../../utils\";\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 * import { Snowplow } from \"./Snowplow\";\n * import { eventDefinitions } from \"./event-definitions\";\n *\n * const snowplow = new Snowplow();\n * snowplow.addEventHandlers(eventDefinitions);\n */\nexport const eventDefinitions: EventDefinition[] = [\n {\n name: \"mobileLinkClick\",\n type: \"structured\",\n makePayload: () => ({\n category: \"marketing\",\n action: \"link-click\",\n label: \"mobile_call_button\",\n property: window.location.href,\n }),\n },\n {\n name: \"operatingHoursClick\",\n type: \"unstructured\",\n makePayload: () => ({\n schema:\n \"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0\",\n data: {\n schema:\n \"iglu:com.simplybusiness/operating_hours_clicked/jsonschema/1-0-2\",\n data: {},\n },\n }),\n },\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: \"Select\",\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"],"names":["snakeCase","eventDefinitions","name","type","makePayload","category","action","label","property","window","location","href","schema","data","params","deviceType","urlFriendlyLabel","replace","toLowerCase","product","title","productLabel","fromValue","toValue","from_value","to_value"],"mappings":"AACA,SAASA,SAAS,QAAQ,cAAc;AAExC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAMC,mBAAsC;IACjD;QACEC,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,aAAa,IAAO,CAAA;gBAClBQ,QACE;gBACFC,MAAM;oBACJD,QACE;oBACFC,MAAM,CAA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ACC,IAAI;YAChC,CAAA;IACF;IACA;QACET,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,aAAa,IAAO,CAAA;gBAClBC,UAAU;gBACVC,QAAQ;gBACRC,OAAO;gBACPC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;IACA;QACET,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,aAAaU,CAAAA;YACX,MAAM,EAAEC,UAAU,EAAE,GAAGD;YAEvB,OAAO;gBACLR,QAAQ;gBACRD,UAAU,CAAC,aAAa,EAAEU,WAAW,0BAA0B,CAAC;gBAChER,OAAO;gBACPC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC;QACF;IACF;CACD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Get Snowplow config from page data props
|
|
2
|
+
export const getSnowplowConfig = (pageData)=>{
|
|
3
|
+
var _pageData_scripts_find, _pageData_scripts;
|
|
4
|
+
return (_pageData_scripts = pageData.scripts) === null || _pageData_scripts === void 0 ? void 0 : (_pageData_scripts_find = _pageData_scripts.find(({ metadata })=>metadata.name === "snowplow")) === null || _pageData_scripts_find === void 0 ? void 0 : _pageData_scripts_find.props;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=getSnowplowConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/services/snowplow/getSnowplowConfig.ts"],"sourcesContent":["import type { TrackingProps, PageDataProps } from \"./types\";\n\n// Get Snowplow config from page data props\nexport const getSnowplowConfig = (\n pageData: PageDataProps,\n): TrackingProps | undefined =>\n pageData.scripts?.find(({ metadata }) => metadata.name === \"snowplow\")\n ?.props as TrackingProps;\n"],"names":["getSnowplowConfig","pageData","scripts","find","metadata","name","props"],"mappings":"AAEA,2CAA2C;AAC3C,OAAO,MAAMA,oBAAoB,CAC/BC;QAEAA,wBAAAA;YAAAA,oBAAAA,SAASC,OAAO,cAAhBD,yCAAAA,yBAAAA,kBAAkBE,IAAI,CAAC,CAAC,EAAEC,QAAQ,EAAE,GAAKA,SAASC,IAAI,KAAK,yBAA3DJ,6CAAAA,uBACIK,KAAK;EAAkB"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import { newTracker, setCookiePath, setUserId, trackPageView, trackSelfDescribingEvent, trackStructEvent } from "@snowplow/browser-tracker";
|
|
15
|
+
/**
|
|
16
|
+
* This class is an abstraction which wraps Snowplow
|
|
17
|
+
* and exposes common methods with other services:
|
|
18
|
+
* - trackEvent : sends a standard payload
|
|
19
|
+
* - trackUnstructEvent : sends a payload for custom schema
|
|
20
|
+
*/ export class Snowplow {
|
|
21
|
+
setContexts(contexts) {
|
|
22
|
+
var _this_contexts;
|
|
23
|
+
this.contexts = contexts;
|
|
24
|
+
// Update identity context
|
|
25
|
+
const index = (_this_contexts = this.contexts) === null || _this_contexts === void 0 ? void 0 : _this_contexts.findIndex((ctx)=>{
|
|
26
|
+
var _ctx_schema;
|
|
27
|
+
return (_ctx_schema = ctx.schema) === null || _ctx_schema === void 0 ? void 0 : _ctx_schema.includes("identity_context");
|
|
28
|
+
});
|
|
29
|
+
if (index > -1) {
|
|
30
|
+
this.contexts[index].data.domain_userid = this.uid;
|
|
31
|
+
}
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
// Send a page view event
|
|
35
|
+
trackView() {
|
|
36
|
+
if (this.trackPageView) {
|
|
37
|
+
trackPageView({
|
|
38
|
+
context: this.contexts
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
// Send a structured event with contexts
|
|
44
|
+
async trackEvent(event) {
|
|
45
|
+
await trackStructEvent({
|
|
46
|
+
...event,
|
|
47
|
+
context: this.contexts
|
|
48
|
+
}, [
|
|
49
|
+
this.bronzeAvalancheTrackerName
|
|
50
|
+
]);
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
// Send a custom event with defined schema and optional contexts
|
|
54
|
+
async trackUnstructEvent(event) {
|
|
55
|
+
if (!event) {
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
await trackSelfDescribingEvent({
|
|
59
|
+
event,
|
|
60
|
+
context: this.contexts
|
|
61
|
+
}, [
|
|
62
|
+
this.avalancheTrackerName
|
|
63
|
+
]);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
addEventHandlers(eventDefinitions) {
|
|
67
|
+
eventDefinitions.forEach(({ name, type, makePayload })=>{
|
|
68
|
+
// Convert type into relevant function
|
|
69
|
+
if (type === "structured") {
|
|
70
|
+
this.addEventHandler(name, (params)=>{
|
|
71
|
+
this.trackEvent(makePayload(params));
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
this.addEventHandler(name, (params)=>{
|
|
75
|
+
this.trackUnstructEvent(makePayload(params));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
addEventHandler(name, handler) {
|
|
82
|
+
this.eventHandlers[name] = handler;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
removeEventHandler(name) {
|
|
86
|
+
delete this.eventHandlers[name];
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
trigger(name, params) {
|
|
90
|
+
if (this.eventHandlers[name]) {
|
|
91
|
+
this.eventHandlers[name](params);
|
|
92
|
+
}
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
constructor(props){
|
|
96
|
+
_define_property(this, "avalancheTrackerName", "sb-ava");
|
|
97
|
+
_define_property(this, "bronzeAvalancheTrackerName", "sb-ava-br");
|
|
98
|
+
_define_property(this, "pvAvalancheTrackerName", "sb-ava-pv");
|
|
99
|
+
_define_property(this, "uid", "");
|
|
100
|
+
_define_property(this, "trackPageView", false);
|
|
101
|
+
_define_property(this, "contexts", []);
|
|
102
|
+
_define_property(this, "eventHandlers", {});
|
|
103
|
+
if (!props) return;
|
|
104
|
+
const { appId, cookieDomain, avalancheCollector, eventMethod, uid, postPath, // includeGAContext,
|
|
105
|
+
// trackActivity,
|
|
106
|
+
trackPageView: tpv } = props;
|
|
107
|
+
this.uid = uid;
|
|
108
|
+
this.trackPageView = tpv;
|
|
109
|
+
// Set options
|
|
110
|
+
const stateStorageStrategy = "cookieAndLocalStorage";
|
|
111
|
+
const baseOptions = {
|
|
112
|
+
appId,
|
|
113
|
+
cookieDomain,
|
|
114
|
+
eventMethod,
|
|
115
|
+
stateStorageStrategy,
|
|
116
|
+
postPath
|
|
117
|
+
};
|
|
118
|
+
// Initialize trackers
|
|
119
|
+
newTracker(this.avalancheTrackerName, avalancheCollector, baseOptions);
|
|
120
|
+
newTracker(this.bronzeAvalancheTrackerName, avalancheCollector, baseOptions);
|
|
121
|
+
// Page view tracker
|
|
122
|
+
newTracker(this.pvAvalancheTrackerName, avalancheCollector, {
|
|
123
|
+
...baseOptions,
|
|
124
|
+
eventMethod: eventMethod === "post" ? "beacon" : eventMethod
|
|
125
|
+
});
|
|
126
|
+
setCookiePath("/");
|
|
127
|
+
if (uid) {
|
|
128
|
+
setUserId(uid);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/services/snowplow/index.ts"],"sourcesContent":["import {\n SelfDescribingJson,\n StructuredEvent,\n TrackerConfiguration,\n newTracker,\n setCookiePath,\n setUserId,\n trackPageView,\n trackSelfDescribingEvent,\n trackStructEvent,\n} from \"@snowplow/browser-tracker\";\nimport { EventDefinition, TrackingProps } from \"./types\";\n\nexport type FrontOfficeStructuredEvent = StructuredEvent & {\n serviceChannelIdentifier: string;\n};\n\n/**\n * This class is an abstraction which wraps Snowplow\n * and exposes common methods with other services:\n * - trackEvent : sends a standard payload\n * - trackUnstructEvent : sends a payload for custom schema\n */\nexport class Snowplow {\n avalancheTrackerName = \"sb-ava\";\n\n bronzeAvalancheTrackerName = \"sb-ava-br\";\n\n pvAvalancheTrackerName = \"sb-ava-pv\";\n\n uid: unknown = \"\";\n\n trackPageView: boolean = false;\n\n contexts: SelfDescribingJson<Record<string, unknown>>[] = [];\n\n eventHandlers: Record<string, (params?: Record<string, unknown>) => void> =\n {};\n\n constructor(props?: TrackingProps) {\n if (!props) return;\n\n const {\n appId,\n cookieDomain,\n avalancheCollector,\n eventMethod,\n uid,\n postPath,\n // includeGAContext,\n // trackActivity,\n trackPageView: tpv,\n } = props;\n this.uid = uid;\n this.trackPageView = tpv;\n\n // Set options\n const stateStorageStrategy = \"cookieAndLocalStorage\";\n const baseOptions: TrackerConfiguration = {\n appId,\n cookieDomain,\n eventMethod,\n stateStorageStrategy,\n postPath,\n };\n // Initialize trackers\n newTracker(this.avalancheTrackerName, avalancheCollector, baseOptions);\n\n newTracker(\n this.bronzeAvalancheTrackerName,\n avalancheCollector,\n baseOptions,\n );\n\n // Page view tracker\n newTracker(this.pvAvalancheTrackerName, avalancheCollector, {\n ...baseOptions,\n eventMethod: eventMethod === \"post\" ? \"beacon\" : eventMethod,\n });\n\n setCookiePath(\"/\");\n if (uid) {\n setUserId(uid);\n }\n }\n\n setContexts(contexts: SelfDescribingJson<Record<string, unknown>>[]) {\n this.contexts = contexts;\n // Update identity context\n const index = this.contexts?.findIndex(ctx =>\n ctx.schema?.includes(\"identity_context\"),\n );\n if (index > -1) {\n this.contexts[index].data.domain_userid = this.uid;\n }\n return this;\n }\n\n // Send a page view event\n trackView() {\n if (this.trackPageView) {\n trackPageView({ context: this.contexts });\n }\n return this;\n }\n\n // Send a structured event with contexts\n async trackEvent(event: StructuredEvent) {\n await trackStructEvent({ ...event, context: this.contexts }, [\n this.bronzeAvalancheTrackerName,\n ]);\n return this;\n }\n\n // Send a custom event with defined schema and optional contexts\n async trackUnstructEvent(event: SelfDescribingJson<Record<string, unknown>>) {\n if (!event) {\n return this;\n }\n await trackSelfDescribingEvent({ event, context: this.contexts }, [\n this.avalancheTrackerName,\n ]);\n return this;\n }\n\n addEventHandlers(eventDefinitions: EventDefinition[]) {\n eventDefinitions.forEach(({ name, type, makePayload }) => {\n // Convert type into relevant function\n if (type === \"structured\") {\n this.addEventHandler(name, (params?: Record<string, unknown>) => {\n this.trackEvent(makePayload(params) as StructuredEvent);\n });\n } else {\n this.addEventHandler(name, (params?: Record<string, unknown>) => {\n this.trackUnstructEvent(\n makePayload(params) as SelfDescribingJson<Record<string, unknown>>,\n );\n });\n }\n });\n return this;\n }\n\n private addEventHandler(\n name: string,\n handler: (params?: Record<string, unknown>) => void,\n ) {\n this.eventHandlers[name] = handler;\n return this;\n }\n\n private removeEventHandler(name: string) {\n delete this.eventHandlers[name];\n return this;\n }\n\n trigger(name: string, params?: Record<string, unknown>) {\n if (this.eventHandlers[name]) {\n this.eventHandlers[name](params);\n }\n return this;\n }\n}\n"],"names":["newTracker","setCookiePath","setUserId","trackPageView","trackSelfDescribingEvent","trackStructEvent","Snowplow","setContexts","contexts","index","findIndex","ctx","schema","includes","data","domain_userid","uid","trackView","context","trackEvent","event","bronzeAvalancheTrackerName","trackUnstructEvent","avalancheTrackerName","addEventHandlers","eventDefinitions","forEach","name","type","makePayload","addEventHandler","params","handler","eventHandlers","removeEventHandler","trigger","constructor","props","pvAvalancheTrackerName","appId","cookieDomain","avalancheCollector","eventMethod","postPath","tpv","stateStorageStrategy","baseOptions"],"mappings":";;;;;;;;;;;;;AAAA,SAIEA,UAAU,EACVC,aAAa,EACbC,SAAS,EACTC,aAAa,EACbC,wBAAwB,EACxBC,gBAAgB,QACX,4BAA4B;AAOnC;;;;;CAKC,GACD,OAAO,MAAMC;IA+DXC,YAAYC,QAAuD,EAAE;YAGrD;QAFd,IAAI,CAACA,QAAQ,GAAGA;QAChB,0BAA0B;QAC1B,MAAMC,SAAQ,iBAAA,IAAI,CAACD,QAAQ,cAAb,qCAAA,eAAeE,SAAS,CAACC,CAAAA;gBACrCA;oBAAAA,cAAAA,IAAIC,MAAM,cAAVD,kCAAAA,YAAYE,QAAQ,CAAC;;QAEvB,IAAIJ,QAAQ,CAAC,GAAG;YACd,IAAI,CAACD,QAAQ,CAACC,MAAM,CAACK,IAAI,CAACC,aAAa,GAAG,IAAI,CAACC,GAAG;QACpD;QACA,OAAO,IAAI;IACb;IAEA,yBAAyB;IACzBC,YAAY;QACV,IAAI,IAAI,CAACd,aAAa,EAAE;YACtBA,cAAc;gBAAEe,SAAS,IAAI,CAACV,QAAQ;YAAC;QACzC;QACA,OAAO,IAAI;IACb;IAEA,wCAAwC;IACxC,MAAMW,WAAWC,KAAsB,EAAE;QACvC,MAAMf,iBAAiB;YAAE,GAAGe,KAAK;YAAEF,SAAS,IAAI,CAACV,QAAQ;QAAC,GAAG;YAC3D,IAAI,CAACa,0BAA0B;SAChC;QACD,OAAO,IAAI;IACb;IAEA,gEAAgE;IAChE,MAAMC,mBAAmBF,KAAkD,EAAE;QAC3E,IAAI,CAACA,OAAO;YACV,OAAO,IAAI;QACb;QACA,MAAMhB,yBAAyB;YAAEgB;YAAOF,SAAS,IAAI,CAACV,QAAQ;QAA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;QACX,IAAI,CAACb,aAAa,GAAGyC;QAErB,cAAc;QACd,MAAMC,uBAAuB;QAC7B,MAAMC,cAAoC;YACxCP;YACAC;YACAE;YACAG;YACAF;QACF;QACA,sBAAsB;QACtB3C,WAAW,IAAI,CAACuB,oBAAoB,EAAEkB,oBAAoBK;QAE1D9C,WACE,IAAI,CAACqB,0BAA0B,EAC/BoB,oBACAK;QAGF,oBAAoB;QACpB9C,WAAW,IAAI,CAACsC,sBAAsB,EAAEG,oBAAoB;YAC1D,GAAGK,WAAW;YACdJ,aAAaA,gBAAgB,SAAS,WAAWA;QACnD;QAEAzC,cAAc;QACd,IAAIe,KAAK;YACPd,UAAUc;QACZ;IACF;AA8EF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/services/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};\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<\n | \"label\"\n | \"deviceType\"\n | \"category\"\n | \"product\"\n | \"title\"\n | \"label\"\n | \"name\"\n | \"fromValue\"\n | \"toValue\",\n 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":"AAuDA,WASM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/index.ts"],"sourcesContent":["export * from \"./text\";\n"],"names":[],"mappings":"AAAA,cAAc,SAAS"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */ import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { pageData } from "../data/scripts-mock";
|
|
4
|
+
import { SnowplowProvider } from "../services/snowplow/SnowplowContext";
|
|
5
|
+
import { getSnowplowConfig } from "../services/snowplow/getSnowplowConfig";
|
|
6
|
+
// Snowplow analytics
|
|
7
|
+
const snowplowProps = getSnowplowConfig(pageData);
|
|
8
|
+
const ProvidersMock = ({ children })=>/*#__PURE__*/ _jsx(SnowplowProvider, {
|
|
9
|
+
scripts: snowplowProps,
|
|
10
|
+
children: children
|
|
11
|
+
});
|
|
12
|
+
export const renderWithProviders = (ui, options)=>render(ui, {
|
|
13
|
+
wrapper: ProvidersMock,
|
|
14
|
+
...options
|
|
15
|
+
});
|
|
16
|
+
// Mocks window.location for url testing
|
|
17
|
+
export const mockLocation = ({ origin = "https://simplybusiness.co.uk", pathname = "" })=>Object.defineProperty(window, "location", {
|
|
18
|
+
get () {
|
|
19
|
+
return {
|
|
20
|
+
origin,
|
|
21
|
+
pathname
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=testUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/testUtils.tsx"],"sourcesContent":["/* eslint-disable import/no-extraneous-dependencies */\nimport { RenderOptions, render } from \"@testing-library/react\";\nimport { ReactElement, ReactNode } from \"react\";\nimport { pageData } from \"../data/scripts-mock\";\nimport { SnowplowProvider } from \"../services/snowplow/SnowplowContext\";\nimport { getSnowplowConfig } from \"../services/snowplow/getSnowplowConfig\";\nimport { PageDataProps } from \"../services/snowplow/types\";\n\n// Snowplow analytics\nconst snowplowProps = getSnowplowConfig(pageData as PageDataProps);\n\nconst ProvidersMock = ({ children }: { children: ReactNode }) => (\n <SnowplowProvider scripts={snowplowProps!}>{children}</SnowplowProvider>\n);\n\nexport const renderWithProviders = (\n ui: ReactElement,\n options?: RenderOptions,\n) => render(ui, { wrapper: ProvidersMock, ...options });\n\n// Mocks window.location for url testing\nexport const mockLocation = ({\n origin = \"https://simplybusiness.co.uk\",\n pathname = \"\",\n}: {\n origin?: string;\n pathname?: string;\n}) =>\n Object.defineProperty(window, \"location\", {\n get() {\n return {\n origin,\n pathname,\n };\n },\n });\n"],"names":["render","pageData","SnowplowProvider","getSnowplowConfig","snowplowProps","ProvidersMock","children","scripts","renderWithProviders","ui","options","wrapper","mockLocation","origin","pathname","Object","defineProperty","window","get"],"mappings":"AAAA,oDAAoD;AACpD,SAAwBA,MAAM,QAAQ,yBAAyB;AAE/D,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,gBAAgB,QAAQ,uCAAuC;AACxE,SAASC,iBAAiB,QAAQ,yCAAyC;AAG3E,qBAAqB;AACrB,MAAMC,gBAAgBD,kBAAkBF;AAExC,MAAMI,gBAAgB,CAAC,EAAEC,QAAQ,EAA2B,iBAC1D,KAACJ;QAAiBK,SAASH;kBAAiBE;;AAG9C,OAAO,MAAME,sBAAsB,CACjCC,IACAC,UACGV,OAAOS,IAAI;QAAEE,SAASN;QAAe,GAAGK,OAAO;IAAC,GAAG;AAExD,wCAAwC;AACxC,OAAO,MAAME,eAAe,CAAC,EAC3BC,SAAS,8BAA8B,EACvCC,WAAW,EAAE,EAId,GACCC,OAAOC,cAAc,CAACC,QAAQ,YAAY;QACxCC;YACE,OAAO;gBACLL;gBACAC;YACF;QACF;IACF,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/text.ts"],"sourcesContent":["export const snakeCase = (text = \"\"): string =>\n text.toLowerCase().replace(/ /g, \"_\");\n"],"names":["snakeCase","text","toLowerCase","replace"],"mappings":"AAAA,OAAO,MAAMA,YAAY,CAACC,OAAO,EAAE,GACjCA,KAAKC,WAAW,GAAGC,OAAO,CAAC,MAAM,KAAK"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare const pageData: {
|
|
2
|
+
scripts: {
|
|
3
|
+
metadata: {
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
props: {
|
|
7
|
+
uid: string;
|
|
8
|
+
cookieDomain: string;
|
|
9
|
+
avalancheCollector: string;
|
|
10
|
+
appId: string;
|
|
11
|
+
includeGAContext: boolean;
|
|
12
|
+
eventMethod: string;
|
|
13
|
+
postPath: string;
|
|
14
|
+
trackActivity: boolean;
|
|
15
|
+
trackPageView: boolean;
|
|
16
|
+
pageViewContext: {
|
|
17
|
+
schema: string;
|
|
18
|
+
data: {
|
|
19
|
+
site: string;
|
|
20
|
+
vertical: string;
|
|
21
|
+
super_segment: string;
|
|
22
|
+
primary_detail: string;
|
|
23
|
+
journey_name: string;
|
|
24
|
+
journey_id: string;
|
|
25
|
+
page_step_name: string;
|
|
26
|
+
page_step_depth: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
distributionChannelContext: {
|
|
30
|
+
schema: string;
|
|
31
|
+
data: {
|
|
32
|
+
service_channel_identifier: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
serviceChannelContext: {
|
|
36
|
+
schema: string;
|
|
37
|
+
data: {
|
|
38
|
+
service_channel_identifier: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
forceSecureTracker: boolean;
|
|
42
|
+
};
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./services";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare const _default: ({
|
|
2
|
+
name: string;
|
|
3
|
+
type: string;
|
|
4
|
+
makePayload: (params: {
|
|
5
|
+
label: "next" | "back" | "redirect";
|
|
6
|
+
}) => {
|
|
7
|
+
category: string;
|
|
8
|
+
action: string;
|
|
9
|
+
label: "next" | "back" | "redirect";
|
|
10
|
+
property: string;
|
|
11
|
+
};
|
|
12
|
+
} | {
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
makePayload: (params: {
|
|
16
|
+
vertical?: string;
|
|
17
|
+
question: string;
|
|
18
|
+
answer?: string;
|
|
19
|
+
}) => {
|
|
20
|
+
schema: string;
|
|
21
|
+
data: {
|
|
22
|
+
site: string;
|
|
23
|
+
vertical: string;
|
|
24
|
+
page_index: number;
|
|
25
|
+
page_name: string;
|
|
26
|
+
section_name: string;
|
|
27
|
+
question: string;
|
|
28
|
+
answer: string | undefined;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
})[];
|
|
32
|
+
export default _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { Snowplow } from ".";
|
|
3
|
+
import { TrackingProps } from "./types";
|
|
4
|
+
export interface SnowplowContextInterface {
|
|
5
|
+
config: TrackingProps;
|
|
6
|
+
snowplow?: Snowplow;
|
|
7
|
+
}
|
|
8
|
+
type ProviderProps = {
|
|
9
|
+
scripts: TrackingProps;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
export declare const SnowplowProvider: ({ scripts, children }: ProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function useSnowplowContext(): SnowplowContextInterface;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
* import { Snowplow } from "./Snowplow";
|
|
13
|
+
* import { eventDefinitions } from "./event-definitions";
|
|
14
|
+
*
|
|
15
|
+
* const snowplow = new Snowplow();
|
|
16
|
+
* snowplow.addEventHandlers(eventDefinitions);
|
|
17
|
+
*/
|
|
18
|
+
export declare const eventDefinitions: EventDefinition[];
|