Skip to main content

Notifications

Google analytics integration with Dynamics 365 Marketing via UTM tagging

As the email atomizing using UTM tags is still under review, the below illustration is purely a manual way of meeting the needs of our customers to integrate google analytics with Dynamics 365 Marketing using UTM tagging.

Requirements:

  • Dynamics 365 Marketing instance
  • WordPress
  • Handl UTM tag manager plugin for WordPress
  • Javascript/Jquery additional script
  • 3 new fields related to the Lead entity

Prepare Dynamics 365 Marketing by creating 3 new fields related to the lead entity. These fields are called respectively UTM Source, UTM Medium and UTM Campaign. (This page provides more information on the definition and usage of these fields: https://ga-dev-tools.web.app/campaign-url-builder/)

Install “Handl UTM manager’ plugin by Haktan Suren in your WordPress site. This easy to use free plugin creates a cookie that store the UTM Source, Medium and Campaign variables in a variable that we will later on access. (https://www.haktansuren.com/handl-utm-grabber/)

Check if the plugin is successfully storing the variables by navigating to your website through a link with UTM tags. You can use the campgain url builder by google to create this links. This will look something like this:

yourwebsite.com?utm_source=newsletter&utm_medium=banner&utm_campaign=spring_sale

Press F12 in Google Chrome to open your developer window and look for “handl_utm”. This will return the following result if everything is working as expected:

We now have successfully stored the UTM variables from a tagged link into a cookie in our WordPress website. The next step is to submit these variables to Dynamics 365 through an embedded marketing form. This means that the Dynamics 365 Marketing form that we created before should contain the 3 UTM lead fields. We do this by first creating a marketing form field in Dynamics 365. (Below is an example of one of these fields)

The next step is to embed these form fields in your Marketing Form templates. These fields should be hidden. You might have to play with the HTML a bit in order to have them appear correctly, i.e. make the section as small as possible. (For debugging purposes I suggest not hiding the fields till everything is working like expected.)

Almost there! Please create a form based on the template above and host it on your website.

In this example, I created an event with the form attached to it. I copy the “form Hosting” code to a page in WordPress and ‘voila’, the form appears and is almost ready to take registrations.

The final step is to let the website ‘magically’ fill in our stored UTM variables in the hidden fields on our Dynamics 365 Marketing form. We do this by adding a little piece of Javascript:

<script>

MsCrmMkt.MsCrmFormLoader.on(“afterFormLoad”, function(event) {

$(“input[title=’UTM Source’]”).val(handl_utm.utm_source);

$(“input[title=’UTM Medium’]”).val(handl_utm.utm_medium);

$(“input[title=’UTM Campaign’]”).val(handl_utm.utm_campaign);

})

</script>

This script will execute an event after the Dynamics form is loaded. However, it still only works if you place this code after your Form Hosting script. So I suggest adding it to the footer or directly as a script below the form.

Congratulations! You should now be able to fill in the form and find the UTM variables back on the lead record. I recommend checking it through a simple API request so that you can avoid changing the lead forms:

– orgurl/api/data/v9.1/leads(recordid)

Result:

You are now able to track your marketing efforts through the complete funnel and see if a specific campaign was effective. (link/form/lead/opportunity/closed deal). Something that should work out of the box with every Marketing/CRM system. Hopefully, Microsoft will implement a better solution soon, but in the meantime enjoy this ‘quick fix’.


This was originally posted here.

Comments

*This post is locked for comments