-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
293 lines (262 loc) · 13 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Metrix SDK HTML</title>
<meta name="description" content="Generated by create next app">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/mvp.css">
<script src="https://cdn.metrix.ir/sdk/web/metrix.umd-2.2.0.js" ></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
const Toast = Swal.mixin({
toast: true,
position: "top-end",
showConfirmButton: false,
timer: 3000,
timerProgressBar: true,
didOpen: (toast) => {
toast.onmouseenter = Swal.stopTimer;
toast.onmouseleave = Swal.resumeTimer;
}
});
</script>
<style>
button:active {
background: darkseagreen;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
width: 40%;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
.container {
padding: 16px;
}
</style>
</head>
<body>
<main>
<div>
<h3>App ID:</h3>
<input id="init-appid-input" placeholder="App ID">
<h3>API Key:</h3>
<input id="init-apikey-input" placeholder="API KEY">
<h3>Push public key:</h3>
<input id="init-public-key-input" placeholder="PUBLIC KEY">
<button id="init-button">Init</button>
<button id="close-button">Close</button>
<p id="init-status" style="color: red;">Not initialized</p>
</div>
<div id="send-event-box" hidden>
<hr/>
<div>
<h3>Enter Your username:</h3>
<input id="login-input" placeholder="[email protected]">
<button id="login-button">Login</button>
<button id="logout-button">Logout</button>
<p id="login-status" style="color: red">Your Anonymous!!!</p>
</div>
<input type="checkbox" id="show-user-send" name="vehicle1">
<label for="show-user-send">
<h4>I want to update user</h4>
</label>
<div id="send-user-box" hidden>
<h3>Send sample user attribute</h3>
<h5>Attributes:</h5>
<div style="display: flex; justify-content: space-between"><label for="first-name-input">First
Name:</label><input id="first-name-input" placeholder="First Name"></div>
<div style="display: flex; justify-content: space-between"><label for="last-name-input">Last Name:</label><input
id="last-name-input" placeholder="Last Name"></div>
<div style="display: flex; justify-content: space-between"><label for="phone-input">Phone Number:</label><input
id="phone-input" placeholder="Phone Number"></div>
<div style="display: flex; justify-content: space-between"><label for="phone-input">Email:</label><input
id="email-input" placeholder="Email"></div>
<div style="display: flex; justify-content: space-between"><label for="city-input">City:</label><input
id="city-input" placeholder="City"></div>
<div style="display: flex; justify-content: space-between"><label for="birth-date-input">Birth Date:</label><input
id="birth-date-input" placeholder="Timestamp"></div>
<h5>Custom Attributes:</h5>
<div style="display: flex; justify-content: space-between">
<label for="user-c-att-key-input">Key:</label><input id="user-c-att-key-input" placeholder="key">
<label for="user-c-att-value-input">Value:</label><input id="user-c-att-value-input" placeholder="value">
</div>
<div style="display: flex; justify-content: space-between">
<label for="user-c-att-key2-input">Key:</label><input id="user-c-att-key2-input" placeholder="key">
<label for="user-c-att-value2-input">Value:</label><input id="user-c-att-value2-input" placeholder="value">
</div>
<button id="user-att-button">Send User</button>
</div>
<div id="event-box" hidden>
<hr/>
<div id="general-event">
<div style="margin-top: 100px">
<h3>Send
<span style="color: red; font-weight: bold">Sample Event With Slug</span>
event with custom attribute:</h3>
<h4>Event Slug:</h4>
<input id="sample-event-c-slug-input" placeholder="Event Slug">
<h4>Custom attributes (Optional): </h4>
<div style="display: flex; justify-content: space-between">
<label for="sample-event-c-att-key-input">Key:</label><input id="sample-event-c-att-key-input" placeholder="key">
<label for="sample-event-c-att-value-input">Value:</label><input id="sample-event-c-att-value-input" placeholder="value">
</div>
<div style="display: flex; justify-content: space-between">
<label for="sample-event-c-att-key2-input">Key:</label><input id="sample-event-c-att-key2-input" placeholder="key">
<label for="sample-event-c-att-value2-input">Value:</label><input id="sample-event-c-att-value2-input" placeholder="value">
</div>
<button id="sample-event-button" disabled>Send <span style="color: yellowgreen; font-weight: bold">Sample Event</span></button>
</div>
</div>
</div>
<script>
let username = localStorage.getItem("username");
const appId = localStorage.getItem('appId');
const apiKey = localStorage.getItem('apiKey');
const publicKey = localStorage.getItem('publicKey');
if (appId && apiKey && publicKey) {
const config = {
push: {
enabled : true, // defaults to false but if set to true you must provide publicKey.
publicKey: publicKey, // your push subscription public key.
showBell: true
}
}
Metrix.init(appId, apiKey, config);
document.getElementById('init-appid-input').value = appId;
document.getElementById('init-apikey-input').value = apiKey;
document.getElementById('init-public-key-input').value = publicKey;
document.getElementById('init-status').innerText = 'Metrix initialized';
document.getElementById('init-status').style.color = 'green'
document.getElementById('send-event-box').removeAttribute('hidden');
document.getElementById('init-button').disabled = true;
}
if (username) {
document.getElementById("login-status").innerHTML = "You're logged in as: " + username;
document.getElementById("login-status").style.color = 'green';
document.getElementById("login-button").disabled = true
username = document.getElementById("login-input").value = username;
document.getElementById('event-box').removeAttribute('hidden')
Metrix.authorizeUser(username)
}
document.getElementById('init-button').onclick = () => {
const appId = document.getElementById('init-appid-input').value;
const apiKey = document.getElementById('init-apikey-input').value;
const publicKey = document.getElementById('init-public-key-input').value;
if (appId.length && apiKey.length && publicKey.length) {
localStorage.setItem('appId', appId);
localStorage.setItem('apiKey', apiKey);
localStorage.setItem('publicKey', publicKey);
document.getElementById('init-status').innerText = 'Metrix initialized';
document.getElementById('init-status').style.color = 'green';
const config = {
push: {
enabled : true, // defaults to false but if set to true you must provide publicKey.
publicKey: publicKey, // your push subscription public key.
showBell: true
}
}
Metrix.init(appId, apiKey, config);
document.getElementById('send-event-box').removeAttribute('hidden')
}
}
document.getElementById('close-button').onclick = () => {
localStorage.removeItem('appId');
localStorage.removeItem('apiKey');
localStorage.removeItem("username");
localStorage.removeItem('publicKey')
Metrix.deauthorizeUser()
window.location.reload();
}
document.getElementById("login-button").onclick = () => {
username = document.getElementById("login-input").value;
if (username.length) {
localStorage.setItem("username", username)
Metrix.authorizeUser(username)
document.getElementById("login-status").innerHTML = "You're logged in as: " + username;
document.getElementById("login-status").style.color = 'green';
document.getElementById('event-box').removeAttribute('hidden')
}
}
document.getElementById("logout-button").onclick = () => {
username = undefined
localStorage.removeItem("username")
Metrix.deauthorizeUser()
document.getElementById("login-button").disabled = false;
document.getElementById('login-input').value = '';
document.getElementById("login-status").innerHTML = "You're logged out!!!"
document.getElementById("login-status").style.color = "red";
document.getElementById('event-box').setAttribute('hidden', '')
}
document.getElementById('show-user-send').onchange = (e) => {
const checked = e.target.checked;
const userSendBox = document.getElementById('send-user-box')
if (checked) {
userSendBox.removeAttribute('hidden')
} else {
userSendBox.setAttribute('hidden', '')
}
}
document.getElementById("user-att-button").onclick = () => {
const firstname = document.getElementById("first-name-input").value;
const lastname = document.getElementById("last-name-input").value;
const phone = document.getElementById("phone-input").value;
const email = document.getElementById("email-input").value;
const city = document.getElementById('city-input').value;
const birthDate = document.getElementById('birth-date-input').value;
const key = document.getElementById("user-c-att-key-input").value;
const value = document.getElementById("user-c-att-value-input").value;
const key2 = document.getElementById("user-c-att-key2-input").value;
const value2 = document.getElementById("user-c-att-value2-input").value;
if (firstname)
Metrix.setFirstName(firstname)
if (lastname)
Metrix.setLastName(lastname)
if (phone)
Metrix.setPhoneNumber(phone)
if (email)
Metrix.setEmail(email)
if (city)
Metrix.setCity(city);
if (birthDate)
Metrix.setBirthday(birthDate);
if (key && value)
Metrix.setCustomAttribute(key, value)
if (key2 && value2)
Metrix.setCustomAttribute(key2, value2)
Toast.fire({
icon: "success",
title: "User Updated"
});
}
document.getElementById("sample-event-button").onclick = () => {
const key = document.getElementById("sample-event-c-att-key-input")?.value;
const value = document.getElementById("sample-event-c-att-value-input")?.value;
const key2 = document.getElementById("sample-event-c-att-key2-input")?.value;
const value2 = document.getElementById("sample-event-c-att-value2-input")?.value;
const attributes = {};
if (key && value)
attributes[key] = value;
if (key2 && value2)
attributes[key2] = value2;
const eventSlug = document.getElementById('sample-event-c-slug-input').value;
if (eventSlug) {
Metrix.newEvent(eventSlug, attributes);
Toast.fire({
icon: "success",
title: "Event Sent"
});
}
}
document.getElementById('sample-event-c-slug-input').oninput = (e) => {
const value = e.target.value;
document.getElementById('sample-event-button').disabled = !(value.length === 5)
}
</script>
</main>
</body>
</html>