How can I install Matomo in a React/Gatsby project hosted on Netlify?

Hey everyone!

I’m wondering how I would go about installing Matomo in a React project hosted on Netlify (or if this is even possible).

To be clear, I’m talking about installing Matomo, and not using the Matomo Cloud version of the service.

I’ve found these two libraries:

and I imagine if I wanted either of them to work with a first-party installation of Matomo (hosted at mydomain.whatever/analytics or something), that I would just put that in the respective URL field of either of those plugins, instead of a mydomain.matomo.cloud address.

I am currently moving my webapp from the default Create React App single-page structure to a Gatsby project, so I can use either of those, but the part I’m stuck on is figuring out how to get Matomo set up on my own domain, like mydomain.whatever/analytics.

All the installation guides or threads I have found are about installing it on a server manually, and as I understand it, Netlify is a “serverless” hosting solution, so I’m not even sure if this is possible.

I’m really lost and would greatly appreciate any help!

Thank you