Capture Referrer URL with Dynamics 365 Marketing Forms
Dynamics 365 Marketing forms can be embed on your own external website to submit back both mapped (to contact or lead) or unmapped (stored as form submissions) values into Dynamics 365.
In a previous post I discovered that the marketing form submission record captures (and sneakily hides) the web page that the form was submitted from aka the ‘Source URL’, but what about the website they came from before they landed on the form aka the ‘Referrer URL’. The instructions are all exactly the same as in this post, just name the field ‘Referrer URL’ instead of ‘Website URL’ and when you get to ‘Populate Website URL on form submit’ use the script below instead. Rather than asking for window.location.href we ask for document.referrer
_YOUR_FORM_HOSTING_SCRIPT_ <div style="display:none"> <script> MsCrmMkt.MsCrmFormLoader.on("afterFormLoad", function() { document.getElementById("_YOUR_FIELD_ID_").value = document.referrer; }); </script></div>
Short, sweet and simple but so very valuable for your marketing attribution metrics.
Links
Official Microsoft instructions here on a simple embedded form scenario -> https://docs.microsoft.com/en-us/dynamics365/marketing/embed-forms#create-an-embedded-form
Further JavaScript for embedded form extensibility options documentation -> https://docs.microsoft.com/en-us/dynamics365/marketing/developer/marketing-form-client-side-extensibility