-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
392 lines (347 loc) ยท 13.9 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Music Gear Store</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
}
h1 {
margin-top: 20px;
color: #333;
}
.product-container {
display: flex;
justify-content: center;
flex-wrap: wrap;
margin: 20px 0;
}
.product {
border: 1px solid #ddd;
background-color: #fff;
border-radius: 8px;
padding: 16px;
margin: 16px;
width: 300px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
text-align: center;
}
.product .emoji {
font-size: 80px;
margin-bottom: 10px;
}
.product h2 {
font-size: 20px;
color: #333;
}
.product p {
font-size: 18px;
color: #555;
}
.button {
border: none;
color: white;
padding: 10px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin: 8px 2px;
cursor: pointer;
border-radius: 5px;
transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.button.view-product {
background-color: #008CBA; /* Blue */
}
.button.add-to-cart {
background-color: #04AA6D; /* Green */
}
.button:active {
transform: scale(0.95);
box-shadow: 0 5px #666;
}
.cart-items {
width: 80%;
max-width: 800px;
margin-top: 20px;
padding: 20px;
border: 1px solid #ddd;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.cart-total {
margin-top: 10px;
font-size: 18px;
color: #333;
}
.purchase-button {
background-color: #f44336; /* Red */
border: none;
color: white;
padding: 12px 28px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
margin-top: 10px;
border-radius: 5px;
}
/* Modal styling */
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
padding-top: 60px;
}
.modal-content {
background-color: #fefefe;
margin: 5% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 300px;
text-align: center;
border-radius: 8px;
}
.modal-content .close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.modal-content .close:hover,
.modal-content .close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
.modal .product-icon {
font-size: 50px;
margin-bottom: 15px;
}
.modal .product-description {
font-size: 16px;
color: #333;
margin: 20px 0;
}
</style>
<script>
(function(name, path, ctx){
ctx[name] = ctx[name] || {
ready: function(fn){
var h = document.getElementsByTagName('head')[0],
s = document.createElement('script'),
loaded;
s.onload = s.onerror = s.onreadystatechange = function(){
if ((s.readyState && !(/^c|loade/.test(s.readyState))) || loaded) {
return;
}
s.onload = s.onreadystatechange = null;
loaded = 1;
ctx[name].ready(fn);
};
s.async = 1;
s.src = path;
h.parentNode.insertBefore(s, h);
}
};
})('KeenTracking', 'https://cdn.jsdelivr.net/npm/keen-tracking@4/dist/keen-tracking.min.js', this);
KeenTracking.ready(function() {
const client = new KeenTracking({
projectId: '66bd7269ee261c601ba6152d',
writeKey: '3476b1a8244bdd7ac4ed0dab8d57a919f771afac2da7f2b2c21ac34ef44b8a0a7978084adf51fe538922a15a79dfe5b8e63e6e0bc0ce32a7f58d17eefbca2ca3604d2f5587a7aa28a56c19d4908754889601598fd3024a69d6697248c60ee1ef'
});
// Generate a UUID to track the user session
const userUUID = generateUUID();
console.log("Your unique user id is: " + userUUID);
// Track initial page view
client.recordEvent('page_view', {
uuid: userUUID,
page: 'Music Gear Store',
timestamp: new Date().toISOString()
});
console.log('Page view event tracked:', {
uuid: userUUID,
page: 'Music Gear Store',
timestamp: new Date().toISOString()
});
// Add event listeners to product detail buttons
const pdpButtons = document.querySelectorAll('.view-product');
pdpButtons.forEach(button => {
button.addEventListener('click', function() {
const productId = this.dataset.productId;
const productName = this.dataset.productName;
const productDescription = getProductDescription(productName);
const productIcon = getProductIcon(productName);
const pdpEvent = {
uuid: userUUID,
product_id: productId,
product_name: productName,
timestamp: new Date().toISOString()
};
client.recordEvent('pdp_view', pdpEvent);
console.log('PDP view event tracked:', pdpEvent);
showModal(productIcon, productDescription);
});
});
// Add event listeners to add to cart buttons
const cart = [];
const addToCartButtons = document.querySelectorAll('.add-to-cart');
addToCartButtons.forEach(button => {
button.addEventListener('click', function() {
const productId = this.dataset.productId;
const productName = this.dataset.productName;
const productPrice = parseFloat(this.dataset.productPrice);
cart.push({ id: productId, name: productName, price: productPrice });
const cartEvent = {
uuid: userUUID,
product_id: productId,
product_name: productName,
cart_contents: cart.map(item => item.name).join(', '),
cart_value: cart.reduce((total, item) => total + item.price, 0),
timestamp: new Date().toISOString()
};
client.recordEvent('add_to_cart', cartEvent);
console.log('Add to cart event tracked:', cartEvent);
updateCartDisplay(cart);
});
});
// Purchase button click event
document.querySelector('.purchase-button').addEventListener('click', function() {
const totalValue = cart.reduce((total, item) => total + item.price, 0);
const purchaseEvent = {
uuid: userUUID,
items_purchased: cart,
total_items: cart.length,
total_value: totalValue,
timestamp: new Date().toISOString()
};
client.recordEvent('purchase', purchaseEvent);
console.log('Purchase event tracked:', purchaseEvent);
showModal("๐", "Purchase completed! Total value: $" + totalValue.toFixed(2) + ". A copy of your receipt has been sent to your email.");
});
// Helper function to update cart display
function updateCartDisplay(cart) {
const cartDisplay = document.querySelector('.cart-items');
const totalValue = cart.reduce((total, item) => total + item.price, 0);
cartDisplay.innerHTML = '<strong>Cart Items:</strong><br>' + cart.map(item => item.name + ' - $' + item.price.toFixed(2)).join('<br>');
document.querySelector('.cart-total').innerHTML = 'Total Value: $' + totalValue.toFixed(2);
}
// Helper function to generate a UUID
function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
// Show modal function with custom icon and content
function showModal(icon, content) {
const modal = document.getElementById("cartModal");
const modalIcon = modal.querySelector('.product-icon');
const modalContent = modal.querySelector('.product-description');
modalIcon.innerHTML = icon;
modalContent.innerHTML = content;
modal.style.display = "block";
}
// Close modal when clicking the close button or outside of the modal
document.querySelector('.modal .close').onclick = function() {
const modal = document.getElementById("cartModal");
modal.style.display = "none";
};
window.onclick = function(event) {
const modal = document.getElementById("cartModal");
if (event.target == modal) {
modal.style.display = "none";
}
};
// Function to return product descriptions
function getProductDescription(productName) {
switch (productName) {
case 'Guitar':
return 'This guitar is crafted from premium woods and delivers a rich, warm tone perfect for any genre. Ideal for both beginners and professionals.';
case 'Turntable':
return 'Our turntable offers unparalleled sound quality and a sleek design. Itโs a must-have for any vinyl enthusiast.';
case 'Synthesizer':
return 'The synthesizer is equipped with a variety of features, making it a versatile instrument for creating a wide range of sounds.';
default:
return 'Product details are currently unavailable.';
}
}
// Function to return product icons
function getProductIcon(productName) {
switch (productName) {
case 'Guitar':
return '๐ธ';
case 'Turntable':
return '๐๏ธ๐๏ธ๐ง';
case 'Synthesizer':
return '๐น';
default:
return 'โน๏ธ';
}
}
});
</script>
</head>
<body>
<h1>Music Gear Store</h1>
<div class="product-container">
<div class="product">
<div class="emoji">๐ธ</div>
<h2>Guitar</h2>
<p>Price: $500</p>
<button class="button view-product" data-product-id="1" data-product-name="Guitar">View Product</button>
<button class="button add-to-cart" data-product-id="1" data-product-name="Guitar" data-product-price="500">Add to Cart</button>
</div>
<div class="product">
<div class="emoji">๐๏ธ๐๏ธ๐ง</div>
<h2>Turntable</h2>
<p>Price: $300</p>
<button class="button view-product" data-product-id="2" data-product-name="Turntable">View Product</button>
<button class="button add-to-cart" data-product-id="2" data-product-name="Turntable" data-product-price="300">Add to Cart</button>
</div>
<div class="product">
<div class="emoji">๐น</div>
<h2>Synthesizer</h2>
<p>Price: $700</p>
<button class="button view-product" data-product-id="3" data-product-name="Synthesizer">View Product</button>
<button class="button add-to-cart" data-product-id="3" data-product-name="Synthesizer" data-product-price="700">Add to Cart</button>
</div>
</div>
<div class="cart-items">
<strong>Cart Items:</strong><br>
<!-- Cart items will be listed here -->
</div>
<div class="cart-total">
Total Value: $0.00
</div>
<button class="purchase-button">Purchase</button>
<!-- Modal -->
<div id="cartModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<span class="product-icon"></span>
<p class="product-description"></p>
</div>
</div>
</body>
</html>