Matomo analytics is not working after recent update

AI-generated summary

After updating Discourse, hosna reported that Matomo analytics stopped logging visits, despite the tracking code remaining unchanged. sam asked for the code, which hosna confirmed matched Matomo’s default snippet. sam suggested triggering a cache rebuild by adding whitespace to scripts — but hosna confirmed this had no effect. A JavaScript error — _paq is not defined — was found in the browser console hosna, pointing to a possible script loading order or CSP issue. sam escalated to xrav3nz, requesting a theme component for Matomo setup. Separately, hosna noted thousands of 404 Not Found job errors — sam confirmed they’re unrelated. xrav3nz later updated the Matomo how-to guide with a new theme component and advised removing old custom scripts. hosna confirmed the fix worked perfectly. The issue was resolved by replacing manual script insertion with the official theme component, eliminating script ordering and CSP conflicts.

2 days ago, I updated my discourse. However, after that, my Matomo analytics for discourse doesn’t log any visit at all. The code for Matomo is still in my discourse in the right place, and I didn’t change it at all.

What is the actual code you are using?

It is exactly what matomo gives me to use.


<!-- Matomo -->
<script type="text/javascript">
 var _paq = _paq || [];
 /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
 _paq.push(['trackPageView']);
 _paq.push(['enableLinkTracking']);
 (function() {
   var u="//zabanshenas.com/piwik/";
   _paq.push(['setTrackerUrl', u+'piwik.php']);
   _paq.push(['setSiteId', '2']);
   var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
   g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
 })();
</script>
<!-- End Matomo Code -->

Did you follow ALL the instructions here?

Can you add a space to each of the scripts and save, it will re-trigger building internal caches.

yes, I followed that instruction.

What scripts? I added a space in matomo script now. But it didn’t change anything.

It is not meant to change anything, just trigger a cache rebuild, is it working now? Are there any errors in the Discourse console?

@Johani can we theme-componentize the motomo howto… not high priority but going to add to your list.

No

If you mean in web console, yes there is an error:

_paq is not defined
@https://talk.zabanshenas.com/theme-javascripts/82e69cdd6bb252c18196db6bbda6863824daa213.js?__ws=talk.zabanshenas.com:5:1
value/<@https://talk.zabanshenas.com/assets/application-5aac05c89f92b6b70efa2541a2fa250a5ae09077adc80108caa7e1f30013078a.js:12:24463
f@https://talk.zabanshenas.com/assets/ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:11:31855
trigger@https://talk.zabanshenas.com/assets/ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:15:15187
i/</<@https://talk.zabanshenas.com/assets/application-5aac05c89f92b6b70efa2541a2fa250a5ae09077adc80108caa7e1f30013078a.js:12:19521
e@https://talk.zabanshenas.com/assets/ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:7:23077
invokeWithOnError@https://talk.zabanshenas.com/assets/ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:7:19387
flush@https://talk.zabanshenas.com/assets/ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:7:19832
flush@https://talk.zabanshenas.com/assets/ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:7:20592
end@https://talk.zabanshenas.com/assets/ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:7:20937
run@https://talk.zabanshenas.com/assets/ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:7:22006
_runExpiredTimers@https://talk.zabanshenas.com/assets/ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:7:25751
p/this._boundRunExpiredTimers@https://talk.zabanshenas.com/assets/ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:7:17981
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:29446:6
u
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:29446:6
o
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:29425:6
e
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:13125:10
invokeWithOnError
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:12554:8
flush
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:12613:8
flush
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:12737:8
end
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:12807:6
run
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:12921:10
_runExpiredTimers
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:13315:4
p/this._boundRunExpiredTimers
_ember_jquery-27e777857b8c0730dacfe09cb11711365d21a5db4f9ee0b85d494e4259cf6cda.js:12776:4
DEBUG: For more advanced debugging, install the Ember Inspector from https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/

Hmmm this could be an ordering thing, going to re-assign this to @xrav3nz

Kyle can you turn the motomo howto into a working theme component with settings first thing tomorrow.

Going to bump this in front of the queue in case there is an ordering issue in place due to CSP related changes.

@hosna you are going to have to wait a day here…

No problem

Another thing, I have thousands of Job exception: 404 Error: 404 Not Found in my logs. Is it related to this?

That sounds very unrelated to this issue

This is the backtrace:

/var/www/discourse/lib/file_helper.rb:51:in `block in download' /var/www/discourse/lib/final_destination.rb:373:in `block (3 levels) in safe_get' /var/www/discourse/lib/final_destination.rb:372:in `catch' /var/www/discourse/lib/final_destination.rb:372:in `block (2 levels) in safe_get' /usr/local/lib/ruby/2.5.0/net/http.rb:1503:in `block in transport_request' /usr/local/lib/ruby/2.5.0/net/http/response.rb:165:in `reading_body' /usr/local/lib/ruby/2.5.0/net/http.rb:1502:in `transport_request' /usr/local/lib/ruby/2.5.0/net/http.rb:1464:in `request' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/rack-mini-profiler-1.0.0/lib/patches/net_patches.rb:9:in `block in request_with_mini_profiler' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/rack-mini-profiler-1.0.0/lib/mini_profiler/profiling_methods.rb:39:in `step' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/rack-mini-profiler-1.0.0/lib/patches/net_patches.rb:8:in `request_with_mini_profiler' /var/www/discourse/lib/final_destination.rb:344:in `block in safe_get' /var/www/discourse/lib/final_destination.rb:388:in `block in safe_session' /usr/local/lib/ruby/2.5.0/net/http.rb:910:in `start' /usr/local/lib/ruby/2.5.0/net/http.rb:609:in `start' /var/www/discourse/lib/final_destination.rb:385:in `safe_session' /var/www/discourse/lib/final_destination.rb:336:in `safe_get' /var/www/discourse/lib/final_destination.rb:108:in `get' /var/www/discourse/lib/file_helper.rb:43:in `download' /var/www/discourse/app/models/user_avatar.rb:23:in `block in update_gravatar!' /var/www/discourse/lib/distributed_mutex.rb:34:in `synchronize' /var/www/discourse/lib/distributed_mutex.rb:5:in `synchronize' /var/www/discourse/app/models/user_avatar.rb:14:in `update_gravatar!' /var/www/discourse/app/jobs/regular/update_gravatar.rb:12:in `execute' /var/www/discourse/app/jobs/base.rb:137:in `block (2 levels) in perform' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/rails_multisite-2.0.4/lib/rails_multisite/connection_management.rb:63:in `with_connection' /var/www/discourse/app/jobs/base.rb:127:in `block in perform' /var/www/discourse/app/jobs/base.rb:123:in `each' /var/www/discourse/app/jobs/base.rb:123:in `perform' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:187:in `execute_job' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:169:in `block (2 levels) in process' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/middleware/chain.rb:128:in `block in invoke' /var/www/discourse/lib/sidekiq/pausable.rb:81:in `call' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/middleware/chain.rb:130:in `block in invoke' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/middleware/chain.rb:133:in `invoke' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:168:in `block in process' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:139:in `block (6 levels) in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/job_retry.rb:98:in `local' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:138:in `block (5 levels) in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq.rb:36:in `block in &lt;module:Sidekiq&gt;' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:134:in `block (4 levels) in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:199:in `stats' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:129:in `block (3 levels) in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/job_logger.rb:8:in `call' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:128:in `block (2 levels) in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/job_retry.rb:73:in `global' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:127:in `block in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/logging.rb:48:in `with_context' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/logging.rb:42:in `with_job_hash_context' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:126:in `dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:167:in `process' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:85:in `process_one' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:73:in `run' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/util.rb:16:in `watchdog' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/util.rb:25:in `block in safe_thread'

and this is the env:

|hostname|talk-app|
|---|---|
|process_id|[443, 452]|
|application_version|dca830cb73371faca8e8497af13064a5bc92b52d|
|current_db|default|
|current_hostname|talk.zabanshenas.com|
|job|Jobs::UpdateGravatar|
|problem_db|default|
|||
|opts||
|user_id|[131679, 131680, 131662, 131675, 131663, 131673, 131672, 131681, 131678, 131676, 131677, 131666, 131664, 131665, 131682, 131674, 131683, 131667, 131684, 131668, 131685, 131686, 131687, 131670, 131669, 131671, 131688, 131689, 131690, 131691, 131692, 131693, 131694, 131695, 131654, 131696, 131697, 131653, 131657, 131655, 131698, 131659, 131656, 131699, 131658, 131652, 131661, 131651, 131660, 131700]|
|avatar_id|[131214, 131215, 131197, 131210, 131198, 131208, 131207, 131216, 131213, 131211, 131212, 131201, 131199, 131200, 131217, 131209, 131218, 131202, 131219, 131203, 131220, 131221, 131222, 131205, 131204, 131206, 131223, 131224, 131225, 131226, 131227, 131228, 131229, 131230, 131189, 131231, 131232, 131188, 131192, 131190, 131233, 131194, 131191, 131234, 131193, 131187, 131196, 131186, 131195, 131235]|
|current_site_id|default|

Yeah we will start eating these errors soon, nothing to worry about.

:wave: @hosna, I’ve updated Matomo Analytics to include instructions on how to install and setup the new “Matomo Analytics” theme component.

Could you give it a try? Please also remember to remove the original custom scripts.

Thank you very much. Works like a charm.