Categories: Dynamics Marketing
*** NOTE: ALL INFORMATION IS ACCURATE AT DATE OF PUBLISHING ***

In a previous blog post, I walked through how to capture the referral url via a marketing form submission and pass it back through as an unmapped form field. This got me thinking about other pieces of information that could be valuable. As a marketer, hopefully you are using and understand UTM Parameters, which can be passed through a URL and then used to analyse your website visits and success of campaigns in Google Analytics. Although currently there isn’t any functionality directly within D365 Marketing for adding UTM Parameters, ideally you are still adding them to the links in your marketing emails. In this post we will look at how you can capture those, and pass them back through in your form submissions and also map through to a Lead record if required.

There are several tools that exist to build urls for your campaigns, but my preferred one is the free tool from Google that you can find here: Campaign URL Builder. It’s really easy to use. First, you add the url that you want to take someone to when they click on the link from an email, paid online ad, or social media post. There are several options available, and you can use any that make sense for your organisation, but only campaign source and campaign medium are required. In this example, I’m creating a link I would share on Twitter (campaign source) and sharing as an organic social post (campaign medium). I am also naming my campaign marketing form submissions (campaign name) and it’s a general post (campaign content). These are open to interpretation but there are best practices Google suggests you follow.

Click to view in detail

Once you’ve added the various fields, your campaign url will be generated which can then be shared (either as the full or a shortened link).

Click to view in detail

When someone clicks on a link and that link includes a D365 Marketing form, how can we find out what the UTM parameters were? First thing, decide if you want to capture that information on new leads. If you do, add your new single line text fields on the Lead table. Then add in your new marketing form fields. Here we can see that I’ve gone with 4 different UTM parameters, and also the referrer URL (that I referenced in this post here). I’ve then mapped them to the new Lead field, but left the Contact mapping empty. You can map to Contact fields if you wish, but not a good idea to have this overwritten each time so I am leaving those unmapped. Make a note of the GUID (the id at the end of the URL) for each of your new marketing form fields, you will need those later.

Click to view in detail

Now we add those to a marketing form and make all of these fields hidden.

Click to view in detail

If you want to make sure a Lead gets created every time the form is filled out, make sure you change the Generate leads without matching field to Yes.

Click to view in detail

Make the form live, and get the generated JavaScript from the form hosting area on your form. You will then need to add that script to your web page, and then also add the script below. Where it shows YOUR_FIELD_ID, replace that with each of the GUIDS for each of your new form fields you created. Check out this post for a handy way to generate this new code on your form page records so it’s automatically provided for you on each form. MASSIVE thank you to my brother @Owen Rumney for helping me with the script.

<script>
MsCrmMkt.MsCrmFormLoader.on("afterFormLoad", 
function() {
let query = new URLSearchParams(document.location.search);
document.getElementById("YOUR_FIELD_ID").value =  document.referrer;
document.getElementById("YOUR_FIELD_ID").value =  query.get("utm_source");
document.getElementById("YOUR_FIELD_ID").value =  query.get("utm_medium");
document.getElementById("YOUR_FIELD_ID6").value =  query.get("utm_campaign");
document.getElementById("YOUR_FIELD_ID").value =  query.get("utm_content");
});
</script></div>

Once you’ve added your marketing form to your website, and you’ve got the link you generated using the Campaign URL Builder tool from Google, you can start sharing your link (or lots of links!). Hopefully hundreds of people flock to fill it out and you start getting submissions. Here we can see the form field submissions are getting populated with the data. We can see the referrer URL populated with the link for Twitter, then all of the UTM Parameters populated with the correct information from the URL.

Click to view in detail

If you are generating internal email notifications for form submissions, that should also include the UTM Parameters.

Click to view in detail

And if you’ve mapped the fields to a Lead record, they should also be populated with the information you need.

Click to view in detail


Check out the latest post:
D365 Marketing Chat With Amey Holden – Discussing Marketing Features from Wave 1 2023


This is just 1 of 372 articles. You can browse through all of them by going to the main blog page, or navigate through different categories to find more content you are interested in. You can also subscribe and get new blog posts emailed to you directly.


6 thoughts on “Capturing UTM Parameters Via D365 Marketing Form Submissions

    1. Hi Bhautik, care to expand on your comment? Not sure what you mean. Familiar to what?

  1. Awesome post as always! One thing I would like to add about the script is that it will only work properly when there’s one form on each web page. If you have multiple embedded forms on the same web page (which happens for some clients), only the hidden UTM fields of the first form would be populated. If the second form is submitted, the UTM fields will be empty.

    If multiple forms are used on one page, we can tweak the script to use “querySelectorAll” instead of getElementById. If JQuery is available, using $(fieldId) is a viable solution too.

    1. Hi Jake! That’s a good new perspective. Yes, I guess someone could have more than one form on a page (although I have yet to have a client with this requirement so never thought about it). Do you have a full script you could share that would help someone?

  2. What an awesome way to do UTM capture – thanks Megan! We are releasing auto-UTM tagging on all outbound URLs in messages in Feb 2023, and weren’t able to complete the related feature to capture UTM tags from inbound URLs. Its coming soon but its so great to see that there’s at least a workaround – with this solution and the auto-UTM tagging, customers will really be able to have a much better time getting insights in analytics products like Google/Adobe/Microsoft Clarity!

    1. Hi Ayushman, that’s wonderful to hear that the auto-UTM tagging is coming in Feb 2023! This will go a long way to help customers with their tracking in Google Analytics and also passing data back through in to Microsoft Clarity. Great work to you and the team!!

Leave a Reply

Your email address will not be published. Required fields are marked *