-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout.html
More file actions
105 lines (103 loc) · 4.05 KB
/
Copy pathcheckout.html
File metadata and controls
105 lines (103 loc) · 4.05 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mock Ecomm - Checkout</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 class="checkout-section">
<div class="checkout-form">
<h2>Shipping Information</h2>
<form id="checkout-form">
<div class="form-group">
<label for="name">Full Name</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" id="address" name="address" required>
</div>
<div class="form-group">
<label for="card">Credit Card</label>
<input type="text" id="card" name="card" placeholder="0000 0000 0000 0000" required>
</div>
<button type="submit" class="btn">Place Order</button>
</form>
</div>
<div class="order-summary" id="order-summary-container">
<h3>Order Summary</h3>
<!-- Order summary will be injected here -->
</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() {
const summaryContainer = document.getElementById('order-summary-container');
const cart = JSON.parse(sessionStorage.getItem('cart')) || [];
// GA4: page_view
window.dataLayer.push(enrichDataLayer({
event: 'page_view',
page_category: 'Checkout'
}));
if (cart.length === 0) {
summaryContainer.innerHTML = '<h3>Order Summary</h3><p>Your cart is empty.</p>';
document.querySelector('.checkout-form').style.display = 'none';
return;
}
let summaryHTML = '<h3>Order Summary</h3><ul>';
let totalValue = 0;
cart.forEach(item => {
const itemTotal = item.price * item.quantity;
totalValue += itemTotal;
summaryHTML += `
<li class="summary-item">
<span>${item.item_name} (x${item.quantity})</span>
<span>$${itemTotal.toFixed(2)}</span>
</li>`;
});
summaryHTML += `</ul><p class="summary-total">Total: <strong>$${totalValue.toFixed(2)}</strong></p>`;
summaryContainer.innerHTML = summaryHTML;
// GA4: begin_checkout
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push(enrichDataLayer({
event: 'begin_checkout',
ecommerce: {
currency: 'USD',
value: totalValue,
items: cart
}
}));
document.getElementById('checkout-form').addEventListener('submit', function(e) {
e.preventDefault(); // Prevent actual form submission for this mock
const transactionId = 'T' + Date.now();
// Redirect to confirmation page
window.location.href = `confirmation.html?id=${transactionId}&total=${totalValue}`;
});
});
</script>
</body>
</html>