Marketo forms in single page applications - incorrect referrer

Junnu_Ekman
Level 1

Marketo forms in single page applications - incorrect referrer

Hi!

My colleagues and I have run into an issue with Marketo forms on our website.

Background:

Our website is a so-called "single page application", which means that when a user navigates between pages, there isn't a "normal" page load, but the URL just changes and the content is replaced.

Issue:

This causes the issue that when a user fills out a form on page A and navigates to page B to fill out another form, on both times the submitted "_mktoReferrer" is the URL of page A. In Marketo, this incorrectly indicates that the forms were filled out on the same page.

(It used to be so that the Marketo forms' "base script" (forms2.min.js) was loaded immediately on the first page of the session, which caused even more issues referrer issues, but this has now been changed to load the script only when a separate "form module" is opened [= forms are loaded into a "lightbox" only when a user clicks certain CTA elements.])

Solution?

Has anyone else come across with this kind of an issue? Were you able to solve the problem? I would be very grateful for any advice!

Best regards,

Junnu Ekman

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo forms in single page applications - incorrect referrer

Good question. The problem is that the _mktoReferrer is cached by the library when first loaded, so it's always the original document.location.href -- kind of an unnecessary optimization but there it is.

The only way I know of to get around this is to delete window.MktoForms2 and reinject forms2.min.js after changing the location (I assume you're using replaceState in your SPA to change the loc).

This is something we do when switching the destination instance of Marketo forms, which is a rare need but doesn't work completely unless you start with a fresh Forms 2.0 library + fresh form render each time.