@saasquatch/squatch-js 2.3.1-0 → 2.3.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/demo/toolbar.tsx CHANGED
@@ -1,249 +1,358 @@
1
- import React, { Component, version } from "react";
2
- import { render } from "react-dom";
3
-
4
- import {
5
- popup,
6
- embed,
7
- embedNew,
8
- embedReferred,
9
- popupNew,
10
- popupReferred,
11
- script,
12
- toURL,
13
- users,
14
- href,
15
- } from "./sandbox";
16
- import { getVersions } from "./versions";
17
- import { delay } from "./util";
18
-
19
- const modes = ["POPUP", "EMBED"];
20
- const widgetTypes = [
21
- "REFERRER_WIDGET",
22
- "CONVERSION_WIDGET",
23
- "p/tuesday-test/w/referrerWidget",
24
- ];
25
- const staticVersions = ["HEAD", "latest", "alpha"];
26
-
27
- /**
28
- * Use the addUrlProps higher-order component to hook-in react-url-query.
29
- */
30
- class App extends Component {
31
- state = {
32
- versions: staticVersions,
33
- };
34
- async componentWillMount() {
35
- const apiVersions = await getVersions();
36
- const versions = [...staticVersions, ...apiVersions];
37
- this.setState({ versions });
38
- }
39
- render() {
40
- return (
41
- <div>
42
- <hr />
43
- <div>
44
- <ParamArea />
45
- <hr />
46
- <h2>Quick pick variables</h2>
47
- <details>
48
- <summary>Tenant / Program</summary>
49
- <a href={href(popup)}>Popup (classic)</a>
50
- <a href={href(embed)}>Embed (classic)</a>
51
- <a href={href(popupNew)}>Popup (new program)</a>
52
- <a href={href(embedNew)}>Embed (new program)</a>
53
- <a href={href(popupReferred)}>Popup (classic referred widget)</a>
54
- <a href={href(embedReferred)}>Embed (classic referred widget)</a>
55
- </details>
56
- <WidgetType />
57
- <ModeList />
58
- <UserList />
59
- <VersionList {...this.state} />
60
- </div>
61
- <hr />
62
-
63
- <button onClick={() => recordPurchase()}>Record Purchase</button>
64
- <hr />
65
-
66
- <button onClick={() => runEventBomb()}>Event Bomb</button>
67
- </div>
68
- );
69
- }
70
- }
71
-
72
- function ParamArea() {
73
- return (
74
- <div>
75
- <h2>Squatch.js Config</h2>
76
- <div>
77
- <textarea id="area1" rows={15} cols={80}>
78
- {JSON.stringify(window["sandbox"], null, 2)}
79
- </textarea>
80
- </div>
81
- <div>
82
- <button
83
- onClick={() => {
84
- let json: Sandbox = JSON.parse(
85
- // @ts-ignore
86
- document.getElementById("area1").value
87
- );
88
- toURL(json);
89
- }}
90
- >
91
- Reload Config
92
- </button>
93
- <button
94
- onClick={() => {
95
- navigator.clipboard.writeText(window.location.toString());
96
- }}
97
- >
98
- Share Current Config
99
- </button>
100
- </div>
101
- </div>
102
- );
103
- }
104
-
105
- async function recordPurchase() {
106
- //@ts-ignore
107
- const { squatch, sandbox } = window;
108
- const {
109
- jwt,
110
- user: { id, accountId },
111
- } = sandbox.initObj;
112
- const fields = {
113
- // Optional
114
- total: 10.0,
115
- revenue: 10.0,
116
- tax: 5.0,
117
- currency: "USD",
118
- };
119
-
120
- await squatch.events().track(
121
- {
122
- userId: id,
123
- accountId: accountId,
124
- events: [
125
- {
126
- key: "purchase",
127
- fields: fields, // Optional
128
- // id: "kjv12kbwktb13t3", // Optional id
129
- // dateTriggered: 1535136384753 // Optional date
130
- },
131
- ],
132
- },
133
- {
134
- jwt,
135
- }
136
- );
137
- // TODO: Eventually we'd like an API like this:
138
- // squatch.events().track("purchase", { ...fields });
139
- }
140
- async function runEventBomb() {
141
- while (true) {
142
- await recordPurchase();
143
- await delay(100);
144
- }
145
- }
146
- function WidgetType(props) {
147
- return (
148
- <details
149
- title={window["sandbox"].initObj.widgetType}
150
- key={0}
151
- id={`dropdown-basic-1`}
152
- >
153
- {widgetTypes.map((widgetType, i) => (
154
- <a
155
- key={i}
156
- href={href({
157
- ...window["sandbox"],
158
- initObj: {
159
- ...window["sandbox"].initObj,
160
- widgetType: widgetType,
161
- },
162
- })}
163
- >
164
- {widgetType}
165
- </a>
166
- ))}
167
- </details>
168
- );
169
- }
170
- function ModeList(props) {
171
- return (
172
- <details
173
- title={window["sandbox"].initObj.engagementMedium}
174
- key={0}
175
- id={`dropdown-basic-1`}
176
- >
177
- <summary>Engagement Medium</summary>
178
- {modes.map((mode, i) => (
179
- <a
180
- key={i}
181
- href={href({
182
- ...window["sandbox"],
183
- initObj: {
184
- ...window["sandbox"].initObj,
185
- engagementMedium: mode,
186
- },
187
- })}
188
- >
189
- {mode}
190
- </a>
191
- ))}
192
- </details>
193
- );
194
- }
195
- function UserList(props) {
196
- return (
197
- <details
198
- title={"User: " + window["sandbox"].initObj.user.firstName}
199
- key={0}
200
- id={`dropdown-basic-1`}
201
- >
202
- <summary>User</summary>
203
- {users.map((user, i) => (
204
- <a
205
- key={i}
206
- href={href({
207
- ...window["sandbox"],
208
- initObj: {
209
- ...window["sandbox"].initObj,
210
- user: user,
211
- },
212
- })}
213
- >
214
- {user["firstName"] || "Empty"}
215
- </a>
216
- ))}
217
- </details>
218
- );
219
- }
220
- function VersionList(props) {
221
- const { versions } = props;
222
- return (
223
- <details
224
- title={"Version: " + window["sandbox"].version || "Head"}
225
- key={0}
226
- id={`dropdown-basic-1`}
227
- >
228
- <summary>Version</summary>
229
- {versions.map((v, i) => (
230
- <a
231
- key={i}
232
- href={href({
233
- ...window["sandbox"],
234
- version: v,
235
- script:
236
- v.toLocaleLowerCase() == "head"
237
- ? script
238
- : `https://unpkg.com/@saasquatch/squatch-js@${v}`,
239
- })}
240
- >
241
- {v}
242
- </a>
243
- ))}
244
- </details>
245
- );
246
- }
247
- const root = document.getElementById("app");
248
- console.log("mount to", root);
249
- render(<App />, root);
1
+ import React, { Component, version } from "react";
2
+ import { render } from "react-dom";
3
+
4
+ import {
5
+ popup,
6
+ embed,
7
+ embedNew,
8
+ embedReferred,
9
+ popupNew,
10
+ popupReferred,
11
+ script,
12
+ toURL,
13
+ users,
14
+ href,
15
+ } from "./sandbox";
16
+ import { getVersions } from "./versions";
17
+ import { delay } from "./util";
18
+ import { widgets, worker } from "./generate";
19
+ import { rest } from "msw";
20
+ import classic from "./templates/classic";
21
+ import MintGA from "./templates/MintGA";
22
+ import VanillaGA from "./templates/VanillaGA";
23
+
24
+ console.log("me old sandbox", window["sandbox"]);
25
+
26
+ console.log("my worker", { worker });
27
+
28
+ // 2. Define request handlers and response resolvers.
29
+
30
+ const modes = ["POPUP", "EMBED"];
31
+ const widgetTypes = [
32
+ "REFERRER_WIDGET",
33
+ "CONVERSION_WIDGET",
34
+ "p/tuesday-test/w/referrerWidget",
35
+ ];
36
+ const staticVersions = ["HEAD", "latest", "alpha", "next"];
37
+
38
+ /**
39
+ * Use the addUrlProps higher-order component to hook-in react-url-query.
40
+ */
41
+ class App extends Component {
42
+ constructor(props) {
43
+ super(props);
44
+ worker.start({
45
+ findWorker: (scriptURL, _mockServiceWorkerUrl) =>
46
+ scriptURL.includes("mockServiceWorker"),
47
+ onUnhandledRequest(req) {
48
+ console.error(
49
+ "Found an unhandled %s request to %s",
50
+ req.method,
51
+ req.url.href
52
+ );
53
+ },
54
+ });
55
+ }
56
+ state = {
57
+ versions: staticVersions,
58
+ toolbarOpen: true,
59
+ };
60
+ async componentWillMount() {
61
+ const apiVersions = await getVersions();
62
+ const versions = [...staticVersions, ...apiVersions];
63
+ this.setState({ versions });
64
+ }
65
+ render() {
66
+ return (
67
+ <div>
68
+ <button
69
+ onClick={() =>
70
+ this.setState({ toolbarOpen: !this.state.toolbarOpen })
71
+ }
72
+ style={{ float: "right" }}
73
+ >
74
+ {this.state.toolbarOpen ? `<` : `>`}
75
+ </button>
76
+ <div style={{ display: this.state.toolbarOpen ? "block" : "none" }}>
77
+ <hr />
78
+ <div>
79
+ <ParamArea />
80
+ <hr />
81
+ <h2>Quick pick variables</h2>
82
+ <details>
83
+ <summary>Tenant / Program</summary>
84
+ <ul>
85
+ <li>
86
+ <a href={href(popup)}>Popup (classic)</a>
87
+ </li>
88
+ <li>
89
+ <a href={href(embed)}>Embed (classic)</a>
90
+ </li>
91
+ <li>
92
+ <a href={href(popupNew)}>Popup (new program)</a>
93
+ </li>
94
+ <li>
95
+ <a href={href(embedNew)}>Embed (new program)</a>
96
+ </li>
97
+ <li>
98
+ <a href={href(popupReferred)}>
99
+ Popup (classic referred widget)
100
+ </a>
101
+ </li>
102
+ <li>
103
+ <a href={href(embedReferred)}>
104
+ Embed (classic referred widget)
105
+ </a>
106
+ </li>
107
+ </ul>
108
+ </details>
109
+ <WidgetType />
110
+ <ModeList />
111
+ <UserList />
112
+ <VersionList {...this.state} />
113
+ <MockedWidgets />
114
+ </div>
115
+ <hr />
116
+
117
+ <button onClick={() => recordPurchase()}>Record Purchase</button>
118
+ <hr />
119
+
120
+ <button onClick={() => runEventBomb()}>Event Bomb</button>
121
+ </div>
122
+ </div>
123
+ );
124
+ }
125
+ }
126
+
127
+ function ParamArea() {
128
+ return (
129
+ <div>
130
+ <h2>Squatch.js Config</h2>
131
+ <div>
132
+ <textarea id="area1" rows={15} cols={70} style={{ maxWidth: "100%" }}>
133
+ {JSON.stringify(window["sandbox"], null, 2)}
134
+ </textarea>
135
+ </div>
136
+ <div>
137
+ <button
138
+ onClick={() => {
139
+ let json: Sandbox = JSON.parse(
140
+ // @ts-ignore
141
+ document.getElementById("area1").value
142
+ );
143
+ toURL(json);
144
+ }}
145
+ >
146
+ Reload Config
147
+ </button>
148
+ <button
149
+ onClick={() => {
150
+ navigator.clipboard.writeText(window.location.toString());
151
+ }}
152
+ >
153
+ Share Current Config
154
+ </button>
155
+ </div>
156
+ </div>
157
+ );
158
+ }
159
+
160
+ async function recordPurchase() {
161
+ //@ts-ignore
162
+ const { squatch, sandbox } = window;
163
+ const {
164
+ jwt,
165
+ user: { id, accountId },
166
+ } = sandbox.initObj;
167
+ const fields = {
168
+ // Optional
169
+ total: 10.0,
170
+ revenue: 10.0,
171
+ tax: 5.0,
172
+ currency: "USD",
173
+ };
174
+
175
+ await squatch.events().track(
176
+ {
177
+ userId: id,
178
+ accountId: accountId,
179
+ events: [
180
+ {
181
+ key: "purchase",
182
+ fields: fields, // Optional
183
+ // id: "kjv12kbwktb13t3", // Optional id
184
+ // dateTriggered: 1535136384753 // Optional date
185
+ },
186
+ ],
187
+ },
188
+ {
189
+ jwt,
190
+ }
191
+ );
192
+ // TODO: Eventually we'd like an API like this:
193
+ // squatch.events().track("purchase", { ...fields });
194
+ }
195
+ async function runEventBomb() {
196
+ while (true) {
197
+ await recordPurchase();
198
+ await delay(100);
199
+ }
200
+ }
201
+ function WidgetType(props) {
202
+ return (
203
+ <details
204
+ title={window["sandbox"].initObj.widgetType}
205
+ key={0}
206
+ id={`dropdown-basic-1`}
207
+ >
208
+ {widgetTypes.map((widgetType, i) => (
209
+ <a
210
+ key={i}
211
+ href={href({
212
+ ...window["sandbox"],
213
+ initObj: {
214
+ ...window["sandbox"].initObj,
215
+ widgetType: widgetType,
216
+ },
217
+ })}
218
+ >
219
+ {widgetType}
220
+ </a>
221
+ ))}
222
+ </details>
223
+ );
224
+ }
225
+ function ModeList(props) {
226
+ return (
227
+ <details
228
+ title={window["sandbox"].initObj.engagementMedium}
229
+ key={0}
230
+ id={`dropdown-basic-1`}
231
+ >
232
+ <summary>Engagement Medium</summary>
233
+ {modes.map((mode, i) => (
234
+ <a
235
+ key={i}
236
+ href={href({
237
+ ...window["sandbox"],
238
+ initObj: {
239
+ ...window["sandbox"].initObj,
240
+ engagementMedium: mode,
241
+ },
242
+ })}
243
+ >
244
+ {mode}
245
+ </a>
246
+ ))}
247
+ </details>
248
+ );
249
+ }
250
+ function UserList(props) {
251
+ return (
252
+ <details
253
+ title={"User: " + window["sandbox"].initObj.user.firstName}
254
+ key={0}
255
+ id={`dropdown-basic-1`}
256
+ >
257
+ <summary>User</summary>
258
+ {users.map((user, i) => (
259
+ <a
260
+ key={i}
261
+ href={href({
262
+ ...window["sandbox"],
263
+ initObj: {
264
+ ...window["sandbox"].initObj,
265
+ user: user,
266
+ },
267
+ })}
268
+ >
269
+ {user["firstName"] || "Empty"}
270
+ </a>
271
+ ))}
272
+ </details>
273
+ );
274
+ }
275
+ function VersionList(props) {
276
+ const { versions } = props;
277
+ return (
278
+ <details
279
+ title={"Version: " + window["sandbox"].version || "Head"}
280
+ key={0}
281
+ id={`dropdown-basic-1`}
282
+ >
283
+ <summary>Version</summary>
284
+ {versions.map((v, i) => (
285
+ <a
286
+ key={i}
287
+ href={href({
288
+ ...window["sandbox"],
289
+ version: v,
290
+ script:
291
+ v.toLocaleLowerCase() == "head"
292
+ ? script
293
+ : `https://unpkg.com/@saasquatch/squatch-js@${v}`,
294
+ })}
295
+ >
296
+ {v}
297
+ </a>
298
+ ))}
299
+ </details>
300
+ );
301
+ }
302
+
303
+ function MockedWidgets(props) {
304
+ const { versions } = props;
305
+
306
+ async function getMockWidget(widget) {
307
+ console.log("fetch");
308
+ // window["squatch"].render()
309
+ window["mockWidget"] = widget;
310
+ window["sandbox"].initObj = {
311
+ ...window["sandbox"].initObj,
312
+ engagementMedium: "EMBED",
313
+ };
314
+
315
+ worker.use(
316
+ rest.put(
317
+ "https://staging.referralsaasquatch.com/api/*",
318
+ (req, res, ctx) => {
319
+ return res(
320
+ ctx.delay(500),
321
+ ctx.status(202, "Mocked status"),
322
+ ctx.json(widgets[window["mockWidget"]])
323
+ );
324
+ }
325
+ )
326
+ );
327
+ document.getElementById("squatchembed").innerHTML = "";
328
+ window["squatch"].widgets().upsertUser(window["sandbox"].initObj);
329
+ // window.location.href = `/?widgetType=${widget}`;
330
+ }
331
+ return (
332
+ <details
333
+ title={"Version: " + window["sandbox"].version || "Head"}
334
+ key={0}
335
+ id={`dropdown-basic-1`}
336
+ >
337
+ <summary>Mocked Widgets</summary>
338
+ <button onClick={() => getMockWidget("QuirksVanillaGA")}>
339
+ Quirks mode - Vanilla
340
+ </button>
341
+ <button onClick={() => getMockWidget("QuirksMintGA")}>
342
+ Quirks mode - Mint
343
+ </button>
344
+ <button onClick={() => getMockWidget("classic")}>Classic</button>
345
+ <button onClick={() => getMockWidget("MintGA")}>GA - Mint</button>
346
+ <button onClick={() => getMockWidget("VanillaGA")}>GA - Vanilla</button>
347
+ <button onClick={() => getMockWidget("MintGAContainer")}>
348
+ Mint - With Container
349
+ </button>
350
+ <button onClick={() => getMockWidget("VanillaGANoContainer")}>
351
+ Vanilla - No Container
352
+ </button>
353
+ </details>
354
+ );
355
+ }
356
+ const root = document.getElementById("app");
357
+
358
+ render(<App />, root);
@@ -1,14 +1,14 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "demo/dist",
4
- "sourceMap": true,
5
- "noImplicitAny": false,
6
- "allowSyntheticDefaultImports": true,
7
- "strictNullChecks": true,
8
- "module": "commonjs",
9
- "target": "es5",
10
- "allowJs": true,
11
- "jsx": "react",
12
- "lib": ["es2015", "dom", "es5", "scripthost"]
13
- }
14
- }
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "demo/dist",
4
+ "sourceMap": true,
5
+ "noImplicitAny": false,
6
+ "allowSyntheticDefaultImports": true,
7
+ "strictNullChecks": true,
8
+ "module": "commonjs",
9
+ "target": "es5",
10
+ "allowJs": true,
11
+ "jsx": "react",
12
+ "lib": ["es2015", "dom", "es5", "scripthost"]
13
+ }
14
+ }