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

**URL:** <https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406>\
**Category:** Product Support\
**Created:** [January 20, 2022, 12:05pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406 "2022-01-20T12:05:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![spiderdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/spiderdev/32/6712_2.png) [@spiderdev](https://forum.mautic.org/u/spiderdev)\
**Post date:** [January 20, 2022, 12:05pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/1 "2022-01-20T12:05:10Z")

</div>

**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

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 20, 2022, 12:18pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/2 "2022-01-20T12:18:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![spiderdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/spiderdev/32/6712_2.png) [@spiderdev](https://forum.mautic.org/u/spiderdev)\
**Post date:** [January 20, 2022, 12:25pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/3 "2022-01-20T12:25:44Z")

</div>

Hi Joeyk, Footer!

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 20, 2022, 12:27pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/4 "2022-01-20T12:27:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![spiderdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/spiderdev/32/6712_2.png) [@spiderdev](https://forum.mautic.org/u/spiderdev)\
**Post date:** [January 20, 2022, 12:31pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/5 "2022-01-20T12:31:58Z")

</div>

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

```auto
<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>

```

---

<div class="post-metadata">

**Author:** ![spiderdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/spiderdev/32/6712_2.png) [@spiderdev](https://forum.mautic.org/u/spiderdev)\
**Post date:** [January 20, 2022, 12:44pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/6 "2022-01-20T12:44:23Z")

</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 …

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 20, 2022, 12:59pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/7 "2022-01-20T12:59:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![spiderdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/spiderdev/32/6712_2.png) [@spiderdev](https://forum.mautic.org/u/spiderdev)\
**Post date:** [January 20, 2022, 2:33pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/8 "2022-01-20T14:33:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 20, 2022, 3:15pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/9 "2022-01-20T15:15:26Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![spiderdev](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/spiderdev/32/6712_2.png) [@spiderdev](https://forum.mautic.org/u/spiderdev)\
**Post date:** [January 20, 2022, 3:52pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/10 "2022-01-20T15:52:59Z")

</div>

ENJOY 💪

```auto
<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.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 20, 2022, 4:49pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/11 "2022-01-20T16:49:37Z")

</div>

Oh yes. Sweeeeet! Thank you for sharing it.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [June 13, 2022, 1:03pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/12 "2022-06-13T13:03:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [June 14, 2022, 10:53am UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/13 "2022-06-14T10:53:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [June 15, 2022, 5:54am UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/14 "2022-06-15T05:54:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pav03](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pav03/32/7028_2.png) [@pav03](https://forum.mautic.org/u/pav03)\
**Post date:** [August 16, 2022, 11:39am UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/15 "2022-08-16T11:39:23Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [July 17, 2023, 8:20am UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/16 "2023-07-17T08:20:40Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [July 17, 2023, 12:47pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/17 "2023-07-17T12:47:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [July 17, 2023, 1:09pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/18 "2023-07-17T13:09:29Z")

</div>

filter based

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [July 17, 2023, 6:04pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/19 "2023-07-17T18:04:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [July 17, 2023, 6:30pm UTC](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406/20 "2023-07-17T18:30:10Z")

</div>

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

[Next page](https://forum.mautic.org/t/dynamic-web-content-is-not-loading-for-the-first-page-load-for-an-anonymous-user/22406.md?page=2)
