Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-155315 Set Marketo POI #3129

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions libs/blocks/marketo/marketo.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const MUNCHKIN_ID = 'marketo munckin';
const SUCCESS_TYPE = 'form.success.type';
const SUCCESS_CONTENT = 'form.success.content';
const SUCCESS_SECTION = 'form.success.section';
const PROGRAM_POI = 'program.poi';
const POI_FILTER = 'field_filters.products';
const FORM_MAP = {
'success-type': SUCCESS_TYPE,
'destination-type': SUCCESS_TYPE,
Expand All @@ -39,6 +41,7 @@ const FORM_MAP = {
'sfdc-campaign-id': 'program.campaignids.sfdc',
};
export const FORM_PARAM = 'form';
const QUERY_POI = 'poi';

export const formValidate = (formEl) => {
formEl.classList.remove('hide-errors');
Expand All @@ -53,6 +56,7 @@ export const decorateURL = (destination, baseURL = window.location) => {
const { hostname, pathname, search, hash } = destinationUrl;

if (!hostname) {
/* c8 ignore next 2 */
throw new Error('URL does not have a valid host');
}

Expand Down Expand Up @@ -146,6 +150,14 @@ export const formSuccess = (formEl, formData) => {
return false;
};

export function setProductOfInterest(formData, search = window.location.search) {
const productOfInterest = new URLSearchParams(search).get(QUERY_POI);
if (!productOfInterest) return;

formData[PROGRAM_POI] = productOfInterest;
formData[POI_FILTER] = 'hidden';
}

const readyForm = (form, formData) => {
const formEl = form.getFormElem().get(0);
const el = formEl.closest('.marketo');
Expand Down Expand Up @@ -238,6 +250,7 @@ export default function init(el) {
if (destinationUrl) formData[SUCCESS_CONTENT] = destinationUrl;
}

setProductOfInterest(formData);
setPreferences(formData);

const fragment = new DocumentFragment();
Expand Down
12 changes: 11 additions & 1 deletion test/blocks/marketo/marketo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from '@esm-bundle/chai';
import sinon, { stub } from 'sinon';
import { delay } from '../../helpers/waitfor.js';
import { setConfig } from '../../../libs/utils/utils.js';
import init, { setPreferences, decorateURL, FORM_PARAM } from '../../../libs/blocks/marketo/marketo.js';
import init, { setPreferences, decorateURL, setProductOfInterest, FORM_PARAM } from '../../../libs/blocks/marketo/marketo.js';

const innerHTML = await readFile({ path: './mocks/body.html' });
window.lana = { log: stub() };
Expand Down Expand Up @@ -44,6 +44,16 @@ describe('marketo', () => {
});
});

describe('marketo setProductOfInterest', () => {
it('sets POI by query param', async () => {
const formData = {};
setProductOfInterest(formData, '?poi=poi1');

expect(formData).to.have.property('program.poi');
expect(formData['program.poi']).to.equal('poi1');
});
});

describe('marketo decorateURL', () => {
it('decorates absolute URL with local base URL', () => {
const baseURL = new URL('http://localhost:6456/marketo-block');
Expand Down
Loading