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

This post is important if you use Dynamics 365 Marketing. It’s important if you want to use Google Analytics (GA) for tracking your goals, and want to know exactly how many form submissions you’ve had for each form. Easy right? Hmm, well not if you want to use the same form, or the same thank you page. The only way you can track is if you have a different thank you page for each form you embed in your website. Well, so I thought for a long time, until I started digging in to Google Tag Manager (GTM) more and more. I’ve now got the steps to set all of this up in GTM that will help you track this no matter which way you are using D365 Marketing Forms. That includes the following scenarios:

  • One Marketing Form, Different Thank You Pages
  • One Marketing Form, Same Thank You Page
  • Different Marketing Forms, Same Thank You Page
  • Different Marketing Forms, Success Message Displayed
  • One Marketing Form, Success Message Displayed

Sound good? OK, buckle up, let’s get to it. First, this assumes you have Google Analytics and Google Tag Manager set up. If, not watch this video to see how to set up GA, and this to see how to set up GTM. Now go to GTM and then click on the Variables menu.

Click to view in detail

GTM includes several built-in variables for Forms. They are not selected by default, so click the box next to each one to allow the ability to pass through information from your forms that are submitted on your website.

Click to view in detail

Now click on Triggers, and then click on New.

Click to view in detail

In the trigger configuration, click to select a trigger.

Click to view in detail

Now we can select Form Submission as our trigger. So when a form is submitted we will DO SOMETHING.

Click to view in detail

Give the new Trigger a name and leave it set as All Forms. More on this later on.

Click to view in detail

At this point, we can preview what we’ve set up. It’s a good idea to know what is happening when a form gets submitted, which will hopefully explain the additional steps in this blog post. Click on Preview from the top right to interact with the website while having the ability to review all of the steps in GTM.

Click to view in detail

When it asks what page you want to review, make sure you put in a URL for a page that includes one of your D365 Marketing Forms embedded, or make sure you have the ability to navigate to it. Go ahead and fill out the form and then press the Submit button. Do not close the page, but minimise it to get back to GTM.

Click to view in detail

Here we can see that we triggered a Form Submit action. You can then click on it, then click on the Variables tab on the right and review the Output. If you scroll to all of the Form related variables, you will see that the information passed back is either long and messy or totally empty. This makes it hard to get to anything to pass back through to GA.

Click to view in detail

So, we are going to need to add a user-defined variable to help us out. Go back to the Variables area from the main menu in GTM and then scroll to the bottom of the variables till you see the User-Defined Variables. Click on New.

Click to view in detail

Click anywhere in the Variable Configuration area, then select Data Layer Variable.

Click to view in detail

In the Data Layer Variable Name, add something like formName. Then set the Data Layer Version to Version 2, and give the new variable a name like formName Custom.

Click to view in detail

Next, we will add our Tag. This will contain the information that gets passed back through to the Event which is then passed into GA. Select the tag type of Google Analytics Universal Analytics.

Click to view in detail

Set the Track Type to Event.


Click to view in detail

If you have added any Events in GA previously you will know that they need a Category. This is something you will add by typing into it, and whatever you call it will be displayed in GA, so go with something collective like Form Submission(s).

Click to view in detail

Next you will add the Action. Click on the add button next to the Action field. When the panel opens with all available actions, you should see the formName Custom user-defined variable that we added. So we can have the Category of Form Submission, then within that, we have the name of a form next.

Click to view in detail

Then we can add something as a Label that will show in GA. For me I thought the path of the page where the form lives would be of interest but this can be whatever you like. Set the Non-Interaction-Hit to True and then pick the Google Analytics ID from the list in Google Analytics settings.

Click to view in detail

In the Triggering section at the bottom of the Tag, click anywhere in the middle.

Click to view in detail

Select the Form Submissions trigger that you created earlier.

Click to view in detail

One last thing that is needed before you can see all of this working. Underneath the script you got for your form in Dynamics 365 Marketing, add in the following:

<script>
window.dataLayer.push({
    'event' : 'formSubmitted', 
    'formName' : 'Lead Generation'
 });
</script>

Instead of Lead Generation, put whatever you want to use for the name of the form that will show up in GA. Add the same script under each of your D365 Marketing Forms where you have added them to pages of your website, making sure to change the formName value for each one.

Click to view in detail

Now if you were to Preview the page again via GTM preview functionality, you will see the formSubmitted action and the formName Customer variable should show the name of the form you added to the script.

Click to view in detail

You can then submit the form and will then be able to get the information along with the page path and all other variables from the web page.

Click to view in detail

We are now done in GTM and you can publish the changes.

Click to view in detail

Go over to Google Analytics and then to the Behaviour section, then click on Events. You should see the tests that you did under the Event Category you added when you created the Tag at the end. Click on the Category name to access more information.

Click to view in detail

If you don’t see anything, make sure you have dates set for today. Also, give it five or ten minutes for the data to flow through.

Click to view in detail

At the view on the bottom, change the Primary Dimension to Event Action. Then click on Secondary dimension and search for label, then add Event Label.

Click to view in detail

Now I can see the total number of Events for each Event Action, which should show the name of your Form. The Event Label is showing the path of the page where the D365 Marketing Form lives. Perfect! One thing to keep in mind, your testing will show up here too. Also, notice in the list I have an action called undefined?

Click to view in detail

The undefined showed up because I hadn’t thought about the search forms on my website, which are also forms that can be submitted. So, back in the Form Submissions trigger, instead of having it trigger on All Forms, I changed that to Some Forms, and used the Form Class to make sure it only triggers when that doesn’t contain search-form (the CSS class on my search box form).

Click to view in detail

I REALLY hope this helps. I was really happy to figure this out and hope it will help my clients in the future!

You can watch a video on this here.


Check out the latest post:
Using An Unmapped Form Field To Capture The Referral URL In D365 Marketing


This is just 1 of 363 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.


2 thoughts on “Tracking D365 Marketing Form Submissions in Google Analytics

  1. If I add the script under the D365 Marketing Forms it fires the analytics event on every page load. How should I add it so it only fires when someone completes the form?

    1. Hi Jeno, it should fire, but you shouldn’t get this detail until the form has actually been submitted. You need the Form Submitted event to be able to pass through the Form Name.

Leave a Reply

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