D365 Marketing Weekly
Have you seen the D365 Marketing Weekly newsletter yet?
A weekly issue covering features, functionality and news on the topic of Marketing, specifically covering Dynamics 365 Marketing and other interesting tools and tips for anyone interested in the subject.
Subscribe Here
*** 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:
Split Your Audience By Number Or Percentage In Customer Insights - Journeys


D365 Marketing Weekly
Have you seen the D365 Marketing Weekly newsletter yet?
A weekly issue covering features, functionality and news on the topic of Marketing, specifically covering Dynamics 365 Marketing and other interesting tools and tips for anyone interested in the subject.
Subscribe Here
This is just 1 of 480 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.




10 thoughts on “Capturing UTM Parameters Via Outbound 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!!

  3. Hi Megan,

    This is a great post. Thanks for your valuable inputs. One question I have is that I’d like to be able to measure the conversions via Google Analytics’ Goal conversion using a thank you page (confirmation page). Once the form is submitted, I’d like to redirect the user to a confirmation page with specific UTM parameters. The issue is that the same form exist on multiple landing pages so I only have one redirection URL to work with. Is there any way that I can pass the same UTM parameters to the thank you page as well?

    Thank you,
    Matt

    1. Hi Matt. Good questions! Yes, you could do this.

      1. You have one Marketing Form
      2. For each place you want to use the form, create one Form Page (from the Form hosting tab on the Marketing form)
      3. When you create each Form Page, you can then set a different redirection URL for each one. You would then use the script generated and add it to the related landing page
      4. If you then want to pass the UTM Parameters from the URL where your form is included and pass it to the redirected thank you page, you could do this using Google Tag Manager doing something like this: https://www.analyticsmania.com/post/transfer-utm-parameters-google-tag-manager/

      I hope this helps!

  4. Hi Megan,

    Hope all is well. One more question, appreciate if you could response. I’m not generating a new lead every time there is a submission. Instead, I update the records if the lead already exist. So for instance if someone comes from FB campaign the UTM parameters will show that. Next they if they fill out another form, this time directly by visiting the landing page without any UTM parameters. When this happens I’d like to update the UTM parameters as direct-visit. The problem is that when I update the value of default hidden UTM fields as “direct-visit”, the UTM parameters don’t update the when the form submission comes from a digital campaign where UTM parameters exist on the URL.

    How would you fix this issue?

    In summar:

    1) All hidden UTM fields has direct-visit as default value
    2) When form submission comes from digital ads, the UTM fields should reflect that. (I’m using the JavaScript code without any issue)
    3) When form submission comes from direct visit, the UTM fields should be updated as direct-visit
    4) There is no new submission every time. Instead, I update the records.

    Thank you

    1. Hi Matt, just trying to understand your question. So are you saying that on some forms you fill out the hidden field and set it as direct-visit in one of the UTM mapped form fields? If you have filled it out, and then your Javascript is running to update those hidden fields, then I guess it would likely override it. I would suggest removing the direct-visit value from your UTM hidden field. Then having a flow that runs so that if the UTM field is empty, and the referrer URL doesn’t contain the term utm, then set the value on the lead as direct-visit.

Leave a Reply

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