Form tracking: Dynamics 365 Marketing

Updated by Aleksandar Grbic

Please only implement the scripts below IF you are currently using the legacy version 1.0 of Dreamdata's Web Tracking script. Otherwise, we recommend using the new Web Tracking script, version 2.0, which has built-in support for form tracking, intent sources and other integrations.

This guide explains how to set up tracking for Dynamics 365 forms.

Tracking all forms

Integrating Dreamdata with Microsoft Dynamics 365 Marketing Forms enables efficient tracking of user interactions.

You can track all the Marketing Forms on your website using the snippet below. The downside of this approach is that all your form submissions would be labeled with the same name, form-submitted. If you would like to track one or multiple forms and assign distinct names, e.g. demo-booked

Please proceed to the following example.

MsCrmMkt.MsCrmFormLoader.on("afterFormSubmit", function (event) {
var email = event.formPlaceholder.querySelector("form input[type=email]").value;
analytics.identify(null, { email: email });
analytics.track("form-submitted");
});

We recommend subscribing to afterFormSubmit event because it's what is recommended in the official documentation:

Triggers on form submit after the form submission is sent to the server. It triggers only when the submission is successful. It triggers before the redirect or showing the confirmation message.

Alternatively, it's possible to change afterFormSubmit to formSubmit and track just before the form is submitted to the server.

Finding the Form Field ID

  1. Open your marketing form and switch to Edit mode.
  2. Open the HTML tab.
  3. Find the ID of the field you want to populate by searching for the field name. You will find the id assigned to an attribute called data-form-block-id, e.g:
    1. data-form-block-id="g3ace55a-a22f-ed11-bba1-000d3ab1d77c" (this is an example id, each of your forms will have a different one)
    2. Note your form's form-id as it will be used in your tracking script.
    3. You will have to repeat this process for every single form that you want to track

To efficiently track one, or multiple forms using the distinct event names, use a mapping object to associate form IDs with event names:

MsCrmMkt.MsCrmFormLoader.on("afterFormSubmit", function(event) {
// Create a Mapping Object:
var idsToName = {
"form-id-1": "event-name-1",
"form-id-2": "event-name-2",
// Add additional form IDs and event names as needed
};

var email = event.formPlaceholder.querySelector("form input[type=email]").value;
var formId = event.getFormPageId();

analytics.identify(null, {
email: email
});

// "form-submitted" is used as a fallback name, in case a mapping between a form id and friendly name doesn't exist
analytics.track(idsToName[formId] || "form-submitted");

});

For more information, refer to the extended outbound marketing forms using code. Click here.


How did we do?