SPA and Contact Monitoring

Is it possible to use Mautic JS tracking tool in a single page application? I tried by calling mt(‘send’, ‘pageview’) multiple times for each page visited by the user but looks like only the first call will actually work so only the first page is tracked

1 Like

Is it possible to use Mautic JS tracking tool in a single page application? I tried by calling mt(‘send’, ‘pageview’) multiple times for each page visited by the user but looks like only the first call will actually work so only the first page is tracked

does anyone have a solution for this now?

Hi!
Are we talking about a single page application, where the page reloads itself with ajax?
If so, you can use the API to inject new info when the page is loaded.
If not, than please rephrase, cause I’m not sure I understand.

So, in SPAs, I have to go to every single page and call mt(“send”, “pageview”)

Hi.

I am very annoyed that I can’t measure the URLs in my SPA pages with mautic.
Can you please tell me what the API is?

First can you please tell me what an SPA is, cause i know only the meaning when I’m soaking myself and getting a massage.

1 Like

Got it. Single page application duh.

Add mautic to the header and it will measure everything.
This is what api is:
https://lmgtfy.app/?q=api+wikipedia
Mautic api:
https://lmgtfy.app/?q=api+mautic

But I dont think tracking with Api is the right way. Javascript is super easy. Need help?

Hi.

Thank you for your reply!
Also, sorry for the confusing question.
Yes, SPA is a single page application.

For example, if a user is directed to the following page from a matutic email, the first page (Page1.html) can be measured in the matutic admin panel, but the next page (Page2.html) will not be measured.

demosite
http://mat000.php.xdomain.jp/Page1.html

I use GoogleTagManager to set the tag of mautic to the website. Is it possible to tell me how I can measure these pages as well?

Hi,
The issue is, that Mautic tracks pageviews.
But your app doesn’t reload the pages, just the embedded content. As a result, there is nothing to track.
You need to fire the tracking event for each ‘content piece’ separately. I wouldn’t call those embedded content pieces pages, cause they are not.

1 Like

Thank you for replying.

So does that mean that mautic can’t measure this kind of SPA page transition?

As others mentioned before, you need to correctly fire the pageview event. Add the javascript to each page and it might work.

Joey

Hello.

Thank you for your kind answer.

I’m not an engineer, so I’m not too familiar with javascript, but do you know of any pages that show how to write it so that it works correctly?
I’m not an engineer, so I don’t know much about javascript.

Hi,

I wouldn’t call them “Page 1” and “Page 2”. Rather “Content 1” and “Content 2”.

Mautic (and Google Analytics as well including any page tracking software) can track newly loaded pages by firing the tracking script in the header.

As you are not loading the header you need to fire the script somewhere else.

You can fire a tracking pixel:

<img src="https://example.com/mtracking.gif?page_url=http%3a%2f%2fexample.com%2fpage1&page_title=Page%20One&email=user%40theirdomain.com" style="display: none;"  alt="mautic is open source marketing automation" />

Or you can add the js to that page and fire it on each page:
(This is for page 2)

<script>
var mauticUrl = 'https://example.com';
var src = mauticUrl + '/mtracking.gif?page_url=' + encodeURIComponent(window.location.href) + '&page_title=page2_' + encodeURIComponent(document.title);
var img = document.createElement('img');
img.style.width  = '1px';
img.style.height  = '1px';
img.style.display = 'none';
img.src = src;
var body = document.getElementsByTagName('body')[0];
body.appendChild(img);
</script>

Please check Contact tracking | Mautic

Sorry to be blunt, I just want to save you some time: this is an engineering issue on your side. Ask someone who understands javascript.

Also:
In case you’d use a free / hosted page builder: make sure you have your Mautic a subdomain of your Landing page domain otherwise tracking won’t really work due to 3rd party cookie limitations by browser policy.

Joey

Hi.

Thank you so much for your prompt reply!

I’ll set the javascript you gave me and give it a try!