let pmfApplyFrameWrapper = document.getElementById('pmfApplyFrame'); const { dataset } = pmfApplyFrameWrapper; const { termsOfServiceUrl, thankYouPageUrl, branded, organization } = dataset ?? {}; const termsOfConditionQuery = termsOfServiceUrl ? `termsOfServiceUrl=${encodeURIComponent(termsOfServiceUrl)}` : undefined; const thankYouPageQuery = thankYouPageUrl ? `thankYouPageUrl=${encodeURIComponent(thankYouPageUrl)}` : undefined; const brandedPage = branded ? `brandedPage=${encodeURIComponent(branded)}` : undefined; const organizationValue = organization ? `organization=${encodeURIComponent(organization)}` : undefined; const extraParams = [termsOfConditionQuery, thankYouPageQuery, brandedPage, organizationValue] .filter(Boolean) .join('&'); // Extract referralId from the WordPress page URL const pathParts = window.location.pathname.split('/').filter(Boolean); const knownPrefixes = ['getfundingnow', 'apply-iframe.html', 'getfundingnow-dev-testing']; // Extend if needed let referralId = undefined; if (!referralId) referralId = new URLSearchParams(window.location.search).get('ref'); if (!referralId && pathParts.length >= 2 && knownPrefixes.includes(pathParts[pathParts.length - 2])) { referralId = pathParts[pathParts.length - 1]; } let iframe = document.createElement('iframe'); iframe.src = `https://apply.myrmapp.com/apply${referralId ? '/' + referralId : ''}?mode=iframe&origin=${window.location.href}${extraParams ? '&' + extraParams : ''}`; iframe.width = '100%'; iframe.height = '100%'; iframe.style.border = '0'; iframe.style.borderRadius = '3px'; iframe.name = 'pmfApplyFrame'; iframe.allow = 'clipboard-read; clipboard-write' pmfApplyFrameWrapper.appendChild(iframe);