Skip to content

Instantly share code, notes, and snippets.

@jcoryalvernaz
Last active August 9, 2022 17:18
Show Gist options
  • Save jcoryalvernaz/fe585340f81dfdfd5a894a5708b29eda to your computer and use it in GitHub Desktop.
Save jcoryalvernaz/fe585340f81dfdfd5a894a5708b29eda to your computer and use it in GitHub Desktop.
// Get the name of the Parsely visitor cookie
const parselyVisitorCookieName = window.PARSELY.visitorManager.visitorCookieName || '_parsely_visitor';
// Get the visitor object from the Parsely cookie
const parselyVisitor = window.PARSELY.ParselyStorage.getJSON(parselyVisitorCookieName);
// Construct hidden fields to pass to the Pardot iframe
// The `parentUrl` will be the URL in which the iframe is embedded
// The `conversionType` and `conversionLabel` should be set per the Parsely docs: https://www.parse.ly/help/integration/conversions-self-managed-integration#conversion-types
const hiddenFieldsObject = {
parsely_conversion_label: conversionLabel,
parsely_conversion_type: conversionType || 'lead_capture',
parsely_visitor_id: parselyVisitor.id,
parsely_visitor_last_session_ts: parselyVisitor.last_session_ts,
parsely_visitor_session_count: parselyVisitor.session_count,
parent_url: parentUrl,
};
// Encode the hidden fields as URL query params
const hiddenFields = Object.entries(hiddenFieldsObject)
.map(([key, value]) => `${key}=${value}`)
.join('&');
// Pass the `hiddenFields` appended to the `formUrl` for the iframe
// Note: Here we are using JSX, but the idea would be the same for HTML
<iframe
src={`${formUrl}?${hiddenFields}`}
width="100%"
type="text/html"
frameBorder="0"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment