Dynamic web content is not loading for the first page load for an anonymous user

Your software
My Mautic version is: 4.1.1
My PHP version is: 7.4
My Database type and version is: Mysql 8

Your problem
My problem is:

Hello everyone,
I’m using Dynamic web content with Email-> Empty filter to show the focus only to anonymous people.

Dynamic web content is not loading for the first page load, but it loads every time after refresh
or a page change.

I would like to make it work the first time page load.

At these points Mautic seems to first check the user and then save the row on the DB, so the second time it finds the row and verifies that it does not have the mail and the focus appears, but in this way I lose hundreds of OnSite views because Mautic does not understand the first time you are an anonymous.

Best Regards

Hi!
Are you running the Mautic tracking script in the header or footer?

Hi Joeyk, Footer!

Well here is the thing:
First you load the dynamic content and THEN you create the contact.
This way the first time you load, there will be no track of this person and the dynamic content cannot be loaded, since there is noone to load for.

I put the Dynamic Content DIV in the footer after the js tracking but it still doesn’t work.

<script type="text/javascript">
   (function(w,d,t,u,n,a,m){w['MauticTrackingObject']=n;
        w[n]=w[n]||function(){(w[n].q=w[n].q||[]).push(arguments)},a=d.createElement(t),
        m=d.getElementsByTagName(t)[0];a.async=1;a.src=u;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://domain.tld/mtc.js','mt');

    var oArgsMTC = {};
    mt('send', 'pageview', oArgsMTC);
</script>

<div data-slot="dwc" data-param-slot-name="onsiteollonl2">
    <h1>Dynamic web content for myslot</h1>
</div>

I forgot!
Inside the DWC slot there is a focus notification, which as mentioned works, but appears only the second time I browse the site …

I think your issue is that the DWC tries to appear too fast. Mautic is simply not ready with the contact. A person more skilled in Javascript could show you how to display the html after 2-3 seconds. So much would be enough.

You can certainly make advanced changes in JS but it is still a serious lack not to intercept the type of user the first time

1 Like

Well, your issue is not ‘not to intercept’ but more like ‘Intercept, save, display, callback, make desision and push content.’ Within the runtime of the script.
On the other hand I 100% agree. It should be like ‘if there is no cookie yet, show this’

ENJOY :muscle:

<script type="text/javascript">
	(function(w,d,t,u,n,a,m){w['MauticTrackingObject']=n;
	w[n]=w[n]||function(){(w[n].q=w[n].q||[]).push(arguments)},a=d.createElement(t),
	m=d.getElementsByTagName(t)[0];a.async=1;a.src=u;m.parentNode.insertBefore(a,m)
	})(window,document,'script','https://domain.tld/mtc.js','mt');

	mt('send', 'pageview', oArgsMTC,{
		onload: function() {
			if($(".mautic-slot .empty-dwc").length)
				MauticJS.replaceDynamicContent(oArgsMTC);
		}
	});
</script>

<div data-slot="dwc" data-param-slot-name="onsiteollonl2" class="mautic-slot">
	<h1 class="empty-dwc"></h1>
</div>

It wasn’t easy but we did it!

We checked mtc.js and found the function that processes the DWC then double check on the onload to verify that the default content has been replaced by focus (of course, as we reported the first time, it never passes and the onload fix the problem), in this way double calls are not created on subsequent visits where Mautic has already identified us.

3 Likes

Oh yes. Sweeeeet! Thank you for sharing it.

This is great - I have a question, is there a way to update this on Mautic code side and not on placing the tracking script on a specific page.

I ask as we are using WP-Mautic to insert the tracking script.

If so which directory and file to edit ?

Thanks

@joeyk - if you have some time to shed some light on the matter

I think the tracking has to run in the browser. You can host the js script on your server and call it remotely, just like mtc.js

@spiderdev - I have the same issue on my instance of Mautic 4.1.2.

I tried your solution, but my browser console gave an error regarding oArgsMTC.

I’m not a developer, but from my limited knowledge of javascript, it looks to me as if the variable is not defined (however, it was in your first post).

Please could you confirm on this?

Thanks

Hi, bringing this topic up again as I have run into this issue and am unable to get things working.

I am running 4.4.4 and have two dynamic slots on a react website and on first load nothing is coming up. On hard refresh the correct slot shows. The two slots are differentiated between email is empty and not empty.

Inside the logs I am seeing both the GET calls however with a 204 response code which from what I understand is empty content.

If there is someone that can explain how I can implement the solution above I would very much appreciate that.

Thanks,

Hello Mike,
is your Dy Content campaign based or filter based?

filter based

Ok. Is it a WP site where you added the tracking and dynamic content by using wp shortcode? If yes, try to add the actual code.

nope it is actually a react site (I think), however I did give it a try on a Wordpress site with the code and not using the wp shortcode… still same behaviour