forked from 8ctopus/sciter-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.htm
More file actions
314 lines (258 loc) · 8.32 KB
/
main.htm
File metadata and controls
314 lines (258 loc) · 8.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<html
window-width="800dip"
window-height="800dip"
>
<head>
<title>sciter analytics demo</title>
<style>
@import url(node_modules/sciter-logger/src/logger.css);
@import url(node_modules/sciter-pagecontrol/src/pagecontrol.css);
@import url(css/themes/default.css);
div.vbox {
width: 200dip;
}
</style>
<script type="module">
import {uuid} from "@sciter";
import Logger from "node_modules/sciter-logger/src/logger.js";
import * as Utils from "node_modules/sciter-utils/src/utils.js";
import Dialogs from "node_modules/sciter-dialogs/src/dialogs.js";
import Analytics from "src/analytics.js";
// initialize logger
Logger.init({
file: URL.toPath(__DIR__ + "test.log"),
clear: true,
});
// attach logger to console
Logger.attach();
// capture unhandled exceptions
Logger.capture();
document.on("ready", function() {
// subscribe to logger messages
Logger.plaintext(document.$("plaintext#logger"));
// log sciter version
console.debug(Utils.sciterInfo());
// initialize
Analytics.init({
log: true,
endpoint: "https://api2.amplitude.com/2/httpapi",
apikey: "0fad02b65a75f270c199db6b920fbf92",
user_id: "123456",
event_properties: {appName: "Sciter analytics", appRelease: "debug"}
//endpoint: "http://localhost/index.php",
//endpoint: "https://httpbin.org/post",
});
// set device info
Analytics.device({device_model : "iPhone 11", platform: "iOS", os_version: "15,4", device_id: "6666ABC"});
// add more environmental variables
/**
Analytics.env({
api_key: "0fad02b65a75f270c199db6b920fbf92",
name: "analytics",
version: "0.0.1",
uuid: uuid(),
});
*/
Analytics.event("app started");
// Analytics.watch("focus", "plaintext", "plaintext focused");
// Analytics.watch("focus", undefined, "focus");
// watch app install click
Analytics.watch("click", "#installCTP", "Install", {installed_app_name: "CopyTrans Photo"});
Analytics.watch("click", "#installCT", "Install CT");
Analytics.watch("click", "#installCTBE","Install CTBE");
// watch app close
Analytics.watch("closerequest", undefined, "app close request");
// add support for F5 reload
Utils.addReloadWindow();
// close window on escape key press
Utils.closeWindowOnEscape(Window.this);
// center window on screen
Utils.centerWindow(Window.this, "screen");
// bring window to front and set input focus
Window.this.activate(true);
});
document.on("closerequest", function(event) {
if (Dialogs.show("question", "Are you sure you want to quit?", "yes no cancel") !== "yes") {
// cancel close
event.preventDefault();
return;
}
Analytics.event("app closed");
});
const headers = {
"Content-Type": "application/json; charset=utf-8",
"Accept": "*/*",
};
document.on("click", "button#httpbin", function() {
const url = "https://httpbin.org/post";
const body = JSON.stringify({
uuid: uuid(),
event: "button clicked",
});
myfetch(url, headers, body);
});
// amplitude test
document.on("click", "button#amplitude", function() {
const url = "https://api2.amplitude.com/2/httpapi";
const body = JSON.stringify({
api_key: "0fad02b65a75f270c199db6b920fbf92",
events: [{
user_id: "datamonster@gmail.com",
device_id: "C8F9E604-F01A-4BD9-95C6-8E5357DF265D",
event_type: "watch_tutorial",
version: "2.1.3",
platform: "iOS",
os_name: "Android",
os_version: "4.2.2",
device_brand: "Verizon",
device_manufacturer: "Apple",
device_model: "iPhone 9,1",
carrier: "Verizon",
country: "United States",
region: "California",
city: "San Francisco",
dma: "San Francisco-Oakland-San Jose, CA",
language: "English",
ip: "127.0.0.1",
}],
});
console.debug(body);
myfetch(url, headers, body);
});
document.on("click", "button#mixpanel", function() {
const url = "https://api.mixpanel.com/track";
const body = JSON.stringify({
event: "Signed up",
properties: {
distinct_id: "13793",
token: "90063d16f08d604ae6f499ba9c689982",
},
});
myfetch(url, headers, body);
});
document.on("click", function(event, element) {
const pagecontrol = document.$("pagecontrol");
switch (element.id) {
case "btLogin":
pagecontrol.showTab("tsDashboard");
break;
case "createAccount":
pagecontrol.showTab("tsSignup");
break;
case "btSignUp":
pagecontrol.showTab("tsLogin");
break;
case "forgotPassword":
pagecontrol.showTab("tsReset");
break;
case "reset":
pagecontrol.showTab("tsSent");
break;
case "showEvents":
Analytics.log();
break;
case "sendEvents":
Analytics.send();
break;
default:
}
});
// handle show tab event
document.on("showtab", "pagecontrol", function(event) {
console.debug(event.detail.tab);
switch (event.detail.tab) {
case "tsLogin":
event = "start login";
break;
case "tsSignup":
event = "start signup";
break;
case "tsDashboard":
event = "end login";
break;
case "tsReset":
event = "start reset";
break;
case "tsSent":
event = "end reset";
break;
default:
}
//console.debug(`event - ${event}`);
// log event
Analytics.event(event);
});
async function myfetch(url, headers, body) {
const response = await fetch(url, {
method: "POST",
cache: "no-cache",
headers,
body,
});
console.line();
console.log(`response status - ${response.status}`);
const json = await response.json();
//console.log(response.text());
console.log(json);
}
</script>
</head>
<body>
<button #httpbin>httpbin</button>
<button #amplitude>amplitude</button>
<button #mixpanel>mixpanel</button>
<button #showEvents>show events</button>
<button #sendEvents>send events</button>
<pagecontrol header-position="top" header-visible="true">
<tab caption="login" #tsLogin selected>
<div .vbox>
<h1> Sign-in </h1>
<label for="email"> Username or email address </label>
<input type="text" #email />
<div .hbox>
<label for="password"> Password </label><a #forgotPassword .right tabindex> Forgot password? </a>
</div>
<input type="password" #password />
<button #btLogin> Login </button>
<p>New? <a #createAccount tabindex>Create an account</a>.</p>
</div>
</tab>
<tab caption="signup" #tsSignup>
<div .vbox>
<h1> Sign Up </h1>
<label for="email2"> Email address </label>
<input type="text" #email2 />
<label for="password2"> Password </label>
<input type="password" #password2 />
<button #btSignUp> Sign up </button>
</div>
</tab>
<tab caption="dashboard" #tsDashboard>
<div .vbox>
<h1> Your Dashboard </h1>
</div>
</tab>
<tab caption="reset" #tsReset>
<div .vbox>
<h1> Reset your password </h1>
<label for="email2"> Enter your user account's verified email address and we will send you a password reset link. </label>
<input type="text" #email2 />
<button #reset> Send password reset email </button>
</div>
</tab>
<tab caption="sent" #tsSent>
<div .vbox>
<h1> Password reset email sent! </h1>
</div>
</tab>
<tab caption="ctcc" #tsCTCC>
<div .vbox>
<a #installCTP>CopyTrans Photo</a>
<a #installCT>CopyTrans</a>
<a #installCTBE>CopyTrans Backup Explorer</a>
</div>
</tab>
</pagecontrol>
<plaintext #logger/>
</body>
</html>