Tracking Code with Webpack

After trying a lot of different scenarios, it doesn’t seem possible to have the Matomo tracking code compiled into webpacker.

I have a Rails 6 app with webpacker, which uses webpack to compile all the Javascript into one file. This has the advantage of having all the JS in one place, and only one file to download. While I can get the Matomo tracking code to compile successfully into webpack, it doesn’t seem to send any data back to the server.

It’s not a huge deal. I’m just putting the code in the head as instructed. I’m just curious if anyone else had run into, and perhaps solved, this problem.

Thanks in advance!


While I would not recommend that much to include the matomo.js in webpack as it makes Matomo updates (or even plugin updates that change the matomo.js) harder, there shouldn’t be any reason why it would not work.

Maybe webpack minifies the file and therefore renames _paq to something else breaking the tracking code. Maybe you could exclude _paq when minifying.