-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct.html
More file actions
156 lines (146 loc) · 5.27 KB
/
Copy pathproduct.html
File metadata and controls
156 lines (146 loc) · 5.27 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mock Ecomm - Product</title>
<script>
window.dataLayer = window.dataLayer || [];
</script>
<script src="assets/js/axeptio-loader.js"></script>
<script src="https://cdn.amplitude.com/script/89bcc735451f7bc5c17d2d992c6b1aa0.experiment.js"></script>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-PNGFSP9L');</script>
<!-- End Google Tag Manager -->
<link rel="stylesheet" href="assets/css/styles.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<style>
.product-detail {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
max-width: 500px;
margin: 3rem auto 2rem auto;
background: #fff;
border-radius: 1.5rem;
box-shadow: 0 4px 32px rgba(99, 102, 241, 0.10);
padding: 2.5rem 2rem 2rem 2rem;
}
.product-detail-img {
width: 260px;
height: 260px;
object-fit: cover;
border-radius: 1.2rem;
margin-bottom: 2rem;
box-shadow: 0 2px 16px rgba(99, 102, 241, 0.10);
}
.product-detail-info h1 {
font-size: 2rem;
margin-bottom: 0.5rem;
color: #222;
}
.product-detail-price {
font-size: 1.5rem;
color: #6366f1;
font-weight: 700;
margin-bottom: 1rem;
}
.product-detail-info p {
color: #555;
margin-bottom: 2rem;
}
.btn-primary {
font-size: 1.2rem;
padding: 1rem 2.5rem;
border-radius: 2rem;
}
</style>
</head>
<body>
<header id="header-placeholder"></header>
<main>
<section class="product-detail">
<!-- Product content will be injected here by JavaScript -->
</section>
</main>
<footer>
<p>© 2025 MockEcomm. All rights reserved.</p>
</footer>
<script src="assets/js/product-data.js"></script>
<script src="assets/js/auth.js"></script>
<script src="assets/js/main.js"></script>
<script src="assets/js/header-loader.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const productDetailSection = document.querySelector('.product-detail');
const params = new URLSearchParams(window.location.search);
const productId = params.get('id');
const product = productCatalog[productId];
if (!product) {
productDetailSection.innerHTML = '<h2>Product not found</h2>';
return;
}
// Dynamically render product content
document.title = product.item_name + ' - Mock Ecomm';
productDetailSection.innerHTML = `
<div class="product-image">
<img src="https://picsum.photos/id/${productId.substring(1) * 10 + 100}/600/600" alt="${product.item_name}">
</div>
<div class="product-info">
<h1>${product.item_name}</h1>
<p class="price">$${product.price.toFixed(2)}</p>
<p class="description">This is a great product. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<div class="actions">
<input type="number" value="1" min="1" id="quantity-input">
<button class="btn" id="add-to-cart-btn">Add to Cart</button>
</div>
</div>
`;
// --- GA4 Page Load Events ---
const itemForGA = { ...product, quantity: 1 };
window.dataLayer.push(enrichDataLayer({
event: 'page_view',
page_category: 'Product Detail Page'
}));
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push(enrichDataLayer({
event: 'view_item',
ecommerce: {
currency: 'USD',
value: product.price,
items: [itemForGA]
}
}));
// --- GA4 Interaction Events ---
document.getElementById('add-to-cart-btn').addEventListener('click', function() {
const quantity = parseInt(document.getElementById('quantity-input').value, 10);
const itemForCart = { ...product, quantity: quantity };
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push(enrichDataLayer({
event: 'add_to_cart',
ecommerce: {
currency: 'USD',
value: itemForCart.price * itemForCart.quantity,
items: [itemForCart]
}
}));
// Add item to a client-side cart (using sessionStorage)
let cart = JSON.parse(sessionStorage.getItem('cart')) || [];
const existingItemIndex = cart.findIndex(item => item.item_id === itemForCart.item_id);
if (existingItemIndex > -1) {
cart[existingItemIndex].quantity += quantity;
} else {
cart.push(itemForCart);
}
sessionStorage.setItem('cart', JSON.stringify(cart));
alert(product.item_name + ' has been added to your cart!');
});
});
</script>
</body>
</html>