Matomo is licensed under GPLv3. This means that if I use matomo in "covered work", then my "covered work" must be open source and licensed under GPLv3.
(DISCLAIMER: this is in no way legal advice)
It would mean this (you need to at least publish the other JS under GPL3, not soure about PHP) if all of Matomo was GPL3 licensed.
To avoid exactly this situation, the tracking code of Matomo is not GPL-licensed, but instead under a BSD-3-clause license. So as long as you follow these three rules (essenially meaning you are not allowed to remove the license header of the matomo.js file), you are free to use Matomo without any implications for the rest of the website.