Sunday, February 5, 2023
More

    Latest Posts

    Filtering Out Google Tag Manager Traffic From D365 Marketing Website Visits

    If you are using D365 Marketing, and are trying to make the most from all the functionality, you’ve likely set up a marketing website record and generated tracking code to add to your organisations corporate website. This means you can track visits to the site, most of which will be anonymous, but with named visits showing when a Contact in D365 interacts with the site (assuming they have cookies in their browser allowing this). However, if you’ve set up the tracking code using Google Tag Manager (which is good best practice), you might have noticed something strange this in your visits. This is where a series of visits show up with a url relating to Google Tag Manager (https://gtm-msr.appspot.com/render2?id=GTM-PLUS-YOUR-ID). What causes them and how do you get rid of them by filtering out Google Tag Manager Traffic? Read on for details.

    If you don’t use Google Tag Manager you can probably just ignore all of this. If you are, you’ve likely set up a Custom HTML type tag and added your tracking code from D365 Marketing. Have a search through your website visits to see if you have anything like this. The Page address and Referrer URL both point to a link that includes your GTM id at the end of it. After doing some Googling, it came up that this could be caused by a couple of things. First, if someone is testing some GTM changes and previews them, but more likely it’s from visitors to your website who have JavaScript disabled in their browser. Google Tag Manager provides two scripts, one for those WITH JS enabled, and a no-script one that fires when JS is not enabled. This is fine and expected behaviour, but D365 Marketing still captures it as a visit. This isn’t unique to D365 and occurs in many other tracking utilities.

    Click to view in detail

    Thanks to this video I found here from Measure School, it explains perfectly how and why it happens. Their example was based on tracking when using Facebook Pixel, so I applied the same logic here. First thing, you have the tracking code for your website when you create the marketing website in D365.

    Click to view in detail

    Then in Google Tag Manager you likely created a tag with the Custom HTML type that fires on all pages of your website. Great!

    Click to view in detail

    However, what we are now going to do is split that up and create two tags that fire on all pages, both using the tag type of Custom HTML. In the first one we are going to add the items that are wrapped in the DIV tags. So the first line, then the last lines is what you need. You can see what you need below, but you will have a different div id, data-website-id and data-hostname. Make sure you use YOUR correct lines of the tracking code.

    <div id="dWftIH4jZfZKXBmyVMsXR-9Zc60sbXrqbOBIVAeM9Fzo"></div>
    <div class="d365-mkt-config" style="display:none" data-website-id="WftIH4jZfZKXBmyVMsXR-9Zc60sbXrqbOBIVAeM9Fzo" data-hostname="b3db011fec024820bd80f2114e60fabd.svc.dynamics.com"></div>

    Add it in to a Custom HTML tag like this.

    Click to view in detail

    Now we need to add in some logic that would only fire the D365 Marketing script part when needed. The logic states, if the page visited includes appspot.com (which is part of that URL that is showing up in our website visits that we don’t actually want captured), DO NOT RUN THE SCRIPT, which means that visit will not be captured in D365 Marketing. If it doesn’t include that, then run the script and we will capture the visit as intended. I believe the script URL should be the same for all, BUT double check the link that you see in your Javascript code in D365 Marketing to be sure.

    <script type="text/javascript">
    if (document.location.href.search('appspot.com') == -1) {
    	var script = document.createElement('script');
    	script.src = 'https://mktdplp102cdn.azureedge.net/public/latest/js/ws-tracking.js?v=1.84.2007';
    	var ref = document.querySelector('script');
    	ref.parentNode.insertBefore(script, ref);
    }
    </script>

    You should then be able to copy and paste this in to a new Custom HTML tag. Massive massive thank you to my brother, Owen Rumney, for the assist (AKA writing it) with the script logic.

    Click to view in detail

    This won’t remove any of the previous GTM visits you’ve captured, but it should stop them moving forwards. Again, as we’ve only done this in GTM for the D365 Marketing tracking code, it also shouldn’t impact anything else you have set up from a tag or trigger perspective. Hope this helps!

    Latest Posts

    Don't Miss

    Stay in touch

    To be updated with all the latest news, offers and special announcements.