Capture UTM Parameters in Dynamics 365 Marketing Forms Using JavaScript (Dynamics 365 Customer Insights)


When running marketing campaigns, UTM parameters help us understand where our leads are coming from. They help us track whether a lead came from Google Ads, Facebook campaigns, email campaigns, or some other source.

Recently while working with a Dynamics 365 Marketing form, we used a small JavaScript snippet to automatically capture UTM parameters from the URL and store them directly into marketing form fields.

 <script>
document.addEventListener("d365mkt-afterformload", function () {
    const params = new URLSearchParams(window.location.search);
      const mappings = [
        { param: "utm_source", name: "custom_utm_source" },
        { param: "utm_medium", name: "custom_utm_medium" },
        { param: "utm_campaign", name: "custom_utm_campaign" },
        { param: "utm_term", name: "custom_utm_term" },
        { param: "utm_content", name: "custom_utm_content" },
        { param: "gclid", name: "custom_gclid" },
        { param: "gclsrc", name: "custom_gclsrc" },
        { param: "fbclid", name: "custom_fbclid" }
    ];
    mappings.forEach(function (m) {
        const field = document.querySelector(`[name="${m.name}"]`);
        const value = params.get(m.param);

        if (field && value) {
            field.value = value;        
        }
    });
});
</script>

Suppose the marketing form URL is opened like this:

https://contoso.com/form?utm_source=google&utm_medium=cpc

In the example below, the values from the URL are automatically populated into the form fields.

The script first waits for the Dynamics 365 Marketing form to fully load using the d365mkt-afterformload event. This is important because the fields may not yet exist when the page initially loads.

After that, the script reads the query string from the URL using URLSearchParams. So if the URL contains values like utm_source=google or utm_medium=cpc, those values become available to the script.

The mappings array is used to map URL parameters to marketing form fields. For example, utm_source maps to custom_utm_source and utm_medium maps to custom_utm_medium.

The script then loops through each mapping, finds the matching field inside the marketing form, and sets the value automatically.

Using this approach helps us capture campaign attribution data directly inside Dataverse during form submission

References –

https://paulinekolde.info/javascript-library-for-real-time-marketing-form-in-customer-insights

Extend Customer Insights – Journeys marketing forms using code

Hope it helps..

Advertisements

Customize the Real-time Marketing Form form / Form Editor to add field (Dynamics 365 Customer Insights – Journey)


Suppose we want to add the Lead Type (a custom choice field) to the Marketing Form’s form / form settings (RTM).

Open the Form table for customization, here we need to add the field to below 2 forms.

Starting with the Form Settings form, drag the field to the form.

A screenshot of a computer

Description automatically generated

If we check the form now, it will ask us to add it to the main form.

A screenshot of a computer

Description automatically generated

Open the Information (Main) form, double click the field to add it. As the field will not render in the form designer, select the field from the Tree View, and Hide it.

A screenshot of a computer

Description automatically generated

Or we can also open the form in the classic designer, there we will be able to see the field.

A screenshot of a computer

Description automatically generated

On saving and publishing the change, we can see our Lead Type field appearing on the Form Designer.

Please refer for more information –

Customize the form editor

Hope it helps..

Advertisements

Fixed – This assets-oce.mkt.dynamics.com page can’t be found in Dynamics 365 Marketing


Recently we got the below error while trying to open the files in our Real-time marketing Assets Library.

We raised the Microsoft Support ticket for this and got the issue fixed.

This was because our environment was in Admin mode. (as we were going live so had kept it in admin mode, till we verify it), and there are specific tasks related to processing marketing content, such as resizing image / optimizing image / etc. that requires some Async Service to run in the background which needs the environment to be in the non-admin mode.

Disabling the Admin mode for the environment fixed it.

Hope it helps..

Advertisements

Fixed – We can’t find the form page you’re trying to load – Dynamics 365 Marketing


Recently we saw the below error in one of our marketing forms hosted on the website –

We can’t find the form page you’re trying to load: <div data-editorblocktype=”FormBlock” data-form-block-id=”64d87bc7-279d-ed11-aad1-00224814fd52″></div>. Please check your page setup.


This occurs if the form is not Live.


Making the form “Go live” will fix the issue.


Hope it helps..

Advertisements

Fixed – The domain where this form is embedded might not be enlisted as a domain record for externally hosted forms in Dynamics 365 Marketing


Recently we were getting the below issue for our Marketing Forms hosted on an external website on a particular authenticated domain. The pages were working fine in other authenticated domains.

The domain where this form is embedded might not be enlisted as a domain record for externally hosted forms. Otherwise, a browser extension or plugin may be blocking this form from loading. Review and reload form to continue.”

This particular domain was also shown as authenticated in our Dynamics 365 marketing.

Our website was e.g. https://www.domain.kiwi/ so we had domain.kiwi authenticated in Dynamics 365 Marketing.

Eventually, we had to raise a Microsoft Support Ticket and were instructed to add/ authenticate www.domain.kiwi   (with www.) also, doing so resolved the issue for us.

Also, there seemed like a UI bug in the Marketing which will cut out “www.” automatically when trying to authenticate the domains.

Hope it helps..

Advertisements

Fix – Exception in creation of lead (Dynamics 365 Marketing)


We were getting this error in the submission of one of our outbound Marketing forms.

Activity id: e1ede147-efb6-457d-bc19-826c6176a2e4, Request id: jH7xRiEzGFTdZQTbE2fkh9_Z_WtjumCqJERuYZbGSL0_0, Exception: Entity ‘Contact’ With Id = 896b960d-c5d7-4c4d-95c7-a9e226afbf8e Does Not Exist

The form had only the Lead form matching defined and Only leads for Update contacts / leads.

So here because of some earlier multiple/different form submissions, a contact got created and stored in the browser’s cookie, which CRM was referring to, and trying to set a Parent Contact for the lead record even though we were having Only leads set for update contact/leads option.

This is the behavior of the product.

https://learn.microsoft.com/en-us/dynamics365/marketing/marketing-forms#createupdate-leads-only

The solution is to delete the cookie or try in incognito or in-private mode or a different browser, and it would work.

This would probably arise because while setting up marketing forms we would do multiple submissions with test data for testing.

Hope it helps..

Advertisements