*** 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.
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.
Now click on Triggers, and then click on New.
In the trigger configuration, click to select a trigger.
Now we can select Form Submission as our trigger. So when a form is submitted we will DO SOMETHING.
Give the new Trigger a name and leave it set as All Forms. More on this later on.
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.
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.
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.
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 anywhere in the Variable Configuration area, then select Data Layer Variable.
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.
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.
Set the Track Type to Event.
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).
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.
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.
In the Triggering section at the bottom of the Tag, click anywhere in the middle.
Select the Form Submissions trigger that you created earlier.
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.
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.
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.
We are now done in GTM and you can publish the changes.
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.
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.
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.
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?
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).
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:
Auto Assign Leads Without Code Using Lead Scoring & Work Assignment
This is just 1 of 477 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.
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?
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.
Hello, how can I track the same but using GA4 instead of UA? Thanks!
Hi Alessandro, sorry, I have not done enough digging in to G4 yet. I’m finding it hard to figure out a lot of things I can do in UA that I am not sure about in G4!!!
Hi Megan,
Can you help me with tracking in Google Ads?
Hi Surjan, no sorry, Google Ads is not one of my topics of interest or knowledge. You would need to find someone who works with Google Ads to figure out how to meet your requirements.