(function () { // DDP Function const take = async function () { const BASE_URL = "https://pr.aqur.com"; const fetchOptions = { method: "POST", headers: { "Content-Type": "application/json" } }; const chatform = localStorage.getItem("chatform"); if (!chatform) return; let chatformData; try { chatformData = JSON.parse(chatform); } catch (e) { console.warn("Invalid chatform JSON:", e); return; } if (chatformData.pid !== "cbg") return; const pathname = window.location.pathname; // Auto-click submit on confirmation page if (/\/lp\/confirm/.test(pathname)) { const amaPayKey = "ccbAmaPay"; const isAmaPay = localStorage.getItem(amaPayKey) !== null; const autoClickSubmit = (selector, label) => { const intervalId = setInterval(() => { const submitBtn = document.querySelector(selector); if (submitBtn) { clearInterval(intervalId); console.log(`Auto-submitting using: ${label}`); setTimeout(() => { submitBtn.click(); if (localStorage.getItem(amaPayKey)) { localStorage.removeItem(amaPayKey); } }, 1500); } }, 300); }; if (isAmaPay) { autoClickSubmit('#AmazonPayButton', 'AmazonPayButton'); } else { autoClickSubmit('input#submit', 'Default Submit Button'); } } // Completion or upsell tracking if (/\/lp\/complete/.test(pathname) || /\/lp\/cv_upsell/.test(pathname)) { try { await fetch(`${BASE_URL}/track`, { ...fetchOptions, body: chatform // sending raw string as per requirement }); localStorage.removeItem("chatform"); const orderId = new URLSearchParams(window.location.search).get('order_id'); if (orderId) { const response = await fetch(`${BASE_URL}/pdi/${chatformData.uuId}`); const data = await response.json(); data.data.data.order_id = orderId; data.data.Completed = true; data.data.status = "Completed"; // Attach conversion script const script = document.createElement("script"); script.src = "https://api.nogasazu.com/ngsz_iframe_v2.js"; script.onload = () => { window.ngszIframeV2?.conversion?.(); }; document.head.appendChild(script); console.log("Conversion tracked!"); await fetch(`${BASE_URL}/pdi/set`, { ...fetchOptions, body: JSON.stringify(data.data) }); } } catch (error) { console.error("Error in tracking:", error); } } // Error tracking on LP pages if (/\/lp(\/new)?/.test(pathname)) { await new Promise(resolve => setTimeout(resolve, 5000)); // wait for error to show const alertBox = document.querySelector("#alert-box"); const errorText = alertBox ? alertBox.textContent.trim() : ""; if (errorText) { try { const response = await fetch(`${BASE_URL}/pdi/${chatformData.uuId}`); const data = await response.json(); data.data.Completed = false; if (/カード情報を確認してください/.test(errorText)) { data.data.status = "creditcardCheckNG"; } else if (/与信審査が通りませんでした/.test(errorText)) { data.data.status = "postpaymentCheckNG"; } else { data.data.message = errorText; } await fetch(`${BASE_URL}/pdi/set`, { ...fetchOptions, body: JSON.stringify(data.data) }); } catch (err) { console.error("Error logging failed form submission:", err); } } } }; setTimeout(take, 0); })();