-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducts.html
More file actions
134 lines (128 loc) · 4.71 KB
/
Copy pathproducts.html
File metadata and controls
134 lines (128 loc) · 4.71 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mock Ecomm - Products</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">
</head>
<body>
<header id="header-placeholder"></header>
<main>
<section>
<h2>All Products</h2>
<div class="product-grid">
<div class="product-card">
<a href="product.html?id=P1" class="product-link" data-product-id="P1">
<img src="https://picsum.photos/id/1025/400/400" alt="Product 1">
<h3>Smart Sneakers</h3>
<p>$120</p>
<span class="btn-view">View</span>
</a>
</div>
<div class="product-card">
<a href="product.html?id=P2" class="product-link" data-product-id="P2">
<img src="https://picsum.photos/id/203/400/400" alt="Product 2">
<h3>Eco Hoodie</h3>
<p>$80</p>
<span class="btn-view">View</span>
</a>
</div>
<div class="product-card">
<a href="product.html?id=P3" class="product-link" data-product-id="P3">
<img src="https://picsum.photos/id/237/400/400" alt="Product 3">
<h3>Wireless Earbuds</h3>
<p>$99</p>
<span class="btn-view">View</span>
</a>
</div>
<div class="product-card">
<a href="product.html?id=P4" class="product-link" data-product-id="P4">
<img src="https://picsum.photos/id/10/400/400" alt="Product 4">
<h3>Fitness Tracker</h3>
<p>$150</p>
<span class="btn-view">View</span>
</a>
</div>
<div class="product-card">
<a href="product.html?id=P5" class="product-link" data-product-id="P5">
<img src="https://picsum.photos/id/20/400/400" alt="Product 5">
<h3>Insulated Bottle</h3>
<p>$45</p>
<span class="btn-view">View</span>
</a>
</div>
</div>
</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() {
// --- GA4 Page Load Events ---
// 1. page_view
window.dataLayer.push(enrichDataLayer({
event: 'page_view',
page_category: 'Product Listing Page'
}));
// 2. view_item_list for all products
const productIdsOnPage = ['P1', 'P2', 'P3', 'P4', 'P5'];
const productItems = productIdsOnPage.map((id, index) => {
const product = productCatalog[id];
return {
...product,
index: index,
item_list_id: 'all_products',
item_list_name: 'All Products'
};
});
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push(enrichDataLayer({
event: 'view_item_list',
ecommerce: {
item_list_id: 'all_products',
item_list_name: 'All Products',
items: productItems
}
}));
// --- GA4 Interaction Events ---
// 3. select_item from product list
document.querySelectorAll('.product-link').forEach(link => {
link.addEventListener('click', function(e) {
const productId = this.dataset.productId;
const product = productItems.find(p => p.item_id === productCatalog[productId].item_id);
if (product) {
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push(enrichDataLayer({
event: 'select_item',
ecommerce: {
item_list_id: 'all_products',
item_list_name: 'All Products',
items: [product]
}
}));
}
});
});
});
</script>
</body>
</html>