@simplybusiness/services 0.1.2 → 0.1.4
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 +16 -0
- package/dist/cjs/services/index.js +0 -4
- package/dist/cjs/services/index.js.map +1 -1
- package/dist/cjs/services/snowplow/Snowplow.js +138 -0
- package/dist/cjs/services/snowplow/Snowplow.js.map +1 -0
- package/dist/cjs/services/snowplow/SnowplowContext.js +2 -2
- package/dist/cjs/services/snowplow/SnowplowContext.js.map +1 -1
- package/dist/cjs/services/snowplow/event-definitions/base.js +37 -0
- package/dist/cjs/services/snowplow/event-definitions/base.js.map +1 -0
- package/dist/cjs/services/snowplow/event-definitions/index.js +31 -0
- package/dist/cjs/services/snowplow/event-definitions/index.js.map +1 -0
- package/dist/cjs/services/snowplow/{event-definitions.js → event-definitions/qcp.js} +5 -26
- package/dist/cjs/services/snowplow/event-definitions/qcp.js.map +1 -0
- package/dist/cjs/services/snowplow/index.js +16 -129
- package/dist/cjs/services/snowplow/index.js.map +1 -1
- package/dist/esm/services/index.js +0 -4
- package/dist/esm/services/index.js.map +1 -1
- package/dist/esm/services/snowplow/Snowplow.js +133 -0
- package/dist/esm/services/snowplow/Snowplow.js.map +1 -0
- package/dist/esm/services/snowplow/SnowplowContext.js +1 -1
- package/dist/esm/services/snowplow/SnowplowContext.js.map +1 -1
- package/dist/esm/services/snowplow/event-definitions/base.js +43 -0
- package/dist/esm/services/snowplow/event-definitions/base.js.map +1 -0
- package/dist/esm/services/snowplow/event-definitions/index.js +14 -0
- package/dist/esm/services/snowplow/event-definitions/index.js.map +1 -0
- package/dist/esm/services/snowplow/{event-definitions.js → event-definitions/qcp.js} +4 -24
- package/dist/esm/services/snowplow/event-definitions/qcp.js.map +1 -0
- package/dist/esm/services/snowplow/index.js +6 -131
- package/dist/esm/services/snowplow/index.js.map +1 -1
- package/dist/types/services/index.d.ts +0 -3
- package/dist/types/services/snowplow/Snowplow.d.ts +29 -0
- package/dist/types/services/snowplow/SnowplowContext.d.ts +1 -1
- package/dist/types/services/snowplow/event-definitions/base.d.ts +18 -0
- package/dist/types/services/snowplow/event-definitions/index.d.ts +2 -0
- package/dist/types/services/snowplow/{event-definitions.d.ts → event-definitions/qcp.d.ts} +2 -2
- package/dist/types/services/snowplow/index.d.ts +6 -29
- package/package.json +15 -15
- package/src/services/index.tsx +0 -4
- package/src/services/snowplow/Snowplow.ts +163 -0
- package/src/services/snowplow/SnowplowContext.tsx +1 -1
- package/src/services/snowplow/event-definitions/base.ts +47 -0
- package/src/services/snowplow/event-definitions/index.ts +13 -0
- package/src/services/snowplow/{event-definitions.ts → event-definitions/qcp.ts} +5 -26
- package/src/services/snowplow/index.test.ts +1 -1
- package/src/services/snowplow/index.ts +6 -163
- package/dist/cjs/services/snowplow/event-definitions.js.map +0 -1
- package/dist/cjs/tsconfig.tsbuildinfo +0 -1
- package/dist/esm/services/snowplow/event-definitions.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 10f56ea: Refactor event definitions
|
|
8
|
+
- 1f347dd: Dependency updates
|
|
9
|
+
- Updated dependencies [a03d10d]
|
|
10
|
+
- Updated dependencies [1f347dd]
|
|
11
|
+
- @simplybusiness/mobius@4.14.0
|
|
12
|
+
|
|
13
|
+
## 0.1.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 2f33be2: Add missing Snowplow types to services package; fix long imports
|
|
18
|
+
|
|
3
19
|
## 0.1.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
// TODO: move all Snowplow related code to a single index.tsx file
|
|
2
1
|
"use strict";
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
3
|
value: true
|
|
5
4
|
});
|
|
6
5
|
_export_star(require("./snowplow"), exports);
|
|
7
|
-
_export_star(require("./snowplow/SnowplowContext"), exports);
|
|
8
|
-
_export_star(require("./snowplow/getSnowplowConfig"), exports);
|
|
9
|
-
_export_star(require("./snowplow/contexts"), exports);
|
|
10
6
|
_export_star(require("./airbrake"), exports);
|
|
11
7
|
function _export_star(from, to) {
|
|
12
8
|
Object.keys(from).forEach(function(k) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/index.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/services/index.tsx"],"sourcesContent":["export * from \"./snowplow\";\nexport * from \"./airbrake\";\n"],"names":[],"mappings":";;;;qBAAc;qBACA"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Snowplow", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Snowplow;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _browsertracker = require("@snowplow/browser-tracker");
|
|
12
|
+
function _define_property(obj, key, value) {
|
|
13
|
+
if (key in obj) {
|
|
14
|
+
Object.defineProperty(obj, key, {
|
|
15
|
+
value: value,
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
obj[key] = value;
|
|
22
|
+
}
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
class Snowplow {
|
|
26
|
+
setContexts(contexts) {
|
|
27
|
+
var _this_contexts;
|
|
28
|
+
this.contexts = contexts;
|
|
29
|
+
// Update identity context
|
|
30
|
+
const index = (_this_contexts = this.contexts) === null || _this_contexts === void 0 ? void 0 : _this_contexts.findIndex((ctx)=>{
|
|
31
|
+
var _ctx_schema;
|
|
32
|
+
return (_ctx_schema = ctx.schema) === null || _ctx_schema === void 0 ? void 0 : _ctx_schema.includes("identity_context");
|
|
33
|
+
});
|
|
34
|
+
if (index > -1) {
|
|
35
|
+
this.contexts[index].data.domain_userid = this.uid;
|
|
36
|
+
}
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
// Send a page view event
|
|
40
|
+
trackView() {
|
|
41
|
+
if (this.trackPageView) {
|
|
42
|
+
(0, _browsertracker.trackPageView)({
|
|
43
|
+
context: this.contexts
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
// Send a structured event with contexts
|
|
49
|
+
async trackEvent(event) {
|
|
50
|
+
await (0, _browsertracker.trackStructEvent)({
|
|
51
|
+
...event,
|
|
52
|
+
context: this.contexts
|
|
53
|
+
}, [
|
|
54
|
+
this.bronzeAvalancheTrackerName
|
|
55
|
+
]);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
// Send a custom event with defined schema and optional contexts
|
|
59
|
+
async trackUnstructEvent(event) {
|
|
60
|
+
if (!event) {
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
await (0, _browsertracker.trackSelfDescribingEvent)({
|
|
64
|
+
event,
|
|
65
|
+
context: this.contexts
|
|
66
|
+
}, [
|
|
67
|
+
this.avalancheTrackerName
|
|
68
|
+
]);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
addEventHandlers(eventDefinitions) {
|
|
72
|
+
eventDefinitions.forEach(({ name, type, makePayload })=>{
|
|
73
|
+
// Convert type into relevant function
|
|
74
|
+
if (type === "structured") {
|
|
75
|
+
this.addEventHandler(name, (params)=>{
|
|
76
|
+
this.trackEvent(makePayload(params));
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
this.addEventHandler(name, (params)=>{
|
|
80
|
+
this.trackUnstructEvent(makePayload(params));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
addEventHandler(name, handler) {
|
|
87
|
+
this.eventHandlers[name] = handler;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
removeEventHandler(name) {
|
|
91
|
+
delete this.eventHandlers[name];
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
trigger(name, params) {
|
|
95
|
+
if (this.eventHandlers[name]) {
|
|
96
|
+
this.eventHandlers[name](params);
|
|
97
|
+
}
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
constructor(props){
|
|
101
|
+
_define_property(this, "avalancheTrackerName", "sb-ava");
|
|
102
|
+
_define_property(this, "bronzeAvalancheTrackerName", "sb-ava-br");
|
|
103
|
+
_define_property(this, "pvAvalancheTrackerName", "sb-ava-pv");
|
|
104
|
+
_define_property(this, "uid", "");
|
|
105
|
+
_define_property(this, "trackPageView", false);
|
|
106
|
+
_define_property(this, "contexts", []);
|
|
107
|
+
_define_property(this, "eventHandlers", {});
|
|
108
|
+
if (!props) return;
|
|
109
|
+
const { appId, cookieDomain, avalancheCollector, eventMethod, uid, postPath, // includeGAContext,
|
|
110
|
+
// trackActivity,
|
|
111
|
+
trackPageView: tpv } = props;
|
|
112
|
+
this.uid = uid;
|
|
113
|
+
this.trackPageView = tpv;
|
|
114
|
+
// Set options
|
|
115
|
+
const stateStorageStrategy = "cookieAndLocalStorage";
|
|
116
|
+
const baseOptions = {
|
|
117
|
+
appId,
|
|
118
|
+
cookieDomain,
|
|
119
|
+
eventMethod,
|
|
120
|
+
stateStorageStrategy,
|
|
121
|
+
postPath
|
|
122
|
+
};
|
|
123
|
+
// Initialize trackers
|
|
124
|
+
(0, _browsertracker.newTracker)(this.avalancheTrackerName, avalancheCollector, baseOptions);
|
|
125
|
+
(0, _browsertracker.newTracker)(this.bronzeAvalancheTrackerName, avalancheCollector, baseOptions);
|
|
126
|
+
// Page view tracker
|
|
127
|
+
(0, _browsertracker.newTracker)(this.pvAvalancheTrackerName, avalancheCollector, {
|
|
128
|
+
...baseOptions,
|
|
129
|
+
eventMethod: eventMethod === "post" ? "beacon" : eventMethod
|
|
130
|
+
});
|
|
131
|
+
(0, _browsertracker.setCookiePath)("/");
|
|
132
|
+
if (uid) {
|
|
133
|
+
(0, _browsertracker.setUserId)(uid);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=Snowplow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/services/snowplow/Snowplow.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":["Snowplow","setContexts","contexts","index","findIndex","ctx","schema","includes","data","domain_userid","uid","trackView","trackPageView","context","trackEvent","event","trackStructEvent","bronzeAvalancheTrackerName","trackUnstructEvent","trackSelfDescribingEvent","avalancheTrackerName","addEventHandlers","eventDefinitions","forEach","name","type","makePayload","addEventHandler","params","handler","eventHandlers","removeEventHandler","trigger","constructor","props","pvAvalancheTrackerName","appId","cookieDomain","avalancheCollector","eventMethod","postPath","tpv","stateStorageStrategy","baseOptions","newTracker","setCookiePath","setUserId"],"mappings":";;;;+BAuBaA;;;eAAAA;;;gCAbN;;;;;;;;;;;;;;AAaA,MAAMA;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,CAACC,aAAa,EAAE;YACtBA,IAAAA,6BAAa,EAAC;gBAAEC,SAAS,IAAI,CAACX,QAAQ;YAAC;QACzC;QACA,OAAO,IAAI;IACb;IAEA,wCAAwC;IACxC,MAAMY,WAAWC,KAAsB,EAAE;QACvC,MAAMC,IAAAA,gCAAgB,EAAC;YAAE,GAAGD,KAAK;YAAEF,SAAS,IAAI,CAACX,QAAQ;QAAC,GAAG;YAC3D,IAAI,CAACe,0BAA0B;SAChC;QACD,OAAO,IAAI;IACb;IAEA,gEAAgE;IAChE,MAA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Y,EACZC,kBAAkB,EAClBC,WAAW,EACX7B,GAAG,EACH8B,QAAQ,EACR,oBAAoB;QACpB,iBAAiB;QACjB5B,eAAe6B,GAAG,EACnB,GAAGP;QACJ,IAAI,CAACxB,GAAG,GAAGA;QACX,IAAI,CAACE,aAAa,GAAG6B;QAErB,cAAc;QACd,MAAMC,uBAAuB;QAC7B,MAAMC,cAAoC;YACxCP;YACAC;YACAE;YACAG;YACAF;QACF;QACA,sBAAsB;QACtBI,IAAAA,0BAAU,EAAC,IAAI,CAACxB,oBAAoB,EAAEkB,oBAAoBK;QAE1DC,IAAAA,0BAAU,EACR,IAAI,CAAC3B,0BAA0B,EAC/BqB,oBACAK;QAGF,oBAAoB;QACpBC,IAAAA,0BAAU,EAAC,IAAI,CAACT,sBAAsB,EAAEG,oBAAoB;YAC1D,GAAGK,WAAW;YACdJ,aAAaA,gBAAgB,SAAS,WAAWA;QACnD;QAEAM,IAAAA,6BAAa,EAAC;QACd,IAAInC,KAAK;YACPoC,IAAAA,yBAAS,EAACpC;QACZ;IACF;AA8EF"}
|
|
@@ -18,13 +18,13 @@ _export(exports, {
|
|
|
18
18
|
});
|
|
19
19
|
const _jsxruntime = require("react/jsx-runtime");
|
|
20
20
|
const _react = require("react");
|
|
21
|
-
const _ = require(".");
|
|
22
21
|
const _contexts = require("./contexts");
|
|
23
22
|
const _eventdefinitions = require("./event-definitions");
|
|
23
|
+
const _Snowplow = require("./Snowplow");
|
|
24
24
|
const SnowplowContext = /*#__PURE__*/ (0, _react.createContext)(null);
|
|
25
25
|
const SnowplowProvider = ({ scripts, children })=>{
|
|
26
26
|
const [config, _setConfig] = (0, _react.useState)(scripts);
|
|
27
|
-
const [snowplow, setSnowplow] = (0, _react.useState)(new
|
|
27
|
+
const [snowplow, setSnowplow] = (0, _react.useState)(new _Snowplow.Snowplow(config));
|
|
28
28
|
// Attach event handlers and set contexts
|
|
29
29
|
(0, _react.useEffect)(()=>{
|
|
30
30
|
if (snowplow && scripts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/services/snowplow/SnowplowContext.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useState,\n type ReactNode,\n} from \"react\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/services/snowplow/SnowplowContext.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useState,\n type ReactNode,\n} from \"react\";\nimport { getContexts } from \"./contexts\";\nimport { eventDefinitions } from \"./event-definitions\";\nimport { Snowplow } from \"./Snowplow\";\nimport { EventDefinition, TrackingProps } from \"./types\";\n\nexport interface SnowplowContextInterface {\n config: TrackingProps;\n snowplow?: Snowplow;\n}\n\nconst SnowplowContext = createContext<SnowplowContextInterface | null>(null);\n\ntype ProviderProps = {\n scripts: TrackingProps;\n children: ReactNode;\n};\n\nexport const SnowplowProvider = ({ scripts, children }: ProviderProps) => {\n const [config, _setConfig] = useState<TrackingProps>(scripts);\n const [snowplow, setSnowplow] = useState<Snowplow>(new Snowplow(config));\n\n // Attach event handlers and set contexts\n useEffect(() => {\n if (snowplow && scripts) {\n const contexts = getContexts(config);\n\n snowplow\n .setContexts(contexts)\n .addEventHandlers(eventDefinitions as EventDefinition[]);\n // Send page view event\n if (config.trackPageView) snowplow.trackView();\n }\n }, [config, snowplow, scripts]);\n\n const value: SnowplowContextInterface = useMemo(\n () => ({\n config,\n snowplow,\n }),\n [config, snowplow],\n );\n\n return (\n <SnowplowContext.Provider value={value}>\n {children}\n </SnowplowContext.Provider>\n );\n};\n\nexport function useSnowplowContext() {\n const context = useContext(SnowplowContext);\n\n if (!context) {\n throw new Error(\n \"useSnowplowContext must be used inside a `SnowplowProvider`\",\n );\n }\n return context;\n}\n"],"names":["SnowplowProvider","useSnowplowContext","SnowplowContext","createContext","scripts","children","config","_setConfig","useState","snowplow","setSnowplow","Snowplow","useEffect","contexts","getContexts","setContexts","addEventHandlers","eventDefinitions","trackPageView","trackView","value","useMemo","Provider","context","useContext","Error"],"mappings":"AAAA,oDAAoD;;;;;;;;;;;IA0BvCA,gBAAgB;eAAhBA;;IAgCGC,kBAAkB;eAAlBA;;;;uBAlDT;0BACqB;kCACK;0BACR;AAQzB,MAAMC,gCAAkBC,IAAAA,oBAAa,EAAkC;AAOhE,MAAMH,mBAAmB,CAAC,EAAEI,OAAO,EAAEC,QAAQ,EAAiB;IACnE,MAAM,CAACC,QAAQC,WAAW,GAAGC,IAAAA,eAAQ,EAAgBJ;IACrD,MAAM,CAACK,UAAUC,YAAY,GAAGF,IAAAA,eAAQ,EAAW,IAAIG,kBAAQ,CAACL;IAEhE,yCAAyC;IACzCM,IAAAA,gBAAS,EAAC;QACR,IAAIH,YAAYL,SAAS;YACvB,MAAMS,WAAWC,IAAAA,qBAAW,EAACR;YAE7BG,SACGM,WAAW,CAACF,UACZG,gBAAgB,CAACC,kCAAgB;YACpC,uBAAuB;YACvB,IAAIX,OAAOY,aAAa,EAAET,SAASU,SAAS;QAC9C;IACF,GAAG;QAACb;QAAQG;QAAUL;KAAQ;IAE9B,MAAMgB,QAAkCC,IAAAA,cAAO,EAC7C,IAAO,CAAA;YACLf;YACAG;QACF,CAAA,GACA;QAACH;QAAQG;KAAS;IAGpB,qBACE,qBAACP,gBAAgBoB,QAAQ;QAACF,OAAOA;kBAC9Bf;;AAGP;AAEO,SAASJ;IACd,MAAMsB,UAAUC,IAAAA,iBAAU,EAACtB;IAE3B,IAAI,CAACqB,SAAS;QACZ,MAAM,IAAIE,MACR;IAEJ;IACA,OAAOF;AACT"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "baseEventDefinitions", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return baseEventDefinitions;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const baseEventDefinitions = [
|
|
12
|
+
// Mobile link in header
|
|
13
|
+
{
|
|
14
|
+
name: "mobileLinkClick",
|
|
15
|
+
type: "structured",
|
|
16
|
+
makePayload: ()=>({
|
|
17
|
+
category: "marketing",
|
|
18
|
+
action: "link-click",
|
|
19
|
+
label: "mobile_call_button",
|
|
20
|
+
property: window.location.href
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
// Operating hours link in footer
|
|
24
|
+
{
|
|
25
|
+
name: "operatingHoursClick",
|
|
26
|
+
type: "unstructured",
|
|
27
|
+
makePayload: ()=>({
|
|
28
|
+
schema: "iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",
|
|
29
|
+
data: {
|
|
30
|
+
schema: "iglu:com.simplybusiness/operating_hours_clicked/jsonschema/1-0-2",
|
|
31
|
+
data: {}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/services/snowplow/event-definitions/base.ts"],"sourcesContent":["import { EventDefinition } 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 * import { Snowplow } from \"./Snowplow\";\n * import { eventDefinitions } from \"./event-definitions\";\n *\n * const snowplow = new Snowplow();\n * snowplow.addEventHandlers(eventDefinitions);\n */\n\n// Base page events\nexport const baseEventDefinitions: EventDefinition[] = [\n // Mobile link in header\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 // Operating hours link in footer\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"],"names":["baseEventDefinitions","name","type","makePayload","category","action","label","property","window","location","href","schema","data"],"mappings":";;;;+BAoBaA;;;eAAAA;;;AAAN,MAAMA,uBAA0C;IACrD,wBAAwB;IACxB;QACEC,MAAM;QACNC,MAAM;QACNC,aAAa,IAAO,CAAA;gBAClBC,UAAU;gBACVC,QAAQ;gBACRC,OAAO;gBACPC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC,CAAA;IACF;IACA,iCAAiC;IACjC;QACET,MAAM;QACNC,MAAM;QACNC,aAAa,IAAO,CAAA;gBAClBQ,QACE;gBACFC,MAAM;oBACJD,QACE;oBACFC,MAAM,CAAC;gBACT;YACF,CAAA;IACF;CACD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
eventDefinitions: function() {
|
|
13
|
+
return eventDefinitions;
|
|
14
|
+
},
|
|
15
|
+
qcpPageEvents: function() {
|
|
16
|
+
return qcpPageEvents;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _base = require("./base");
|
|
20
|
+
const _qcp = require("./qcp");
|
|
21
|
+
const eventDefinitions = [
|
|
22
|
+
..._base.baseEventDefinitions,
|
|
23
|
+
..._qcp.qcpEventDefinitions
|
|
24
|
+
];
|
|
25
|
+
const qcpPageEvents = [
|
|
26
|
+
..._base.baseEventDefinitions,
|
|
27
|
+
..._qcp.qcpEventDefinitions
|
|
28
|
+
]; // Create a new export for each kind of page below
|
|
29
|
+
// containing just the subset needed for that page
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/services/snowplow/event-definitions/index.ts"],"sourcesContent":["import { baseEventDefinitions } from \"./base\";\nimport { qcpEventDefinitions } from \"./qcp\";\n\n// All events (keep up to date with new files)\nexport const eventDefinitions = [\n ...baseEventDefinitions,\n ...qcpEventDefinitions,\n];\n\nexport const qcpPageEvents = [...baseEventDefinitions, ...qcpEventDefinitions];\n\n// Create a new export for each kind of page below\n// containing just the subset needed for that page\n"],"names":["eventDefinitions","qcpPageEvents","baseEventDefinitions","qcpEventDefinitions"],"mappings":";;;;;;;;;;;IAIaA,gBAAgB;eAAhBA;;IAKAC,aAAa;eAAbA;;;sBATwB;qBACD;AAG7B,MAAMD,mBAAmB;OAC3BE,0BAAoB;OACpBC,wBAAmB;CACvB;AAEM,MAAMF,gBAAgB;OAAIC,0BAAoB;OAAKC,wBAAmB;CAAC,EAE9E,kDAAkD;CAClD,kDAAkD"}
|
|
@@ -2,35 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "qcpEventDefinitions", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return qcpEventDefinitions;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _utils = require("
|
|
12
|
-
const
|
|
13
|
-
{
|
|
14
|
-
name: "mobileLinkClick",
|
|
15
|
-
type: "structured",
|
|
16
|
-
makePayload: ()=>({
|
|
17
|
-
category: "marketing",
|
|
18
|
-
action: "link-click",
|
|
19
|
-
label: "mobile_call_button",
|
|
20
|
-
property: window.location.href
|
|
21
|
-
})
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: "operatingHoursClick",
|
|
25
|
-
type: "unstructured",
|
|
26
|
-
makePayload: ()=>({
|
|
27
|
-
schema: "iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",
|
|
28
|
-
data: {
|
|
29
|
-
schema: "iglu:com.simplybusiness/operating_hours_clicked/jsonschema/1-0-2",
|
|
30
|
-
data: {}
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
},
|
|
11
|
+
const _utils = require("../../../utils");
|
|
12
|
+
const qcpEventDefinitions = [
|
|
34
13
|
{
|
|
35
14
|
// QDP details button
|
|
36
15
|
name: "detailsClicked",
|
|
@@ -232,4 +211,4 @@ const eventDefinitions = [
|
|
|
232
211
|
}
|
|
233
212
|
];
|
|
234
213
|
|
|
235
|
-
//# sourceMappingURL=
|
|
214
|
+
//# sourceMappingURL=qcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/services/snowplow/event-definitions/qcp.ts"],"sourcesContent":["import { snakeCase } from \"../../../utils\";\nimport { EventDefinition, 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 * import { Snowplow } from \"./Snowplow\";\n * import { eventDefinitions } from \"./event-definitions\";\n *\n * const snowplow = new Snowplow();\n * snowplow.addEventHandlers(eventDefinitions);\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: \"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":["qcpEventDefinitions","name","type","makePayload","category","action","label","property","window","location","href","params","deviceType","urlFriendlyLabel","replace","toLowerCase","product","title","productLabel","snakeCase","fromValue","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AM;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,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,EAAEC,UAAU,EAAE,GAAGD;YAEvB,OAAO;gBACLN,QAAQ;gBACRD,UAAU,CAAC,aAAa,EAAEQ,WAAW,0BAA0B,CAAC;gBAChEN,OAAO;gBACPC,UAAUC,OAAOC,QAAQ,CAACC,IAAI;YAChC;QACF;IACF;CACD"}
|
|
@@ -2,137 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
} else {
|
|
21
|
-
obj[key] = value;
|
|
22
|
-
}
|
|
23
|
-
return obj;
|
|
24
|
-
}
|
|
25
|
-
class Snowplow {
|
|
26
|
-
setContexts(contexts) {
|
|
27
|
-
var _this_contexts;
|
|
28
|
-
this.contexts = contexts;
|
|
29
|
-
// Update identity context
|
|
30
|
-
const index = (_this_contexts = this.contexts) === null || _this_contexts === void 0 ? void 0 : _this_contexts.findIndex((ctx)=>{
|
|
31
|
-
var _ctx_schema;
|
|
32
|
-
return (_ctx_schema = ctx.schema) === null || _ctx_schema === void 0 ? void 0 : _ctx_schema.includes("identity_context");
|
|
33
|
-
});
|
|
34
|
-
if (index > -1) {
|
|
35
|
-
this.contexts[index].data.domain_userid = this.uid;
|
|
36
|
-
}
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
// Send a page view event
|
|
40
|
-
trackView() {
|
|
41
|
-
if (this.trackPageView) {
|
|
42
|
-
(0, _browsertracker.trackPageView)({
|
|
43
|
-
context: this.contexts
|
|
5
|
+
_export_star(require("./contexts"), exports);
|
|
6
|
+
_export_star(require("./event-definitions"), exports);
|
|
7
|
+
_export_star(require("./getSnowplowConfig"), exports);
|
|
8
|
+
_export_star(require("./Snowplow"), exports);
|
|
9
|
+
_export_star(require("./SnowplowContext"), exports);
|
|
10
|
+
_export_star(require("./types"), exports);
|
|
11
|
+
function _export_star(from, to) {
|
|
12
|
+
Object.keys(from).forEach(function(k) {
|
|
13
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
14
|
+
Object.defineProperty(to, k, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function() {
|
|
17
|
+
return from[k];
|
|
18
|
+
}
|
|
44
19
|
});
|
|
45
20
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// Send a structured event with contexts
|
|
49
|
-
async trackEvent(event) {
|
|
50
|
-
await (0, _browsertracker.trackStructEvent)({
|
|
51
|
-
...event,
|
|
52
|
-
context: this.contexts
|
|
53
|
-
}, [
|
|
54
|
-
this.bronzeAvalancheTrackerName
|
|
55
|
-
]);
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
// Send a custom event with defined schema and optional contexts
|
|
59
|
-
async trackUnstructEvent(event) {
|
|
60
|
-
if (!event) {
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
await (0, _browsertracker.trackSelfDescribingEvent)({
|
|
64
|
-
event,
|
|
65
|
-
context: this.contexts
|
|
66
|
-
}, [
|
|
67
|
-
this.avalancheTrackerName
|
|
68
|
-
]);
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
addEventHandlers(eventDefinitions) {
|
|
72
|
-
eventDefinitions.forEach(({ name, type, makePayload })=>{
|
|
73
|
-
// Convert type into relevant function
|
|
74
|
-
if (type === "structured") {
|
|
75
|
-
this.addEventHandler(name, (params)=>{
|
|
76
|
-
this.trackEvent(makePayload(params));
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
this.addEventHandler(name, (params)=>{
|
|
80
|
-
this.trackUnstructEvent(makePayload(params));
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
addEventHandler(name, handler) {
|
|
87
|
-
this.eventHandlers[name] = handler;
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
removeEventHandler(name) {
|
|
91
|
-
delete this.eventHandlers[name];
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
trigger(name, params) {
|
|
95
|
-
if (this.eventHandlers[name]) {
|
|
96
|
-
this.eventHandlers[name](params);
|
|
97
|
-
}
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
constructor(props){
|
|
101
|
-
_define_property(this, "avalancheTrackerName", "sb-ava");
|
|
102
|
-
_define_property(this, "bronzeAvalancheTrackerName", "sb-ava-br");
|
|
103
|
-
_define_property(this, "pvAvalancheTrackerName", "sb-ava-pv");
|
|
104
|
-
_define_property(this, "uid", "");
|
|
105
|
-
_define_property(this, "trackPageView", false);
|
|
106
|
-
_define_property(this, "contexts", []);
|
|
107
|
-
_define_property(this, "eventHandlers", {});
|
|
108
|
-
if (!props) return;
|
|
109
|
-
const { appId, cookieDomain, avalancheCollector, eventMethod, uid, postPath, // includeGAContext,
|
|
110
|
-
// trackActivity,
|
|
111
|
-
trackPageView: tpv } = props;
|
|
112
|
-
this.uid = uid;
|
|
113
|
-
this.trackPageView = tpv;
|
|
114
|
-
// Set options
|
|
115
|
-
const stateStorageStrategy = "cookieAndLocalStorage";
|
|
116
|
-
const baseOptions = {
|
|
117
|
-
appId,
|
|
118
|
-
cookieDomain,
|
|
119
|
-
eventMethod,
|
|
120
|
-
stateStorageStrategy,
|
|
121
|
-
postPath
|
|
122
|
-
};
|
|
123
|
-
// Initialize trackers
|
|
124
|
-
(0, _browsertracker.newTracker)(this.avalancheTrackerName, avalancheCollector, baseOptions);
|
|
125
|
-
(0, _browsertracker.newTracker)(this.bronzeAvalancheTrackerName, avalancheCollector, baseOptions);
|
|
126
|
-
// Page view tracker
|
|
127
|
-
(0, _browsertracker.newTracker)(this.pvAvalancheTrackerName, avalancheCollector, {
|
|
128
|
-
...baseOptions,
|
|
129
|
-
eventMethod: eventMethod === "post" ? "beacon" : eventMethod
|
|
130
|
-
});
|
|
131
|
-
(0, _browsertracker.setCookiePath)("/");
|
|
132
|
-
if (uid) {
|
|
133
|
-
(0, _browsertracker.setUserId)(uid);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
21
|
+
});
|
|
22
|
+
return from;
|
|
136
23
|
}
|
|
137
24
|
|
|
138
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/services/snowplow/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../src/services/snowplow/index.ts"],"sourcesContent":["export * from \"./contexts\";\nexport * from \"./event-definitions\";\nexport * from \"./getSnowplowConfig\";\nexport * from \"./Snowplow\";\nexport * from \"./SnowplowContext\";\nexport * from \"./types\";\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
// TODO: move all Snowplow related code to a single index.tsx file
|
|
2
1
|
export * from "./snowplow";
|
|
3
|
-
export * from "./snowplow/SnowplowContext";
|
|
4
|
-
export * from "./snowplow/getSnowplowConfig";
|
|
5
|
-
export * from "./snowplow/contexts";
|
|
6
2
|
export * from "./airbrake";
|
|
7
3
|
|
|
8
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/index.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/services/index.tsx"],"sourcesContent":["export * from \"./snowplow\";\nexport * from \"./airbrake\";\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,aAAa"}
|