Skip to content

Instantly share code, notes, and snippets.

@jcoryalvernaz
Last active September 7, 2022 21:22
Show Gist options
  • Save jcoryalvernaz/43285b7455b0b2832e46a2a747b44f5c to your computer and use it in GitHub Desktop.
Save jcoryalvernaz/43285b7455b0b2832e46a2a747b44f5c to your computer and use it in GitHub Desktop.
<script type="text/javascript">
//<![CDATA[
setTimeout(function() {
// Get the name for the Parsely visitor cookie
const parselyVisitorCookieName = PARSELY.visitorManager.visitorCookieName || '_parsely_visitor';
// Construct the visitor object with hidden fields passed to the form
const parselyVisitor = {
id: "%%parsely_visitor_id{js}%%",
session_count: parseInt("%%parsely_visitor_session_count{js}%%", 10),
last_session_ts: parseInt("%%parsely_visitor_last_session_ts{js}%%", 10),
};
// Set the Parsely visitor cookie within the iframe
PARSELY.ParselyStorage.setJSON(parselyVisitorCookieName, parselyVisitor, { sameSite: 'none', secure: true });
// Manually trigger the conversion event with the type and label passed to the form
PARSELY.beacon.trackPageView({
url: "%%parent_url{js}%%",
action: 'conversion',
data: { _conversion_type: "%%parsely_conversion_type{js}%%", _conversion_label: "%%parsely_conversion_label{js}%%" },
});
// Get the redirect from the Pardot hidden fields
// Setting the redirect in the Pardot UI causes a race condition with this code
const redirectUrl = "%%redirect_url{js}%%";
if (redirectUrl) {
top.location = redirectUrl;
};
}, 200);
//]]>
</script>
@phlipper
Copy link

phlipper commented Sep 1, 2022

@jcoryalvernaz for the lines using parseInt, remember to add the radix argument:

      session_count: parseInt("%%parsely_visitor_session_count{js}%%", 10),
      last_session_ts: parseInt("%%parsely_visitor_last_session_ts{js}%%", 10),

@jcoryalvernaz
Copy link
Author

@jcoryalvernaz for the lines using parseInt, remember to add the radix argument:

      session_count: parseInt("%%parsely_visitor_session_count{js}%%", 10),
      last_session_ts: parseInt("%%parsely_visitor_last_session_ts{js}%%", 10),

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment