Matomo Tracking Script is failing as the api throws Bad Request

I am currently experiencing issues with the Matomo tracking script on my website. Despite implementing the script as per the instructions on your website, it does not seem to be working correctly. I checked the API call in the network tab and found that it failed due to bad requests. I have added the details below.

Error is seen in the browser console:

The method ‘setTrackingSource’ was not found in “_paq” variable. Please have a look at the Matomo tracker documentation:

TypeError: The method ‘setTrackingSource’ was not found in “_paq” variable. Please have a look at the Matomo tracker documentation:

API Failure recorded in network tab:

POST 400 (Bad Request)

Query String Parameters :

action_name: Combifam – Official Site of Combifam FC…
idsite: 8
rec: 1
r: 011262
h: 14
m: 52
s: 23
_id: 107a9b209baf44db
_idn: 0
send_image: 0
_refts: 0
pdf: 1
qt: 0
realp: 0
wma: 0
fla: 0
java: 0
ag: 0
cookie: 1
res: 1366x768
pv_id: Y1GDiY
pf_net: 719
pf_srv: 1393
pf_tfr: 3
uadata: {"fullVersionList":[{"brand":"Chromium","version":"112.0.5615.139"},{"brand":"Google Chrome","version":"112.0.5615.139"},{"brand":"Not:A-Brand","version":""}],"mobile":false,"model":"","platform":"Windows","platformVersion":"10.0.0"}

Response from the API:

This resource is part of Matomo. Keep full control of your data with the leading free and open source web analytics & conversion optimisation platform.

This file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use index.php instead.

Tracking script used:

var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
(function() {
var u=;
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '8']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);

<!-- End Matomo Code -->

Plugin used : WP-Matomo Integration (WP-Piwik) – WordPress plugin |

Note: This issue is not WordPress-specific. We are getting the same errors on other sites as well when we use the tracking script generated by our On-Premise Matomo Analytics.

Instance details:

Matomo version: 4.14.2
MySQL version: 5.7.42-0ubuntu0.18.04.1
PHP version: 8.2.4

We are stuck in our Matomo Analytics integration due to the above issues. How do I fix them?