Quantcast
Channel: Support & Bugs - Matomo forums
Viewing all articles
Browse latest Browse all 5706

"Vanilla" Matomo in a React.js application

$
0
0

@bkis wrote:

I want to track the usage of a Single Page Application (React.js) with Matomo.
I know there is a guide to include it in SPAs, but it doesn’t work for me. The guide says you should include the tracking code as usual and then call

_paq.push(...whatever...);
_paq.push(['trackPageView']);

for every consecutive URL change. But aren’t the _paq.push([‘trackPageView’]); calls supposed to be made before the script is loaded?

It seems to work for the first page view (when the tracking code is executed), but using _paq.push afterwards gives me an error:

_paq.push() was used but Matomo tracker was not initialized before the matomo.js file was loaded. Make sure to configure the tracker via _paq.push before loading matomo.js.

That kind of makes sense to me - but the guide for SPAs seems to suggest the above procedure.

I even tried to execute the full tracker code on every URL change, but of course this prepends a new script tag with the matomo.js for every change (ending up with duplicate script tags) and still gives me the same error.

Is there anything i forgot? I don’t want to use third-party modules like piwik-react-router, because this would force me to change a lot of my application logic just for including the tracking.

Thanks in advance for any help!

Posts: 6

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 5706

Trending Articles