Skip to content

Commit a83d1d5

Browse files
authored
Update Marketo integration: add inline message feature on form submission (#976)
* Update Marketo integration: add inline message feature on form submission * fully replace the form with the post submit message * fix white background on dark mode * format * remove cache overrides * review --------- Co-authored-by: Nicolas Dorseuil <nicolas@gitbook.io>
1 parent f8c7dd7 commit a83d1d5

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

.changeset/major-jeans-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/integration-marketo': minor
3+
---
4+
5+
Marketo: add option to set an inline message on submit

integrations/marketo/src/form.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Action = { action: '@ui.modal.close'; returnValue: { formId?: string } };
1111
export const marketoFormBlock = createComponent<
1212
{
1313
formId?: string | undefined;
14+
message?: string | undefined;
1415
},
1516
{},
1617
Action,
@@ -24,6 +25,7 @@ export const marketoFormBlock = createComponent<
2425
return {
2526
props: {
2627
formId: action.returnValue.formId || undefined,
28+
message: action.returnValue.message || undefined,
2729
},
2830
};
2931
}
@@ -35,13 +37,20 @@ export const marketoFormBlock = createComponent<
3537
async render(element, { environment }) {
3638
element.setCache({ maxAge: 0 });
3739
const formId = element.props.formId;
40+
const message = element.props.message;
3841
const accountId = environment.installation?.configuration?.account;
3942

4043
const cacheKey = getWebframeCacheKey();
4144
const webframeURL = new URL(`${environment.integration.urls.publicEndpoint}/webframe`);
4245
webframeURL.searchParams.set('formId', formId || '');
4346
webframeURL.searchParams.set('munchkinId', accountId || '');
4447
webframeURL.searchParams.set('v', cacheKey);
48+
if (element.props.message) {
49+
webframeURL.searchParams.set(
50+
'message',
51+
encodeURIComponent(element.props.message) || '',
52+
);
53+
}
4554

4655
return (
4756
<block
@@ -54,6 +63,7 @@ export const marketoFormBlock = createComponent<
5463
componentId: 'settingsModal',
5564
props: {
5665
currentFormId: formId,
66+
currentMessage: message,
5767
},
5868
},
5969
},
@@ -88,15 +98,16 @@ export const marketoFormBlock = createComponent<
8898
* A modal to configure the Mailchimp block.
8999
*/
90100
export const settingsModal = createComponent<
91-
{ currentFormId?: string },
92-
{ formId?: string },
101+
{ currentFormId?: string; currentMessage?: string },
102+
{ formId?: string; message?: string },
93103
{},
94104
MarketoRuntimeContext
95105
>({
96106
componentId: 'settingsModal',
97107

98108
initialState: (props) => ({
99109
formId: props.currentFormId || '',
110+
message: props.currentMessage || '',
100111
}),
101112

102113
async render(element, context) {
@@ -111,6 +122,7 @@ export const settingsModal = createComponent<
111122
action: '@ui.modal.close',
112123
returnValue: {
113124
formId: element.dynamicState('formId'),
125+
message: element.dynamicState('message'),
114126
},
115127
}}
116128
/>
@@ -121,6 +133,10 @@ export const settingsModal = createComponent<
121133
<text>Marketo Form ID</text>
122134
<textinput state="formId" />
123135
</box>
136+
<box>
137+
<text>Optional Post-Submit Message</text>
138+
<textinput state="message" />
139+
</box>
124140
</vstack>
125141
</modal>
126142
);

integrations/marketo/webframe/public/webframe.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<html>
2+
<head>
3+
<meta name="color-scheme" content="light dark">
4+
</head>
25
<style>
36
* {
47
margin: 0;

integrations/marketo/webframe/src/webframe.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const gitbookWebFrame = window.parent;
22
const params = new URLSearchParams(window.location.search);
33
const formId = params.get('formId');
44
const munchkinId = params.get('munchkinId');
5+
const message = params.get('message');
56

67
let cachedSize: { height: number } | undefined;
78

@@ -60,12 +61,22 @@ if (!form) {
6061

6162
form.id = elId;
6263

63-
window.MktoForms2.loadForm('//app-sj15.marketo.com', munchkinId, formId, () => {
64+
window.MktoForms2.loadForm('//app-sj15.marketo.com', munchkinId, formId, (mktoForm) => {
6465
console.info('marketo-embed: form loaded');
6566
sendAction({
6667
action: '@webframe.ready',
6768
});
6869

70+
if (message) {
71+
mktoForm.onSuccess(() => {
72+
form.innerHTML =
73+
'<div class="mktoFormRow"><h3 class="mktoHtmlText">' +
74+
decodeURIComponent(message) +
75+
'</h3></div>';
76+
return false; // Prevent the default form submission behavior
77+
});
78+
}
79+
6980
recalculateSize();
7081

7182
// Listen for any DOM changes and send the new size to the parent.

integrations/marketo/webframe/types/MarketoForms.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ export {};
22

33
// https://experienceleague.adobe.com/en/docs/marketo-developer/marketo/javascriptapi/forms-api-reference?lang=en
44
declare global {
5-
interface MarketoForm {}
5+
interface MarketoForm {
6+
onSubmit: (callback: () => void) => void;
7+
onSuccess: (callback: () => boolean) => void;
8+
}
69

710
interface GlobalMarketo {
811
loadForm: (

0 commit comments

Comments
 (0)