Skip to content

Instantly share code, notes, and snippets.

@orangerdev
Created April 3, 2025 17:02
Show Gist options
  • Save orangerdev/58c0a2115f40f1ddb6b69c634d372cef to your computer and use it in GitHub Desktop.
Save orangerdev/58c0a2115f40f1ddb6b69c634d372cef to your computer and use it in GitHub Desktop.
Hubspot modification for Wix to receive any URL params then parse them to the fields
!(function () {
("use strict");
const e = {
RECEIVED_ANALYTICS: "HS_CTA_PARENT_RECEIVED_ANALYTICS",
DEVICE_TYPE: "HS_CTA_PARENT_DEVICE_TYPE",
PROXY_ANALYTICS_FN_CALLBACK: "HS_CTA_PARENT_PROXY_ANALYTICS_FN",
INIT: "HS_CTA_PARENT_INIT",
SHOWING_CTA: "HS_CTA_SHOWING_CTA",
SEND_EXTRACTED_STYLES: "HS_SEND_EXTRACTED_STYLES",
STARTED: "HS_CTA_STARTED",
NAVIGATE_PAGE: "HS_CTA_NAVIGATE_PAGE",
CLICK_EVENT: "HS_CTA_CLICK_EVENT",
CLOSE_INTERACTIVE: "HS_CTA_CLOSE_INTERACTIVE",
HAS_CLOSED: "HS_CTA_HAS_CLOSED",
NEW_HEIGHT: "HS_CTA_NEW_HEIGHT",
DISPLAY_CALL_TO_ACTION: "HS_DISPLAY_CALL_TO_ACTION",
PROXY_ANALYTICS: "HS_CTA_PROXY_ANALYTICS",
PROXY_ANALYTICS_FN: "HS_CTA_PROXY_ANALYTICS_FN",
SEND_FORM_DEFINITION: "HS_SEND_FORM_DEFINITION",
SEND_CTA_CONFIG: "HS_SEND_CTA_CONFIG",
SEND_EMBED_CONTEXT: "HS_SEND_EMBED_CONTEXT",
RECEIVE_FILTERED_STYLESHEETS: "RECEIVE_FILTERED_STYLESHEETS",
SEND_STYLESHEETS: "SEND_STYLESHEETS",
RENDER_RECAPTCHA: "RENDER_RECAPTCHA",
EXECUTE_RECAPTCHA: "EXECUTE_RECAPTCHA",
RESET_RECAPTCHA: "RESET_RECAPTCHA",
RECAPTCHA_SUCCESS: "RECAPTCHA_SUCCESS",
RECAPTCHA_EXPIRED: "RECAPTCHA_EXPIRED",
TRIGGER_CTA: "HS_CTA_TRIGGER_CTA",
CTA_FORM_SUBMITTED: "HS_CTA_FORM_SUBMITTED",
V4_FORM_READY: "HS_V4_FORM_READY",
SEND_FORM_EXTRA_SUBMISSION_METADATA:
"HS_SEND_FORM_EXTRA_SUBMISSION_METADATA",
SEND_FORM_SUBMISSION_SUCCESS_INFO: "HS_SEND_FORM_SUBMISSION_SUCCESS_INFO",
SEND_FORM_SUBMISSION_SUCCESS: "HS_SEND_FORM_SUBMISSION_SUCCESS",
SEND_FORM_SUBMISSION_FAILED: "HS_SEND_FORM_SUBMISSION_FAILED",
SEND_FORM_INTERACTION_NAVIGATE: "HS_SEND_FORM_INTERACTION_NAVIGATE",
GET_FORM_FIELD_VALUES: "HS_GET_FORM_FIELD_VALUES",
SEND_FORM_FIELD_VALUES: "HS_SEND_FORM_FIELD_VALUES",
GET_FIELD_VALUE: "HS_GET_FIELD_VALUE",
SET_FIELD_VALUE: "HS_SET_FIELD_VALUE",
SEND_FIELD_VALUE: "HS_SEND_FIELD_VALUE",
MEETINGS_BOOKING_SUCCESS: "HS_CTA_MEETINGS_BOOKING_SUCCESS",
};
function t(e, t = {}) {
for (const s in t) Object.hasOwnProperty.call(t, s) && (e.style[s] = t[s]);
}
function s(...e) {
if (
window.location.search.indexOf("hs_debug_interactive") > -1 ||
window.location.host.includes("local.hsappstatic")
) {
console.log("[web-interactives-embed]", ...e);
window.location.search.indexOf("hs_is_selenium") > -1 &&
console.log(...[...e].map((e) => JSON.stringify(e)));
}
}
class n {
constructor() {
this.listeners = new Map();
}
on(e, t) {
if (!this.listeners.has(e)) {
this.listeners.set(e, [t]);
return;
}
const s = this.listeners.get(e);
this.listeners.set(e, [...s, t]);
}
off(e) {
this.listeners.delete(e);
}
emit(e, t) {
const s = this.listeners.get(e);
s && s.length && s.forEach((e) => e(t));
}
reset() {
this.listeners = new Map();
}
}
function i() {
return new n();
}
const r = (...e) => {
s("[GlobalIframeCommunication]", ...e);
};
class o {
constructor() {
this.iframeCommunicators = new Map();
this.eventEmitter = i();
this.reset = () => {
this.eventEmitter.reset();
this.iframeCommunicators = new Map();
};
}
registerHandler(e, t) {
this.eventEmitter.on(e, t);
}
registerHandlers(e) {
r("Registering handlers", e);
Object.keys(e).forEach((t) => {
const s = t,
n = e[s];
n && this.registerHandler(s, n);
});
}
registerCommunicator(e, t) {
r("Registering communicator", t);
const s = this.iframeCommunicators.get(t) || [];
this.iframeCommunicators.set(t, [...s, e]);
}
removeCommunicator(e) {
r("Removing Iframe Communicator from GlobalCommunication: ", e);
this.iframeCommunicators.delete(e);
}
emit(e, t) {
r("Emitting event", { event: e, messagePayload: t });
this.eventEmitter.emit(e, t);
}
broadcast(e, t) {
const s = this.iframeCommunicators.get(e);
if (s) {
r("Broadcasting", s);
s.forEach((e) => {
e.sendMessage(t);
});
} else r("Cannot find communcators array, not broadcasting", e, t);
}
broadcastAll(e) {
r("Broadcasting", e, "to all", this.iframeCommunicators);
for (const [t, s] of this.iframeCommunicators) this.broadcast(t, e);
}
}
var a = new o();
function c() {
return new MessageChannel();
}
const l = (...e) => {
s("[iframeCommunication]", ...e);
};
class d {
constructor(t, s) {
this.queue = [];
this.initialised = !1;
this.events = new Map();
this.eventEmitter = i();
this.handleMessage = (e) => {
if (!e.data || !e.data.type) return;
const { type: t, payload: s } = e.data;
l("Handling message", { type: t, payload: s });
this.eventEmitter.emit(t, s);
a.emit(t, Object.assign({}, s, { id: this.id }));
};
this.handleFrameLoaded = () => {
if (this.iframe.contentWindow) {
l("Iframe loaded", this.iframe);
this.iframe.contentWindow.postMessage({ type: e.INIT }, "*", [
this.channel.port2,
]);
this.initialised = !0;
this.flushQueue();
} else l("Content window not there, not loading");
};
this.iframe = t;
this.id = s;
this.channel = c();
this.channel.port1.onmessage = this.handleMessage;
this.iframe.addEventListener("load", this.handleFrameLoaded);
l("Iframe communication set up", s, t);
}
sendMessage({ type: e, payload: t }) {
if (this.initialised) {
l("Posting message", { type: e, payload: t });
this.channel.port1.postMessage({ type: e, payload: t });
} else {
l("Queueing message", { type: e, payload: t });
this.queue.push({ type: e, payload: t });
}
}
registerHandler(e, t) {
this.eventEmitter.on(e, t);
}
registerHandlers(e) {
l("Registering handlers in IframeCommunication", e);
Object.keys(e).forEach((t) => {
const s = t,
n = e[s];
n && this.registerHandler(s, n);
});
}
removeHandler(e) {
l("Removing handler", e);
this.eventEmitter.off(e);
}
remove() {
l("Removing frame communicator:", this.id);
this.channel.port1.close();
a.removeCommunicator(this.id);
}
flushQueue() {
if (this.initialised) {
l("Flushing queue", this.queue);
this.queue.forEach((e) => {
this.sendMessage(e);
});
} else l("Not flushing queue, not initialised");
}
}
function h(e, t) {
l("Creating iframe communication");
const s = new d(e, t);
a.registerCommunicator(s, t);
return s;
}
function u(e) {
const t = window.location.origin.startsWith("http:")
? "http://"
: "https://";
return e.startsWith(t) ? e : `${t}${e.replace(/http(s)?:\/\//, "")}`;
}
function m(e) {
e.style.border = "none";
e.style.height = "100%";
e.style.width = "100%";
e.style.visibility = "hidden";
}
function p(e, t) {
const s = document.createElement("iframe");
s.src = u(e);
Object.keys(t).forEach((e) => {
s.setAttribute(e, t[e]);
});
m(s);
return s;
}
function f(e, t, s) {
e.startsWith("http") || (e = `https://${e}`);
const n = new URL(e);
n.searchParams.set(t, s);
return n.href;
}
const E = (...e) => {
s("[FrameComponent]", ...e);
},
g = () => {};
class S {
constructor({
id: e,
container: t,
iframeSrc: s,
resizeHeight: n,
onFrameReady: i,
useResponsiveStyling: r,
extraAttributes: o = {},
}) {
this.onFrameReady = g;
this.resizeHeight = !0;
this.handleHeightChange = ({ height: e }) => {
if (!this.resizeHeight) return;
const t =
e + 2 * parseInt(getComputedStyle(this.iframe).borderTopWidth, 10);
E("Handle height change", this.id, { adjustedHeight: t, height: e });
this.setContainerStyle({ height: `${t}px` });
};
this.id = e;
this.resizeHeight = n;
if (r) {
E("Responsive styling is enabled", e);
s = f(s, "enableResponsiveStyles", "true");
}
this.iframe = p(s, o);
this.container = t;
this.iframeCommunicator = h(this.iframe, e);
i && (this.onFrameReady = i);
t.appendChild(this.iframe);
this.registerHandlers();
}
registerHandlers() {
this.iframeCommunicator.registerHandlers({
[e.STARTED]: this.onFrameReady,
[e.NEW_HEIGHT]: this.handleHeightChange,
});
}
setStyle(e) {
E("Set style", this.id, e);
t(this.iframe, e);
}
setShouldResize(e) {
this.resizeHeight = e;
}
setContainerStyle(e) {
t(this.container, e);
}
}
function _(e) {
return new S(e);
}
class I {
constructor(e, t) {
this.listeners = new Set();
this.batching = !1;
this.queue = [];
this.subscribe = (e) => {
this.listeners.add(e);
let t = () => {};
this.options &&
this.options.onSubscribe &&
(t = this.options.onSubscribe(e, this));
return () => {
this.listeners.delete(e);
t();
};
};
this.setState = (e) => {
const t = this.state;
this.options && this.options.updateFn
? (this.state = this.options.updateFn(t)(e))
: (this.state = e(t));
if (this.state !== t) {
this.queue.push(() => {
this.listeners.forEach((e) => e(this.state, t));
this.options &&
this.options.onUpdate &&
this.options.onUpdate(this.state, t);
});
this._flush();
}
};
this._flush = () => {
if (!this.batching) {
this.queue.forEach((e) => e());
this.queue = [];
}
};
this.batch = (e) => {
this.batching = !0;
e();
this.batching = !1;
this._flush();
};
this.state = e;
this.options = t;
}
}
function b(e, t = !1) {
!window.navigator.userAgent.includes("Firefox") && t
? window.open(e, "_blank", "noopener")
: window.location.assign(e);
}
const C = "hubspotutk",
w = "__hstc",
A = "__hssc",
y = (e) => {
const t = document.cookie.match(`(^|[^;]+)\\s*${e}\\s*=\\s*([^;]+)`);
return t ? t.pop() : "";
},
v = () => y(C),
F = () => y(w),
T = () => y(A),
R = (...e) => {
s("[models/Analytics]", ...e);
};
class O {
constructor() {
this._handleFetchSucceded = (e) => {
this.store.setState((t) => {
const s = {};
s.path = e.path;
s.referrerPath = e.referrerPath;
s.referrer = "";
s.analyticsPageId = e.pageId;
s.hsfp = e._getFingerprint();
s.canonicalUrl = e.canonicalUrl;
s.contentType = e.contentType;
s.pageId = O.getPageId() || e.pageId;
e.session && (s.hssc = e.session.get());
if (e.utk) {
s.hstc = e.utk.get();
s.hutk = e.utk.visitor;
}
return Object.assign({}, t, s, { isLoaded: !0 });
});
};
window._hsq = window._hsq || [];
const e = {
isLoaded: !1,
pageUrl: window.location.href,
pageTitle: window.document.title,
referrer: window.document.referrer,
userAgent: window.navigator.userAgent,
hutk: v(),
hssc: T(),
hstc: F(),
pageId: O.getPageId(),
};
this.store = new I(e);
this.fetchAnalytics();
}
fetchAnalytics() {
this._analyticsQueue.push(this._handleFetchSucceded);
}
subscribe(e) {
return this.store.subscribe(e);
}
get analytics() {
return this.store.state;
}
track(e) {
R("Tracking analytics", e);
this._analyticsQueue.push(e);
}
get _analyticsQueue() {
return window._hsq;
}
static getPageId() {
const e = window.hsVars;
return e && e.analytics_page_id
? e.analytics_page_id
: e && e.page_id
? e.page_id
: null;
}
static getLanguage() {
const e = window.hsVars;
return e && e.language ? e.language : null;
}
}
var N = new O();
const D = (...e) => {
s("[AnalyticsProxyController]", ...e);
},
M = ["trackFormView", "trackFormVisible", "trackFormInteraction"];
class P {
constructor({ applicationController: e, analyticsStore: t }) {
this.viewQueue = new Map();
this.applicationController = e;
this.analyticsStore = t;
this.listenForAnalyticsUpdate();
this.listenForProxyMessage();
}
listenForAnalyticsUpdate() {
this.analyticsStore.subscribe((t, s) => {
!s.isLoaded &&
t.isLoaded &&
a.broadcastAll({ type: e.RECEIVED_ANALYTICS, payload: t });
});
}
flushViewQueue(e) {
const t = this.viewQueue.get(e) || [];
for (const e of t) this.analyticsStore.track(e);
this.viewQueue.delete(e);
}
handleFormView(e, t) {
const s = this.applicationController.viewedStore;
if (s && s.hasBeenViewed(e)) {
this.analyticsStore.track(t);
return;
}
const n = this.viewQueue.get(e) || [];
D("Adding form view to analytics queue", { id: e, analytics: t });
this.viewQueue.set(e, [...n, t]);
}
listenForProxyMessage() {
a.registerHandlers({
[e.PROXY_ANALYTICS]: ({ analytics: e, id: t }) => {
P.isFormView(e)
? this.handleFormView(t, e)
: this.analyticsStore.track(e);
},
});
}
static isFormView(e) {
const [t] = e;
return M.includes(t);
}
}
class x {
constructor({ applicationController: e }) {
this.applicationController = e;
this.listenForNavigation();
}
listenForNavigation() {
a.registerHandlers({
[e.NAVIGATE_PAGE]: ({ url: e, openNewTab: t, id: s }) => {
const n = this.applicationController.getNavigationUrl(
{ url: e, openNewTab: t },
s,
);
if (t) return;
b(
n,
this.applicationController.getShouldOpenNewTab(
{ url: e, openNewTab: t },
s,
),
);
},
});
}
}
class H {
constructor() {
this.extractedStyles = { rules: {}, keyframes: {} };
this.crossOriginStyleSheets = new Set();
}
extractStyles() {
const e = { rules: {}, keyframes: {} };
for (const t of document.styleSheets)
if (!this.crossOriginStyleSheets.has(t))
try {
const s = t.cssRules || t.rules;
for (const t of s)
t instanceof CSSStyleRule
? (e.rules[t.selectorText] = this.extractProperties(t.style))
: t instanceof CSSKeyframesRule &&
(e.keyframes[t.name] = this.extractKeyframes(t));
} catch (e) {
this.crossOriginStyleSheets.add(t);
}
this.extractedStyles = e;
}
extractProperties(e) {
const t = {};
for (const s of Array.from(e)) t[s] = e.getPropertyValue(s);
return t;
}
extractKeyframes(e) {
const t = [];
for (const s of e.cssRules) {
if (!(s instanceof CSSKeyframeRule)) continue;
const e = this.extractProperties(s.style);
t.push({ keyText: s.keyText, style: e });
}
return t;
}
}
class U {
constructor() {
this.analyticsStore = N;
this.analyticsProxyController = new P({
analyticsStore: this.analyticsStore,
applicationController: this,
});
this.navigationProxyController = new x({ applicationController: this });
this.styleExtractorController = new H();
}
getNavigationUrl(e, t) {
return e.url;
}
getShouldOpenNewTab(e, t) {
return e.openNewTab;
}
}
class L {
constructor() {
this.handleIntersection = (e) => {
e.forEach((e) => {
if (e.isIntersecting) {
const t = e.target;
this.onElementAppear(t);
this.observedElements.delete(t);
this.observer.unobserve(t);
}
});
};
this.observer = new IntersectionObserver(this.handleIntersection, {
threshold: 0.5,
});
this.observedElements = new Map();
}
onElementAppear(e) {
const t = this.observedElements.get(e);
t && t(e);
}
observe(e, t) {
if (
(() => {
const t = e.getBoundingClientRect(),
s = window.innerHeight;
return t.bottom >= 0 && t.top < s;
})()
)
t(e);
else if (!this.observedElements.has(e)) {
this.observedElements.set(e, t);
this.observer.observe(e);
}
}
unobserve(e) {
if (this.observedElements.has(e)) {
this.observedElements.delete(e);
this.observer.unobserve(e);
}
}
}
function V() {
return new L();
}
function k(e, t) {
const s = new Set(e.keys()),
n = new Set(t.keys());
return new Set([...n].filter((e) => !s.has(e)));
}
function j(e, t) {
const s = new Map(e);
for (const [e, n] of t) s.set(e, n);
return s;
}
const $ = (e) => null === e,
B = (e) => void 0 === e,
q = (e) => "object" == typeof e,
G = (e) => "string" == typeof e,
Y = (e) => q(e) && 0 === Object.keys(e).length,
z = (e) => G(e) && 0 === e.trim().length,
X = (e) => $(e) || B(e) || z(e) || Y(e);
const W = "hs-form-frame",
Q = "data-env",
K = "data-form-id",
J = "data-portal-id",
Z = "data-region",
ee = "data-sfdc-campaign-id",
te = "data-go-to-webinar-webinar-key",
se = "data-webinar-id",
ne = "data-webinar-source",
ie = "data-test-id",
re = "embedded-form-",
oe = "title";
var ae = () => Array.from(document.getElementsByClassName(W));
const ce = "na1",
le = "prod",
de = "forms-embed-v3-frame",
he = (e, t) => e.getAttribute(t) || "";
var ue = (e) => ({
formId: he(e, K),
portalId: Number(he(e, J)),
region: he(e, Z) || ce,
env: he(e, Q) || le,
sfdcCampaignId: he(e, ee),
goToWebinarWebinarKey: he(e, te),
webinarId: he(e, se),
webinarSource: he(e, ne),
});
function me(e) {
const t = new MutationObserver((t) => {
const s = [];
for (const e of t)
if ("childList" === e.type)
for (const t of e.addedNodes)
t instanceof HTMLElement && t.classList.contains(W) && s.push(t);
s.length && e(s);
});
t.observe(document.body, { childList: !0, subtree: !0 });
return () => {
t.disconnect();
};
}
const pe = /^[{]?[0-9a-fA-F]{8}-?([0-9a-fA-F]{4}-?){3}[0-9a-fA-F]{12}[}]?$/,
fe = ["qa", "prod"];
var Ee = (e) => {
const { portalId: t, formId: s, region: n, env: i } = e;
return !(t < 1) && !!pe.test(s) && !!n && !!fe.includes(i);
};
function ge(e = ae()) {
const t = new Map(),
s = new Map();
e.forEach((e) => {
const n = ue(e);
if (!Ee(n)) {
console.error(`${n} has missing or invalid data attributes.`);
return;
}
const { formId: i } = n;
t.set(i, [...(t.get(i) || []), e]);
s.set(e, n);
});
return { formContainerElementsMap: t, embedContextsMap: s };
}
const Se = a;
class _e {
constructor({ embedContext: t, container: s, iframeSrc: n }) {
this.handleLoad = () => {
this.frameComponent.setStyle({ visibility: "" });
};
this.sendEmbedContextWithInstanceId = (t) => {
this.frameComponent.iframeCommunicator.sendMessage({
type: e.SEND_EMBED_CONTEXT,
payload: t,
});
};
this.listenForV4FormReadyEvent = () => {
Se.registerHandlers({
[e.V4_FORM_READY]: ({ instanceId: e }) => {
this.sendEmbedContextWithInstanceId(
Object.assign({ instanceId: e }, this.embedContext),
);
},
});
};
this.listenForLoad();
this.container = s;
this.initContainer();
this.embedContext = t;
this.frameComponent = _({
iframeSrc: n,
container: s,
id: t.formId,
onFrameReady: this.resolveFrameload,
resizeHeight: !0,
extraAttributes: {
[ie]: `${re}${t.formId}`,
[oe]: "Form",
scrolling: "no",
},
});
this.listenForV4FormReadyEvent();
}
initContainer() {
this.container.style.height = "0";
this.container.replaceChildren();
}
listenForLoad() {
const e = new Promise((e) => {
this.resolveFrameload = e;
});
Promise.all([e])
.then(() => {
this.handleLoad();
})
.catch(() => {});
}
}
function Ie({ embedContext: e, container: t, iframeSrc: s }) {
return new _e({ embedContext: e, container: t, iframeSrc: s });
}
const be = { APP: "app", APP_API: "app-api" };
function Ce(e, t) {
const s = t && t.hubletOverride ? t.hubletOverride : e;
return s === ce ? "" : `-${s}`;
}
function we(e, t, s) {
if (s && s.hubletPostfixLocation && "domain" === s.hubletPostfixLocation)
return t;
t === be.APP_API && (t = be.APP);
return `${t}${Ce(e, s)}`;
}
function Ae(e, t, s) {
return `${ve(s)}${ye(t, s)}${Fe(e, s)}`;
}
function ye(e, t) {
return "qa" === (t && t.envOverride ? t.envOverride : e) ? "qa" : "";
}
function ve(e) {
return e && e.domainOverride ? e.domainOverride : "hubspot";
}
function Fe(e, t) {
return t && t.hubletPostfixLocation && "domain" === t.hubletPostfixLocation
? Ce(e, t)
: "";
}
function Te(e) {
return e && e.tldOverride ? e.tldOverride : "com";
}
function Re(e) {
return e === be.APP_API ? "/api" : "";
}
function Oe(e, t, s, n) {
return `https://${we(t, e, n)}.${Ae(t, s, n)}.${Te(n)}${Re(e)}`;
}
var Ne = ({
subDomainPrefix: e,
hublet: t,
isQa: s,
pathname: n = "",
pathValues: i = {},
domainOverride: r,
tldOverride: o,
query: a,
}) => {
const c = Object.keys(i).reduce(
(e, t) => e.replace(RegExp(`{{${t}}}`, "g"), i[t]),
n,
),
l = Oe(e, t || ce, s ? "qa" : "prod", {
domainOverride: r,
tldOverride: o,
}),
d = new URL(c, l);
if (a) for (const [e, t] of Object.entries(a)) d.searchParams.append(e, t);
return d.href;
};
const De = new URLSearchParams(window.location.search).get("isLocal"),
Me = () => window.location.search;
function Pe({
portalId: e,
formId: t,
region: s,
env: n,
hutk: i,
editorVersion: r,
}) {
const o = {
hublet: "true" === De ? ce : s,
isQa: "true" !== De && "qa" === n,
subDomainPrefix: "true" === De ? "local" : "js",
domainOverride: "true" === De ? "hsappstatic" : "hsforms",
tldOverride: "net",
};
return Ne(
"2.0" === r
? Object.assign({}, o, {
pathname:
"true" === De
? "ui-forms-embed-components-app/static/html/frame.html"
: "ui-forms-embed-components-app/frame.html",
query: Object.assign(
{
_hsPortalId: `${e || ""}`,
_hsFormId: t || "",
_hsIsQa: `${"qa" === n}`,
_hsHublet: s || ce,
_hsDisableScriptloader: "true",
_hsDisableRedirect: "true",
},
i && { _hsUtk: i },
Object.fromEntries(new URLSearchParams(Me())),
),
})
: Object.assign({}, o, {
pathname:
"true" === De
? "forms-embed/static/html/{{env}}-na-iframe-page.html"
: "forms/embed/iframe.html",
pathValues: { env: "prod" === n ? "" : "qa" },
query: Object.assign(
{},
Object.fromEntries(new URLSearchParams(Me())),
),
}),
);
}
class xe {
constructor({
embeddedContainers: e,
environment: t,
handleView: s,
formStore: n,
analyticsStore: i,
}) {
this.elementObserver = V();
this.embedComponents = new Map();
this.embeddedContainers = e;
this.environment = t;
this.handleView = s;
this.formStore = n;
this.analyticsStore = i;
this.listenForEmbeddedContainers();
}
listenForEmbeddedContainers() {
this.embeddedContainers.subscribe((e, t) => {
const s = k(t.embedContextsMap, e.embedContextsMap);
this.createViews([...s]);
this.listenForElementViews([...s]);
});
}
listenForElementViews(e) {
for (const t of e) {
const e = this.embeddedContainers.embedContextsMap.get(t);
if (!e) return;
this.elementObserver.observe(t, () => this.handleView(e.formId));
}
}
createViews(e) {
for (const t of e) {
const e = this.embeddedContainers.embedContextsMap.get(t);
if (!e) continue;
if (this.embedComponents.has(t)) continue;
const s = this.analyticsStore.analytics.hutk,
n = Ie({
embedContext: Object.assign(
{},
e,
this.environment.propsForContext(),
s && { hutk: s },
),
container: t,
iframeSrc: Pe({
hutk: s,
portalId: e.portalId,
formId: e.formId,
region: e.region,
env: e.env,
editorVersion: this.formStore.formEditorVersion,
}),
});
this.embedComponents.set(t, n);
}
}
}
function He(e) {
return new xe(e);
}
const Ue = "www.recaptcha.net",
Le = "www.google.com",
Ve = () =>
(window && window.grecaptcha && window.grecaptcha.enterprise) || void 0,
ke = (e) => `https://${"CN" === e ? Ue : Le}/recaptcha`,
je = ({ callbackId: e, countryCode: t, locale: s }) => {
const n = () => {
const n = window.document.createElement("script");
n.async = !0;
n.defer = !0;
n.id = "recaptcha";
n.onerror = (e) => {
throw e;
};
n.src = `${ke(t)}/enterprise.js?&onload=${e}&render=explicit&hl=${s}`;
n.type = "text/javascript";
window.document.head.appendChild(n);
};
"complete" === window.document.readyState
? n()
: window.addEventListener("load", n);
},
$e = "hs-forms-embed-frame-recaptcha";
class Be {
constructor() {
this.registerRecaptchaHandlers = () => {
Se.registerHandlers({
[e.RENDER_RECAPTCHA]: (e) => {
this.handleRenderRecaptcha(e);
},
[e.EXECUTE_RECAPTCHA]: ({ UUID: e }) => {
this.handleExecuteRecaptcha(e);
},
[e.RESET_RECAPTCHA]: ({ UUID: e }) => {
this.handleResetRecaptcha(e);
},
});
};
this.handleRenderRecaptcha = ({
UUID: e,
callbackId: t,
countryCode: s,
locale: n,
sitekey: i,
size: r,
badge: o,
inherit: a,
}) => {
this.renderRecaptchaInTarget({
sitekey: i,
UUID: e,
callbackId: t,
size: r,
badge: o,
inherit: a,
});
je({ callbackId: t, countryCode: s, locale: n });
};
this.createRecaptchaTarget = (e) => {
const t = `${$e}_${e}`,
s = document.createElement("div");
s.setAttribute("id", t);
s.style.setProperty("display", "none");
s.style.setProperty("width", "0px");
s.style.setProperty("height", "0px");
document.body.append(s);
this.recaptchas.set(e, { target: s });
return s;
};
this.renderRecaptchaInTarget = ({
sitekey: e,
UUID: t,
callbackId: s,
size: n,
badge: i,
inherit: r,
}) => {
window[s] = () => {
const s = this.createRecaptchaTarget(t),
o = Ve(),
a = this.recaptchas.get(t);
if (o && s && a) {
const c = o.render(
s,
{
sitekey: e,
callback: (e) => {
this.onSuccess(e, t);
},
"expired-callback": () => {
this.onExpired(t);
},
size: n,
badge: i,
},
r,
);
this.recaptchas.set(t, Object.assign({}, a, { widgetId: c }));
}
};
};
this.onSuccess = (t, s) => {
Se.broadcastAll({
type: e.RECAPTCHA_SUCCESS,
payload: { token: t, UUID: s },
});
};
this.onExpired = (t) => {
Se.broadcastAll({ type: e.RECAPTCHA_EXPIRED, payload: { UUID: t } });
};
this.recaptchas = new Map();
this.registerRecaptchaHandlers();
}
handleExecuteRecaptcha(e) {
const t = this.recaptchas.get(e);
if (t) {
const e = t.widgetId,
s = Ve();
void 0 !== e && s && s.execute(e);
}
}
handleResetRecaptcha(e) {
const t = this.recaptchas.get(e);
if (t) {
const e = t.widgetId,
s = Ve();
void 0 !== e && s && s.reset(e);
}
}
}
function qe() {
return new Be();
}
class Ge {
constructor() {
this.markAsViewed = (e) => {
this.store.setState((t) =>
Object.assign({}, t, { viewed: new Set([...t.viewed, e]) }),
);
};
const e = { viewed: new Set() };
this.store = new I(e);
}
subscribe(e) {
this.store.subscribe(e);
}
hasBeenViewed(e) {
return this.store.state.viewed.has(e);
}
get viewed() {
return this.store.state.viewed;
}
}
function Ye() {
return new Ge();
}
class ze extends U {
constructor({ formsStore: e, environment: t, embededContainers: s }) {
super();
this.handleView = (e) => {
this.viewedStore.markAsViewed(e);
this.analyticsProxyController.flushViewQueue(e);
};
this.formsStore = e;
this.environment = t;
this.embededContainers = s;
this.viewedStore = Ye();
this.embeddedFormsController = He({
embeddedContainers: this.embededContainers,
environment: this.environment,
handleView: this.handleView,
formStore: this.formsStore,
analyticsStore: this.analyticsStore,
});
this.recaptchaController = qe();
}
initFormController() {
this.embededContainers.addElements(ge());
this.listenForAddedEmbeddedContainers();
}
listenForAddedEmbeddedContainers() {
me((e) => {
const t = ge(e);
this.embededContainers.addElements(t);
});
}
}
var Xe = ze;
const We = "__HS__FORMS__EMBED__",
Qe = "HubspotFormsV4",
Ke = "__SECRET_INTERNAL_DO_NOT_USE",
Je = "DEFINITION_NOT_FOUND",
Ze = "DEFINITION_FAILURE",
et = "INVALID_FORM_GUID",
tt = "IP_ADDRESS_IS_PROBABLY_A_BOT",
st = "NON_EMBEDDABLE_FORM",
nt = "UNCAUGHT_JS_ERROR",
it = "DEFINITION_SUCCESS",
rt = "FALLBACK_DEFINITION_SUCCESS",
ot = "FALLBACK_DEFINITION_FAILURE",
at = "SUBMISSION_PERIOD_ENDED",
ct = "RATE_LIMIT_EXCEEDED";
var lt = (e) =>
Object.keys(e || {}).reduce(
(t, s) => Object.assign({}, t, X(e[s]) ? {} : { [s]: e[s] }),
{},
);
var dt = () =>
"randomUUID" in crypto
? crypto.randomUUID()
: ([1e7] + -1e3 + -4e3 + 8e3 + -1e11).replace(/[018]/g, (e) =>
(
e ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (e / 4)))
).toString(16),
);
const ht = "?";
function ut() {
return "undefined" == typeof document || null == document.location
? ""
: document.location.href;
}
function mt() {
return "undefined" == typeof document || null == document.location
? ""
: document.location.origin
? document.location.origin
: `${document.location.protocol}//${document.location.hostname}${
document.location.port ? `:${document.location.port}` : ""
}`;
}
function pt(e) {
if (void 0 === e.stack || !e.stack) return null;
const t =
/^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|[a-z]:|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,
s =
/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx(?:-web)|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
n =
/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|moz-extension).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js))(?::(\d+))?(?::(\d+))?\s*$/i,
i = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i,
r = /\((\S*)(?::(\d+))(?::(\d+))\)/,
o = e.stack.split("\n"),
a = [];
let c, l, d;
for (let h = 0, u = o.length; h < u; ++h) {
if ((l = t.exec(o[h]))) {
const e = l[2] && 0 === l[2].indexOf("native");
if (l[2] && 0 === l[2].indexOf("eval") && (c = r.exec(l[2]))) {
l[2] = c[1];
l[3] = c[2];
l[4] = c[3];
}
d = {
filename: e ? null : l[2],
function: l[1] || ht,
args: e ? [l[2]] : [],
lineno: l[3] ? +l[3] : null,
colno: l[4] ? +l[4] : null,
};
} else if ((l = s.exec(o[h])))
d = {
filename: l[2],
function: l[1] || ht,
args: [],
lineno: +l[3],
colno: l[4] ? +l[4] : null,
};
else {
if (!(l = n.exec(o[h]))) continue;
if (l[3] && l[3].indexOf(" > eval") > -1 && (c = i.exec(l[3]))) {
l[3] = c[1];
l[4] = c[2];
l[5] = null;
} else
0 !== h ||
l[5] ||
void 0 === e.columnNumber ||
(a[0].column = e.columnNumber + 1);
d = {
filename: l[3],
function: l[1] || ht,
args: l[2] ? l[2].split(",") : [],
lineno: l[4] ? +l[4] : null,
colno: l[5] ? +l[5] : null,
};
}
!d.function && d.line && (d.function = ht);
if (d.filename && "blob:" === d.filename.substr(0, 5)) {
const e = new XMLHttpRequest();
e.open("GET", d.filename, !1);
e.send(null);
if (200 === e.status) {
let t = e.responseText || "";
t = t.slice(-300);
const s = t.match(/\/\/# sourceMappingURL=(.*)$/);
if (s) {
let e = s[1];
"~" === e.charAt(0) && (e = mt() + e.slice(1));
d.url = e.slice(0, -4);
}
}
}
a.push(d);
}
return a.length
? { name: e.name, message: e.message, url: ut(), stack: a }
: null;
}
function ft(e, t, s) {
const n = { filename: t, lineno: s };
if (n.filename && n.lineno) {
e.incomplete = !1;
n.function || (n.function = ht);
if (e.stack.length > 0 && e.stack[0].filename === n.filename) {
if (e.stack[0].lineno === n.lineno) return !1;
if (!e.stack[0].lineno && e.stack[0].function === n.function) {
e.stack[0].lineno = n.lineno;
return !1;
}
}
e.stack.unshift(n);
e.partial = !0;
return !0;
}
e.incomplete = !0;
return !1;
}
function Et(e, t) {
const s =
/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,
n = [],
i = {};
let r,
o,
a = !1;
for (let e = Et.caller; e && !a; e = e.caller)
if (e !== gt) {
o = { filename: null, function: ht, lineno: null, colno: null };
e.name
? (o.function = e.name)
: (r = s.exec(e.toString())) && (o.function = r[1]);
if (void 0 === o.function)
try {
o.function = r.input.substring(0, r.input.indexOf("{"));
} catch (e) {}
i[`${e}`] ? (a = !0) : (i[`${e}`] = !0);
n.push(o);
}
t && n.splice(0, t);
const c = { name: e.name, message: e.message, filename: ut(), stack: n };
ft(
c,
e.sourceURL || e.fileName,
e.line || e.lineNumber,
e.message || e.description,
);
return c;
}
function gt(e, t) {
if ("string" == typeof e)
return { name: "Error", message: e, filename: ut() };
let s = null;
t = null == t ? 0 : +t;
try {
s = pt(e);
if (s) return s;
} catch (e) {}
try {
s = Et(e, t + 1);
if (s) return s;
} catch (e) {}
return { name: e.name, message: e.message, filename: ut() };
}
var St = (e) => {
new Image().src = e;
};
const _t = [
/timeout exceeded/,
/Request aborted/,
/Network Error/,
/Failed to execute 'send' on 'XMLHttpRequest'/,
/Unexpected end of JSON input/,
/Unexpected token/,
/IP_ADDRESS_IS_PROBABLY_A_BOT/,
/SUBMISSION_PERIOD_ENDED/,
/RATE_LIMIT_EXCEEDED/,
],
It = [/\/OtAutoBlock\.js/, /\/mootools\.js/],
bt = [/\/?forms\/embed\/frame(-v2)?\.js/],
Ct = (e, t) => {
const s = gt(e),
n = s.stack ? s.stack[0].filename : s.filename;
return (
bt.some((t) => t.test(e.stack || "")) &&
(!!t || bt.some((e) => e.test(n)))
);
};
var wt = (e, t = !1) => {
if (!e) return !1;
const { message: s = "", stack: n = "" } = e || {};
return Boolean(
Ct(e, t) && !_t.find((e) => e.test(s)) && !It.find((e) => e.test(n)),
);
};
const At =
"https://exceptions{{region}}.hs-embed-reporting{{env}}.com/outpost/developer-forms-embed",
yt = ({ region: e, env: t }) => {
const s = e ? `-${e}` : "",
n = "qa" === t ? "qa" : "";
return At.replace("{{region}}", s).replace("{{env}}", n);
},
vt = (
e,
t,
{
env: s = "PROD",
url: n = "",
query: i = "",
version: r = "",
region: o = "",
tags: a = {},
user: c = {},
extra: l = {},
},
) => {
const d = Date.now() / 1e3,
h = gt(t);
return {
environment: s,
tags: Object.assign({ region: o }, a),
logger: "javascript",
platform: "javascript",
request: {
headers: { "User-Agent": navigator.userAgent },
url: n || window.location.href,
queryString: i.replace(/^\?/, ""),
},
event_id: dt().replace(/-/g, ""),
transaction: h.stack ? h.stack[0].filename : h.filename,
level: e,
exception: {
values: [
{
mechanism: { handled: !0, type: "generic" },
type: h.name,
value: h.message,
stacktrace: { frames: h.stack ? h.stack.reverse() : [] },
},
],
},
timestamp: d,
version: r,
user: c,
extra: lt(l),
};
},
Ft = (e = "", t = "", s = {}) => {
const n = vt(e, t, s);
St(
`${yt(s)}/raw/error.gif?url=${
n.request.url
}&report=${encodeURIComponent(JSON.stringify(n))}`,
);
};
const Tt = "https://forms{{region}}.hsforms{{env}}.com/embed/v3",
Rt = ({ env: e, region: t }) => {
const s = t ? `-${t}` : "",
n = "qa" === e ? "qa" : "";
return Tt.replace("{{region}}", s).replace("{{env}}", n);
};
var Ot = {
reportError: ({
key: e,
error: t,
data: s,
requestParams: n,
projectVersion: i,
renderVersion: r,
module: o,
}) => {
wt(t) &&
Ft("error", t, {
type: "Error",
env: n.env,
region: n.region,
url: window.location.href,
query: window.location.search,
tags: { key: e, projectVersion: i, renderVersion: r, module: o },
extra: {
key: e,
data: JSON.stringify(s),
formId: n.formId,
portalId: n.portalId,
},
});
},
reportAnalyticCount: (e = "", t = 1, s = { env: "", region: "" }) => {
St(`${Rt(s)}/counters.gif?key=${e}&count=${t}`);
},
};
var Nt = (e) => {
const { response: { status: t, data: s = {} } = {} } = e || {},
n = s.message || s.error;
if (404 === t) return Je;
if (400 === t) {
if (/form guid/i.test(n)) return et;
if (/you cannot (embed|fetch) this type of form/i.test(n)) return st;
if (/IP_ADDRESS_IS_PROBABLY_A_BOT/i.test(n)) return tt;
if (/SUBMISSION_PERIOD_ENDED/i.test(n)) return at;
}
return 429 === t && /RATE_LIMIT_EXCEEDED/i.test(n) ? ct : null;
};
const Dt = (e = [], t = "") => {
const s = e.find(({ name: e }) => e === t) || {};
return "true" === s.value || ("false" !== s.value && s.value);
};
var Mt = Dt;
var Pt = ({ form: { metaData: e = [] } = {} }) =>
Mt(e, "definitionS3WriteDate") ? rt : it;
const xt = "1.0",
Ht = "2.0",
Ut = (e) => /^[0-9]+$/.test(e.toString()),
Lt = (e) =>
/^[{]?[0-9a-fA-F]{8}-?([0-9a-fA-F]{4}-?){3}[0-9a-fA-F]{12}[}]?$/.test(e);
class Vt {
constructor() {
const e = { forms: new Map() };
this.store = new I(e);
this.editorVersion = xt;
}
has(e) {
return this.store.state.forms.has(e);
}
get(e) {
return this.store.state.forms.get(e);
}
subscribe(e) {
return this.store.subscribe(e);
}
fetchForm(e, t) {
if (!Ut(t.portalId)) throw new Error("Missing required portalId");
if (!Lt(t.formId)) throw new Error("Missing required formId");
const { formId: s, portalId: n, region: i, env: r, hutk: o = "" } = t,
a = Ne({
hublet: i,
isQa: "qa" === r,
subDomainPrefix: "forms",
domainOverride: "hsforms",
pathname:
this.editorVersion && this.editorVersion === Ht
? "embed/v4/render-definition/{{portalId}}/{{formId}}"
: "embed/v3/form/{{portalId}}/{{formId}}/json",
pathValues: { formId: s, portalId: `${n}` },
query: Object.assign({}, o && { hutk: o }),
});
fetch(a, { mode: "cors", signal: e })
.then((e) => this.handleResponseSuccess(e, t))
.catch((e) => {
const s = Nt(e),
n = this.getDefinitionError(Ze, s, t);
if (s) this.handleResponseError(n);
else {
this.handleResponseError(n, !0);
this.fetchFormFallback(t);
}
});
}
get formEditorVersion() {
return this.editorVersion;
}
set formEditorVersion(e) {
this.editorVersion = e;
}
fetchFormFallback(e) {
const { formId: t, portalId: s, env: n } = e,
i = Ne({
subDomainPrefix: "hubspot-forms-static-embed",
domainOverride: "s3.amazonaws",
pathname: "{{env}}/{{portalId}}/{{formId}}.json.gz",
pathValues: { formId: t, portalId: `${s}`, env: n },
});
fetch(i, { mode: "cors" })
.then((t) => this.handleResponseSuccess(t, e))
.catch((t) =>
this.handleResponseError(this.getDefinitionError(ot, t, e)),
);
}
handleResponseSuccess(e, t) {
e.ok
? e
.json()
.then((s) => {
const n = Pt(s);
Ot.reportAnalyticCount(`${de}-${n}`, 1, {
env: t.env,
region: t.region,
});
this.store.setState((n) => ({
forms: n.forms.set(
t.formId,
Object.assign({}, s, {
definitionHublet: e.headers.get("x-origin-hublet") || "",
}),
),
}));
})
.catch((e) =>
this.handleResponseError(this.getDefinitionError(nt, e, t)),
)
: e
.text()
.then((e) =>
this.handleResponseError(this.getDefinitionError(Ze, e, t)),
)
.catch((e) =>
this.handleResponseError(this.getDefinitionError(nt, e, t)),
);
}
getDefinitionError(e, t, s) {
return {
key: e,
error: t,
data: t && t.response && t.response.data ? [t.response.data] : [],
requestParams: s,
projectVersion: window[We].app,
module: window[We].projectName,
renderVersion: "v3-frame",
};
}
handleResponseError(e, t = !1) {
Ot.reportError(e);
Ot.reportAnalyticCount(`${de}-${e.key}`, 1, {
env: e.requestParams.env,
region: e.requestParams.region,
});
if (!t) throw new Error(e.error);
}
}
var kt = new Vt();
class jt {
constructor() {
this.pageUrl = window.location.href;
this.pageTitle = window.document.title;
this.pageId = null;
this.referrer = window.document.referrer;
this.isHubSpotCmsGeneratedPage = !1;
this.pageId = this._getPageId();
this.isHubSpotCmsGeneratedPage = this._getIsHubSpotCmsGeneratedPage();
}
_getPageId() {
const { analytics_page_id: e, page_id: t } = window.hsVars || {};
return e || t || null;
}
_getIsHubSpotCmsGeneratedPage() {
const e = window.document;
return Boolean(
e &&
e.querySelector &&
e.querySelector('meta[name="generator"][content="HubSpot"]'),
);
}
propsForContext() {
return {
pageUrl: this.pageUrl,
pageTitle: this.pageTitle,
referrer: this.referrer,
pageId: this.pageId,
isHubSpotCmsGeneratedPage: this.isHubSpotCmsGeneratedPage,
};
}
}
var $t = new jt();
class Bt {
constructor() {
const e = {
formContainerElementsMap: new Map(),
embedContextsMap: new Map(),
};
this.store = new I(e);
}
subscribe(e) {
return this.store.subscribe(e);
}
get formContainerElements() {
return this.store.state.formContainerElementsMap;
}
get embedContextsMap() {
return this.store.state.embedContextsMap;
}
addElements(e) {
this.store.setState((t) => ({
formContainerElementsMap: j(
t.formContainerElementsMap,
e.formContainerElementsMap,
),
embedContextsMap: j(t.embedContextsMap, e.embedContextsMap),
}));
}
}
class qt {
constructor(e) {
this.formData = e;
this.attachToWindow();
}
init(e) {
const { instanceId: t, formId: s } = e;
this.createFormInstanceMethods(e);
this.formData.setFormInstanceInfo({
instanceId: t,
formInfo: { formId: s },
});
}
attachToWindow() {
window[Qe] = {
[Ke]: {
_forms: new Map(),
_setForm({ instanceId: e, instanceMethods: t }) {
this[Ke]._forms.set(e, t);
},
_getFormByInstanceId(e) {
return this[Ke]._forms.get(e);
},
},
getForms() {
return Array.from(this[Ke]._forms.values());
},
getFormFromEvent({ detail: { instanceId: e } }) {
return this[Ke]._getFormByInstanceId.call(this, e);
},
};
}
createFormInstanceMethods(e) {
const { instanceId: t, formId: s } = e,
{ clientApi: n, __internalApi: i } = this.getFormInternalApi() || {};
n &&
i &&
!i._getFormByInstanceId.call(n, t) &&
i._setForm.call(n, {
instanceId: t,
instanceMethods: {
getFormId: () => s,
getInstanceId: () => t,
getRedirectUrl: () => this.formData.getRedirectUrl(t),
getConversionId: () => this.formData.getConversionId(t),
getFormFieldValues: () => this.getFormFieldValues(e),
getFieldValue: (t) => this.getFieldValue(e, t),
setFieldValue: (t, s) =>
this.setFieldValue({
baseFormInfo: e,
propertyReference: t,
value: s,
}),
setExtraSubmissionMetadata: (e) =>
this.sendExtraSubmissionMetadata({
formId: s,
instanceId: t,
metadata: e,
}),
},
});
}
sendExtraSubmissionMetadata(t) {
const { formId: s } = t;
Se.broadcast(s, {
type: e.SEND_FORM_EXTRA_SUBMISSION_METADATA,
payload: t,
});
}
setFieldValue({ baseFormInfo: t, propertyReference: s, value: n }) {
const { formId: i, instanceId: r } = t;
Se.broadcast(i, {
type: e.SET_FIELD_VALUE,
payload: { instanceId: r, propertyReference: s, value: n },
});
}
async getFormFieldValues(t) {
let s;
const { formId: n } = t,
i = new Promise((e) => {
s = e;
});
this.listenForSendFormFieldValues(s);
Se.broadcast(n, { type: e.GET_FORM_FIELD_VALUES, payload: t });
return await i.then((e) => e);
}
async getFieldValue(t, s) {
let n;
const { formId: i, instanceId: r } = t,
o = new Promise((e) => {
n = e;
});
this.listenForSendFieldValue(n);
Se.broadcast(i, {
type: e.GET_FIELD_VALUE,
payload: { instanceId: r, propertyReference: s },
});
return await o.then((e) => e);
}
listenForSendFormFieldValues(t) {
Se.registerHandlers({
[e.SEND_FORM_FIELD_VALUES]: ({ formFieldValues: e }) => {
null == t || t(e);
},
});
}
listenForSendFieldValue(t) {
Se.registerHandlers({
[e.SEND_FIELD_VALUE]: ({ fieldValue: e }) => {
null == t || t(e);
},
});
}
getFormInternalApi() {
const e = window[Qe];
if (e && e[Ke]) return { clientApi: e, __internalApi: e[Ke] };
}
}
function Gt(e) {
return new qt(e);
}
const Yt = {
ON_FORM_READY: "hs-form-event:on-ready",
ON_FORM_SUBMISSION_SUCCESS: "hs-form-event:on-submission:success",
ON_FORM_SUBMISSION_FAILED: "hs-form-event:on-submission:failed",
ON_FORM_INTERACTION_NAVIGATE: "hs-form-event:on-interaction:navigate",
};
class zt {
constructor(e) {
this.formData = e;
}
init({ initialiseThirdPartyApi: e }) {
this.listenForFormReadyEvent({ initialiseThirdPartyApi: e });
this.listenForFormNavigationEvent();
this.listenForSubmissionSuccessEvent();
this.listenForSubmissionFailedEvent();
}
listenForFormReadyEvent({ initialiseThirdPartyApi: t }) {
Se.registerHandlers({
[e.V4_FORM_READY]: (e) => {
t(e);
this.triggerGlobalEvent(
Object.assign({}, e, { type: Yt.ON_FORM_READY }),
);
},
});
}
listenForSubmissionSuccessEvent() {
Se.registerHandlers({
[e.SEND_FORM_SUBMISSION_SUCCESS]: ({ formId: e, instanceId: t }) => {
this.triggerGlobalEvent({
type: Yt.ON_FORM_SUBMISSION_SUCCESS,
instanceId: t,
formId: e,
});
},
});
}
listenForFormNavigationEvent() {
Se.registerHandlers({
[e.SEND_FORM_INTERACTION_NAVIGATE]: (e) => {
this.triggerGlobalEvent(
Object.assign({}, e, { type: Yt.ON_FORM_INTERACTION_NAVIGATE }),
);
},
});
}
listenForSubmissionFailedEvent() {
Se.registerHandlers({
[e.SEND_FORM_SUBMISSION_FAILED]: ({ formId: e, instanceId: t }) => {
this.triggerGlobalEvent({
type: Yt.ON_FORM_SUBMISSION_FAILED,
instanceId: t,
formId: e,
});
},
});
}
triggerGlobalEvent({ type: e, instanceId: t, formId: s }) {
if (
document &&
void 0 !== typeof window &&
window &&
window.CustomEvent
) {
const n = new CustomEvent(e, {
bubbles: !0,
cancelable: !0,
detail: { formId: s, instanceId: t },
});
document.dispatchEvent(n);
}
}
}
function Xt(e) {
return new zt(e);
}
class Wt {
constructor() {
this.formDataMap = new Map();
}
setFormInstanceInfo({ instanceId: e, formInfo: t }) {
const s = this.formDataMap.get(e) || {};
this.formDataMap.set(e, Object.assign({}, s, t));
}
getRedirectUrl(e) {
var t;
return (
(null === (t = this.formDataMap.get(e)) || void 0 === t
? void 0
: t.redirectUrl) || ""
);
}
getConversionId(e) {
var t;
return (
(null === (t = this.formDataMap.get(e)) || void 0 === t
? void 0
: t.conversionId) || ""
);
}
}
var Qt = Wt;
class Kt extends Xe {
constructor(e) {
super(e);
this.initialiseThirdPartyApi = (e) => {
this.thirdPartyApiController.init(e);
};
this.formData = new Qt();
this.thirdPartyApiController = Gt(this.formData);
this.globalEventController = Xt(this.formData);
}
init() {
this.formsStore.formEditorVersion = Ht;
this.globalEventController.init({
initialiseThirdPartyApi: this.initialiseThirdPartyApi,
});
this.listenForSubmissionSuccessInfo();
this.initFormController();
}
listenForSubmissionSuccessInfo() {
Se.registerHandlers({
[e.SEND_FORM_SUBMISSION_SUCCESS_INFO]: ({
instanceId: e,
redirectUrl: t,
conversionId: s,
}) => {
this.formData.setFormInstanceInfo({
instanceId: e,
formInfo: { redirectUrl: t, conversionId: s },
});
},
});
}
}
var Jt = new Kt({
formsStore: kt,
environment: $t,
embededContainers: new Bt(),
}),
Zt = {
mode: "compressed",
staticDomainPrefix: "//static.hsappstatic.net",
bender: {
depVersions: {
"forms-embed-parent": "static-1.2962",
"hs-lodash": "static-4.9",
"hs-test-utils": "static-1.5430",
HubStyleTokens: "static-2.8983",
"jasmine-runner": "static-1.3797",
quartz: "static-1.3935",
react: "static-7.133",
"web-interactives-embed-framework": "static-2.2956",
"hubspot-url-utils": "static-1.1941",
outpost: "static-1.1764",
"bend-plugin-trellis-migration": "static-1.1006",
"foundations-components": "static-1.4075",
"foundations-theming": "static-1.1294",
"framer-motion": "static-1.29",
"hs-test-utils-bend-plugin": "static-1.541",
"hub-http": "static-1.2732",
"hub-http-janus": "static-1.582",
"hub-http-rxjs": "static-1.546",
immutable: "static-2.19",
msw: "static-1.39",
"react-dom": "static-7.85",
"react-redux": "static-7.16",
"react-utils": "static-2.3120",
redux: "static-4.16",
"redux-mock-store": "static-1.8",
"redux-thunk": "static-2.17",
"testing-library": "static-1.112",
transmute: "static-2.29",
UIComponents: "static-3.5933",
jasmine: "static-4.1708",
"browserslist-config-hubspot": "static-1.144",
enviro: "static-4.273",
PortalIdParser: "static-2.252",
"quartz-core-utils": "static-1.802",
StyleGuideUI: "static-3.431",
csstype: "static-1.8",
"bend-plugin-foundations-components": "static-1.343",
"floating-ui": "static-1.19",
"foundations-assets": "static-1.2193",
"hs-story-utils": "static-1.6375",
I18n: "static-7.1297",
"metrics-js": "static-1.6993",
moment: "static-3.26",
"react-aria": "static-1.31",
"react-select-plus": "static-1.65",
"react-virtualized": "static-2.66",
"styled-components": "static-2.40",
"tanstack-table": "static-1.10",
"ui-fonts": "static-1.327",
"ui-images": "static-2.762",
"foundations-theming-base": "static-1.279",
rxjs: "static-5.10",
"hoist-non-react-statics": "static-3.9",
classnames: "static-2.10",
cssUtils: "static-1.319",
"head-dlb": "static-1.2378",
HubStyle: "static-2.9293",
icons: "static-2.585",
"i18n-data": "static-1.187",
"moment-timezone": "static-5.17",
"react-input-autosize": "static-2.17",
sassPrefix: "static-1.120",
HeadJS: "static-2.514",
"hs-promise-rejection-tracking": "static-1.2850",
raven: "static-3.3177",
"raven-hubspot": "static-1.3484",
},
depPathPrefixes: {
"forms-embed-parent": "/forms-embed-parent/static-1.2962",
"hs-lodash": "/hs-lodash/static-4.9",
"hs-test-utils": "/hs-test-utils/static-1.5430",
HubStyleTokens: "/HubStyleTokens/static-2.8983",
"jasmine-runner": "/jasmine-runner/static-1.3797",
quartz: "/quartz/static-1.3935",
react: "/react/static-7.133",
"web-interactives-embed-framework":
"/web-interactives-embed-framework/static-2.2956",
"hubspot-url-utils": "/hubspot-url-utils/static-1.1941",
outpost: "/outpost/static-1.1764",
"bend-plugin-trellis-migration":
"/bend-plugin-trellis-migration/static-1.1006",
"foundations-components": "/foundations-components/static-1.4075",
"foundations-theming": "/foundations-theming/static-1.1294",
"framer-motion": "/framer-motion/static-1.29",
"hs-test-utils-bend-plugin":
"/hs-test-utils-bend-plugin/static-1.541",
"hub-http": "/hub-http/static-1.2732",
"hub-http-janus": "/hub-http-janus/static-1.582",
"hub-http-rxjs": "/hub-http-rxjs/static-1.546",
immutable: "/immutable/static-2.19",
msw: "/msw/static-1.39",
"react-dom": "/react-dom/static-7.85",
"react-redux": "/react-redux/static-7.16",
"react-utils": "/react-utils/static-2.3120",
redux: "/redux/static-4.16",
"redux-mock-store": "/redux-mock-store/static-1.8",
"redux-thunk": "/redux-thunk/static-2.17",
"testing-library": "/testing-library/static-1.112",
transmute: "/transmute/static-2.29",
UIComponents: "/UIComponents/static-3.5933",
jasmine: "/jasmine/static-4.1708",
"browserslist-config-hubspot":
"/browserslist-config-hubspot/static-1.144",
enviro: "/enviro/static-4.273",
PortalIdParser: "/PortalIdParser/static-2.252",
"quartz-core-utils": "/quartz-core-utils/static-1.802",
StyleGuideUI: "/StyleGuideUI/static-3.431",
csstype: "/csstype/static-1.8",
"bend-plugin-foundations-components":
"/bend-plugin-foundations-components/static-1.343",
"floating-ui": "/floating-ui/static-1.19",
"foundations-assets": "/foundations-assets/static-1.2193",
"hs-story-utils": "/hs-story-utils/static-1.6375",
I18n: "/I18n/static-7.1297",
"metrics-js": "/metrics-js/static-1.6993",
moment: "/moment/static-3.26",
"react-aria": "/react-aria/static-1.31",
"react-select-plus": "/react-select-plus/static-1.65",
"react-virtualized": "/react-virtualized/static-2.66",
"styled-components": "/styled-components/static-2.40",
"tanstack-table": "/tanstack-table/static-1.10",
"ui-fonts": "/ui-fonts/static-1.327",
"ui-images": "/ui-images/static-2.762",
"foundations-theming-base": "/foundations-theming-base/static-1.279",
rxjs: "/rxjs/static-5.10",
"hoist-non-react-statics": "/hoist-non-react-statics/static-3.9",
classnames: "/classnames/static-2.10",
cssUtils: "/cssUtils/static-1.319",
"head-dlb": "/head-dlb/static-1.2378",
HubStyle: "/HubStyle/static-2.9293",
icons: "/icons/static-2.585",
"i18n-data": "/i18n-data/static-1.187",
"moment-timezone": "/moment-timezone/static-5.17",
"react-input-autosize": "/react-input-autosize/static-2.17",
sassPrefix: "/sassPrefix/static-1.120",
HeadJS: "/HeadJS/static-2.514",
"hs-promise-rejection-tracking":
"/hs-promise-rejection-tracking/static-1.2850",
raven: "/raven/static-3.3177",
"raven-hubspot": "/raven-hubspot/static-1.3484",
},
project: "forms-embed-parent",
staticDomain: "//static.hsappstatic.net",
staticDomainPrefix: "//static.hsappstatic.net",
},
};
const es = () => window[We],
ts = () => "loading" === document.readyState,
ss = () => {
window[We] = {
projectName: `${Zt.bender.project}`,
app: `${Zt.bender.project}-${Zt.bender.depVersions[Zt.bender.project]}`,
mountedAt: window.performance.now(),
mountedBy: document.currentScript,
instance: Xe,
numAttemptedScriptInits: 1,
};
},
ns = (e) => {
document.removeEventListener("DOMContentLoaded", () => ns(e));
e();
};
function is(e) {
const t = es();
if (t) {
1 === t.numAttemptedScriptInits &&
document.currentScript &&
console.warn(
`The script ${document.currentScript.getAttribute(
"src",
)} only needs to be included once on the page`,
);
t.numAttemptedScriptInits++;
} else {
ss();
ts() ? document.addEventListener("DOMContentLoaded", () => ns(e)) : e();
}
}
// Fungsi untuk mengambil semua parameter UTM dari URL
function getUTMParams() {
const urlParams = new URLSearchParams(window.location.search);
return {
utm_campaign: urlParams.get("utm_campaign"),
utm_source: urlParams.get("utm_source"),
utm_medium: urlParams.get("utm_medium"),
utm_term: urlParams.get("utm_term"),
utm_content: urlParams.get("utm_content"),
};
}
// Fungsi untuk mengisi field form dengan data UTM
function populateUTMFields(instanceId, utmParams) {
Object.entries(utmParams).forEach(([field, value]) => {
if (value) {
// Gunakan fungsi setFieldValue untuk mengisi field
window.HubspotFormsV4.__SECRET_INTERNAL_DO_NOT_USE
._getFormByInstanceId(instanceId)
.setFieldValue(field, value);
}
});
}
// Modifikasi event listener untuk menangani form ready
document.addEventListener("hs-form-event:on-ready", (event) => {
const { instanceId } = event.detail;
// Ambil data UTM dari URL
const utmParams = getUTMParams();
// Isi field form dengan data UTM
populateUTMFields(instanceId, utmParams);
});
is(() => Jt.init());
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment