document.addEventListener('DOMContentLoaded', function () {
var hasTracked = false;
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
// CF7 の送信成功メッセージを検知
if (
!hasTracked &&
node.nodeType === 1 &&
node.classList.contains('wpcf7-response-output') &&
(node.classList.contains('wpcf7-mail-sent-ok') || node.classList.contains('wpcf7-form-sent'))
) {
hasTracked = true;
console.log("SubmitForm fired"); // デバッグ用(不要なら削除OK)
if (typeof ttq !== 'undefined') {
ttq.track('SubmitForm');
}
}
});
});
});
// CF7フォームを監視対象にする
var forms = document.querySelectorAll('.wpcf7');
forms.forEach(function (form) {
observer.observe(form, { childList: true, subtree: true });
});
});