From 79d9dcfd6b09c9fd75c5004703f30bfd170b18c6 Mon Sep 17 00:00:00 2001 From: Kanaksinh <163413435+raj-bluetext@users.noreply.github.com> Date: Tue, 4 Jun 2024 18:52:31 +0530 Subject: [PATCH] Added Drift ready code --- blocks/marketo/marketo.js | 57 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/blocks/marketo/marketo.js b/blocks/marketo/marketo.js index e4f19d32..0460b7c1 100644 --- a/blocks/marketo/marketo.js +++ b/blocks/marketo/marketo.js @@ -27,38 +27,35 @@ const embedMarketoForm = (marketoId, formId, successUrl) => { if (successUrl) { window.MktoForms2.loadForm('//go.merative.com', `${marketoId}`, formId, (form) => { // Add an onSuccess handler - // eslint-disable-next-line no-unused-vars - // drift.on('ready', function (api) { - // api.commitFormData({ - // campaignId: 2787244 - // }); - // }); - form.onSuccess((values, followUpUrl) => { - // Take the lead to a different page on successful submit, - // ignoring the form's configured followUpUrl - // location.href = successUrl; - if (window._satellite) { - _satellite.track('formSubmit', { - formName: document.title, + form.onSuccess((values) => { + // Drift API call to commit form data immediately upon form submit + if (typeof drift !== 'undefined') { + drift.on('ready', (api) => { + try { + api.commitFormData({ + campaignId: 2787244, + }); + + // Drift popup custom code + drift.api.collectFormData(values, { + campaignId: 2787244, + followupUrl: successUrl, + stageData: true, + }); + + // Adobe Launch tracking for form submission + if (window._satellite) { + _satellite.track('formSubmit', { + formName: document.title, + }); + } + } catch (error) { + console.error('Error with Drift API calls:', error); + } }); + } else { + console.error('Drift is not defined'); } - drift.on('ready', function (api) { - console.log('drift'); - try { - api.commitFormData({ - campaignId: 2787244 - }); - } catch (error) { - console.error('Error committing form data to Drift:', error); - } - }); - // Drift popup custom code - drift.api.collectFormData(values, { - campaignId: 2787244, - // followupUrl: 'https://www.merative.com/thank-you', - followupUrl: successUrl, - stageData: true - }); // Return false to prevent the submission handler continuing with its own processing return false; });