WIX Integration
Last updated
<script type="text/javascript">
window.onmessage = (event) => {
const data = event.data;
if (!data || data.type !== "ORDER_AND_CLICK") return;
const order = data.order;
const clickId = data.click_id || "";
// --- Calculate amount WITHOUT shipping ---
const orderTotal = Number(order?.totals?.total ?? 0);
const shippingAmount =
Number(order?.totals?.shipping ?? 0) ||
Number(order?.shippingInfo?.shippingFee ?? 0);
const amountWithoutShipping = Math.max(
0,
(orderTotal - shippingAmount).toFixed(2)
);
// --- Extract coupon code (if any) ---
let couponCode = "";
if (order?.discount?.coupon?.code) {
couponCode = order.discount.coupon.code;
} else if (Array.isArray(order?.discounts) && order.discounts[0]?.coupon?.code) {
couponCode = order.discounts[0].coupon.code;
}
var img = document.createElement("img");
img.src =
"https://{namespace}-tracking.tracknow.info/success.jpg" +
"?campaign_id={campaign ID}" +
"&amount=" + encodeURIComponent(amountWithoutShipping) +
"&order_id=" + encodeURIComponent(order?.number ?? "") +
"&click_id=" + encodeURIComponent(clickId) +
"&coupon=" + encodeURIComponent(couponCode);
img.height = "1";
img.width = "1";
img.style.display = "none";
document.body.appendChild(img);
};
</script>import { local } from 'wix-storage';
$w.onReady(function () {
const clickId = local.getItem("click_id") || "";
$w('#thankYouPage1').getOrder()
.then((order) => {
$w('#html3').postMessage({
type: "ORDER_AND_CLICK",
order: order,
click_id: clickId
});
})
.catch(() => {});
});