diff --git a/blocks/marketo/marketo.js b/blocks/marketo/marketo.js index dac6772c..1024fdfc 100644 --- a/blocks/marketo/marketo.js +++ b/blocks/marketo/marketo.js @@ -20,15 +20,22 @@ const loadScript = (url, attrs) => { return script; }; -const embedMarketoForm = (marketoId, formId, successUrl) => { +const embedMarketoForm = (marketoId, formId, successUrl, driftCampaignID, fastlaneEnable) => { if (formId && marketoId) { const mktoScriptTag = loadScript('//go.merative.com/js/forms2/js/forms2.min.js'); mktoScriptTag.onload = () => { - if (successUrl) { + if (successUrl) { window.MktoForms2.loadForm('//go.merative.com', `${marketoId}`, formId, (form) => { // Add an onSuccess handler // eslint-disable-next-line no-unused-vars form.onSuccess((values, followUpUrl) => { + // Adding drift script for chatbot + if (fastlaneEnable) { + drift.api.collectFormData(values, { + campaignId: Number(driftCampaignID), + followupUrl: '/thank-you', + }); + } // Take the lead to a different page on successful submit, // ignoring the form's configured followUpUrl location.href = successUrl; @@ -83,6 +90,8 @@ export default function decorate(block) { const formTitle = blockConfig['form-title']; const formId = blockConfig['form-id']; const successUrl = blockConfig['success-url']; + const driftCampaignID = blockConfig['drift-campaign-id']; + const fastlaneEnable = JSON.parse(blockConfig['fastlane-enable'] || false); if (formId && marketoId) { // Create the form element @@ -103,7 +112,7 @@ export default function decorate(block) { const observer = new IntersectionObserver((entries) => { if (entries.some((e) => e.isIntersecting)) { // Embed the Marketo form - embedMarketoForm(marketoId, formId, successUrl); + embedMarketoForm(marketoId, formId, successUrl, driftCampaignID, fastlaneEnable); observer.disconnect(); } });