<script>
const VALID_STORE_CODES = ["STORE_NOVA", "STORE_DC", "STORE_TYSONS"];
// Read URL parameters Meta passes in
const params = new URLSearchParams(window.location.search);
const productId = params.get("productId");
const storeCode = params.get("storeCode");
// Validate product ID
if (!productId || !/^[a-zA-Z0-9_-]+$/.test(productId)) {
window.location.href = "/error?reason=invalid_product";
}
// Validate store code if provided
else if (storeCode && !VALID_STORE_CODES.includes(storeCode)) {
window.location.href = "/error?reason=invalid_store";
}
// All good — redirect to your Squarespace shop page
else {
let redirectUrl = `/shop?productId=${productId}`;
if (storeCode) redirectUrl += `&storeCode=${storeCode}`;
window.location.href = redirectUrl;
}
</script>