Sunday, February 5, 2023
More

    Latest Posts

    Using An Unmapped Form Field To Capture The Referral URL In D365 Marketing

    One of THE BEST things about being a part of the Dynamics and Power Platform Community is the content people produce. Many a time I’ve been helped out by reading someone’s blog or watching their video, but not just with getting an answer. Sometimes the bigger help is how it can spark off your own idea or musings about if something related is possible. This is one such situation. I knew my good friend @AmeyHolden had written a post about capturing the referral (or referrer) url via a form submission so you know what page the submitter was on prior to filling out your marketing form. Once you know how, it’s not difficult, but I wanted to also make it easier for marketers to access the Javascript required, but also didn’t want to populate it on to a Contact (or Lead) field. In this post I’ll piggyback off Amey’s post as the starting point.

    The first thing is creating a new marketing form field. It’s just a single line of text as the field type. However, where most times you would be mapping it back to a Contact and/or Lead field, in this instance we will leave both of them blank. If you did want to map it, you would need to make sure you have a field on those record types where you want to capture it.

    Click to view in detail

    Once you have your marketing form field, add it to your marketing form(s) and make sure you set it as being hidden. Don’t set a default value.

    Click to view in detail

    Go ahead and make the marketing form live. You will notice the message displayed at the top. It’s not an error, but more of an informative warning to let you know that the form has at least one field on it that’s not mapped to anything, which we already know. So it’s fine, ignore it and carry on.

    Click to view in detail

    Now we need to use a bit of Javascript to take the URL of the page the person was on prior to visiting your form, and pass it through as the form field value when the submission is created in D365. For this, we need to get the GUID of the form field. So go back to it and open the record. Then from the top in the browser get the last part of the URL which comes after msdyncrm_marketingformfield&id=. Save that id somewhere.

    Click to view in detail

    This next part isn’t needed, but it’s more of a nice to have to help out other marketers creating forms and adding them to your website. Ideally now that you have the Referrer URL form field, you can add it to your Marketing Form templates so it’s always included. When you have a marketing form to embed, you create a record called a Form Page (msdyncrm_formpage). Add a new multiline text field called Referral URL Script, and add it to the form of that table. Then create a new business rule.

    Click to view in detail

    There are several ways you can do it, but I have it set as the condition is if the Referral URL Script field doesn’t contain data, then set the field value to contain some JavaScript.

    Click to view in detail

    This is the JavaScript to add. Make sure you add the GUID of your form field that you added at the start, and replace that where I have YOUR_FIELD_ID. Then save and make your business rule active.

    <div style="display:none"> <script> MsCrmMkt.MsCrmFormLoader.on("afterFormLoad",  function() {   document.getElementById("YOUR_FIELD_ID").value =  document.referrer; }); </script></div>

    I’ve added the field directly below where the auto generated script is provided. This way it makes it easier for people and you don’t have to go and look for it every time you want to add it. Just make sure you do actually have the field on the marketing form. Now you can take the first script provided by Microsoft and add it to your website where you want your marketing form to g, then add the second referral url script directly after it.

    Click to view in detail

    Now when you start getting your form submissions, the Referrer URL field will be populated with the URL from the page the submitter was on prior to landing on page that included the marketing form. Note that because we are not mapping this to a field, they will only be contained in the marketing form submissions record.

    Click to view in detail

    This information is really useful though as if you have followed this blog where I show how you can create a form submission email notification, the referrer URL will be included here too.

    Click to view in detail

    Latest Posts

    Don't Miss

    Stay in touch

    To be updated with all the latest news, offers and special announcements.