matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.7k stars 2.62k forks source link

Uncaught TypeError: The method 'setTrackingSource' was not found in "_paq" variable. #20770

Closed naivedeveloper95 closed 8 months ago

naivedeveloper95 commented 1 year ago

I have embedded the scripts generated by Matomo (self-hosting) on a WordPress site. The first one is for Matomo Tracking script and the second one is for Tag Manager. The scripts generated are as follows:

`

` ` ` ## Context I am unable to accomplish Matomo tracking due to this error. I created this instance today itself. I have added the instance details at the bottom. ## Current Behavior ![image](https://github.com/matomo-org/matomo/assets/15083393/392a6812-ed4d-4f23-b605-2e3ac27926da) ## Note: I have made no changes other than installing the script generated by Matomo into the WordPress site. I tried with the WP-Matomo plugin as well as inserting the script into the code through HCFM in WordPress admin settings. Neither of these worked. Please suggest if there is something wrong that I am doing. ## Your Environment Matomo version: 4.13.3 MySQL version: 5.7.42-0ubuntu0.18.04.1 PHP version: 8.2.4
sgiehl commented 1 year ago

This seems to be a wordpress specific issue. The string setTrackingSource does not even occur once in Matomo's code. I'll move this to the Matomo for Wordpress repo, so the wordpress team can investigate.

mattmary commented 1 year ago

Hello @naivedeveloper95

Sorry to hear that you encounter an issue with our plugin. Can I ask you:

Mat

naivedeveloper95 commented 1 year ago

I tried different ways but ended up encountering the same error. Below are the methods I tried before raising this issue:

Note: I always had only one of them enabled at once. For example, if I added the snippet through code, I disable the HCFM one and did the same for other methods.

Kind regards, Satyam

mattmary commented 1 year ago

Hello @naivedeveloper95

I'm not sure to understand which configuration do you expect:

We recommand using our plugin for websites under 50k page views / month. Is it your case? Or you have a bigger traffic?

Please tell me what are your choices, and I will help you to solve your integration.

Kind regards

Mat

naivedeveloper95 commented 1 year ago

Which plugin should I use? Matomo on premise + the WP-Piwik or Matomo for WordPress plugin?

I have tried both of them individually, and it throws this error: image

mattmary commented 1 year ago

Hello @naivedeveloper95

I would say the answer is yours: if you have more than 50k page views / month, we recommand using Matomo on premise. In the other case, it's probably easier to use our WordPress plugin. On this choice made, and if you choose to use our WordPress plugin, I'll help you with your integration. Kind regards

Mat

naivedeveloper95 commented 1 year ago

I tried WP-Matomo Plugin and my Matomo instance is a self-hosted one. The plugin shows it is connected to my instance and I have also enabled tracking, still, it throws the error. I have added screenshots for you to look over.

image image image

mattmary commented 1 year ago

Hello,

So if your current configuration is the WP-Matomo plugin + Matomo on premise, I can't help you: this repository is dedicated to the Matomo for WordPress plugin only. I move your issue to the Matomo repository one. Kind regards

Mat

naivedeveloper95 commented 1 year ago

@sgiehl Can you please check if someone is looking into this issue? We need this fix urgently as we are integrating Matomo and WordPress tracking not working is a blocker.

sgiehl commented 1 year ago

@naivedeveloper95 I'm sorry, but in this case we aren't able to help you either. Matomo itself should work and does not contain any method called setTrackingSource. So if you have trouble with WP-Matomo plugin, maybe try to get in touch with the author of it here: https://github.com/braekling/WP-Matomo

Findus23 commented 1 year ago

Hi,

It seems like the only mention of setTrackingSource on the internet (apart from your posts) is this PiwikPro documentation: https://developers.piwik.pro/en/latest/data_collection/web/javascript_tracking_client/api.html#getTrackingSource

So is it possible that whatever code you are using to interact with Matomo, is not written for Matomo, but for Piwik Pro?

Findus23 commented 1 year ago

FYI, this is the issue:

curl -s  https://yoursite.example/ | grep -B 4 -A 4 setTrackingSource

<!-- /end HFCM by 99 Robots -->
<script>
var _paq = _paq || [];
_paq.push(["setTrackingSource","wordpress","1.2.1"]);
</script>
<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];

You website contains a script where _paq.push(["setTrackingSource","wordpress","1.2.1"]); is called and the warning you are seeing is just telling you that Matomo doesn't have any function called setTrackingSource (as that's apparently a Piwik Pro function).

And it turns out those lines are added by the https://de.wordpress.org/plugins/piwik-pro/ plugin, so just uninstall this plugin to remove the warning.

https://plugins.trac.wordpress.org/browser/piwik-pro/tags/1.2.1/includes/Plugin.php#L92

naivedeveloper95 commented 1 year ago

@Findus23 Worked like a charm! Thanks!