@saasquatch/squatch-js 2.3.0 → 2.3.1-3

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,249 @@
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
+
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,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
+ }
package/demo/util.ts CHANGED
@@ -1,22 +1,22 @@
1
- export function getQueryStringParams(query) {
2
- return query
3
- ? (/^[?#]/.test(query) ? query.slice(1) : query)
4
- .split("&")
5
- .reduce((params, param) => {
6
- let [key, value] = param.split("=");
7
- params[key] = value
8
- ? decodeURIComponent(value.replace(/\+/g, " "))
9
- : "";
10
- return params;
11
- }, {})
12
- : {};
13
- }
14
-
15
-
16
- export function delay (duration) {
17
- return new Promise(function(resolve, reject){
18
- setTimeout(function(){
19
- resolve();
20
- }, duration)
21
- })
1
+ export function getQueryStringParams(query) {
2
+ return query
3
+ ? (/^[?#]/.test(query) ? query.slice(1) : query)
4
+ .split("&")
5
+ .reduce((params, param) => {
6
+ let [key, value] = param.split("=");
7
+ params[key] = value
8
+ ? decodeURIComponent(value.replace(/\+/g, " "))
9
+ : "";
10
+ return params;
11
+ }, {})
12
+ : {};
13
+ }
14
+
15
+
16
+ export function delay (duration) {
17
+ return new Promise(function(resolve, reject){
18
+ setTimeout(function(){
19
+ resolve();
20
+ }, duration)
21
+ })
22
22
  }
package/demo/versions.ts CHANGED
@@ -1,14 +1,14 @@
1
- export async function getVersions(): Promise<string[]> {
2
- const headers = {
3
- Origin: "google.com",
4
- "X-Requested-With":
5
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
6
- };
7
-
8
- const response = await fetch(
9
- "https://cors-anywhere.herokuapp.com/https://registry.npmjs.org/@saasquatch/squatch-js",
10
- {}
11
- );
12
- const body = await response.json();
13
- return Object.keys(body.versions).reverse();
14
- }
1
+ export async function getVersions(): Promise<string[]> {
2
+ const headers = {
3
+ Origin: "google.com",
4
+ "X-Requested-With":
5
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
6
+ };
7
+
8
+ const response = await fetch(
9
+ "https://cors-anywhere.herokuapp.com/https://registry.npmjs.org/@saasquatch/squatch-js",
10
+ {}
11
+ );
12
+ const body = await response.json();
13
+ return Object.keys(body.versions).reverse();
14
+ }
@@ -42,7 +42,7 @@ export default class EventsApi {
42
42
  * Track an event for a user
43
43
  *
44
44
  * @param params Parameters for request
45
- * @param params.jwt the JSON Web Token (JWT) that is used to authenticate the user
45
+ * @param options.jwt the JSON Web Token (JWT) that is used to authenticate the user
46
46
  *
47
47
  * @return An ID to confirm the event has been accepted for asynchronous processing
48
48
  */