SMF plugin Global Headers and Footers breaks Matomo tracking code

Hi Friends,
3 weeks ago, after a few years of steady growth, I’m suddenly seeing site visits going down significantly (approx 75% of usual). Yes, we’ve had a “down” week once in a while, but 3 in a row, going steadily downward - no. I can’t think of anything to explain this, so I wanted to ask if anyone else might have noticed something like this.

Could there be some internet phenomenon behind this?

I noticed another topic in this board, about a Firefox feature and discussing whether it would block Matomo (Firefox Anti-tracking). I was trying to find the list of sites that it blocks, but I couldn’t find it. However, Matomo does not report any significant change in Firefox use for browsing my site. (If Ff was blocking my site, it seems l like I would see a drop for Firefox visits, relative to other browsers.)

Could this or some other similar software be behind this? Or is anyone aware of something else?

Let me know if you need some more info to help answer this. I’m not the most tech-savvy person around, and I’m not sure what other info might be needed to research this.

Fyi, my site is a portal style of forum (SMF) which provides support for an open source graphics program. It’s not really social in nature, other than being a forum…I mean, we don’t discuss the weather or BFFs or “likes” or that kind of thing- it’s only for helping people learn how to use a graphics program. And nothing has happened that the community is aware of, that would suddenly change overall interest in the program.

Thanks for any comments or insights to how I can research this more.

My site homepage: Welcome to Inkscape Community!
Forum index: Inkscape Community - Index

Hi,

You can find the links to the blocklists here:
Firefox Anti-tracking - #2 by Lukas

But as you noticed, this has nothing to do with Adblockers (after all you have also renamed piwik.php).

Next idea was an error with the HTTPS config.

https://www.ssllabs.com/ssltest/analyze.html?d=inkscapecommunity.com

But while your server isn’t configured to the latests security, that would only mean more visitors in Matomo as you also support ancient browsers. (But you should still upgrade this in the interest of your visitors)

Next I noticed that my browser only makes a request to https://inkscapecommunity.com/stats/pi.php?idsite=1&rec=1 and not the piwik.js.

And this is the way to find out the real issue. Take a look at your tracking code:

<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push([&#39;trackPageView&#39;]);
  _paq.push([&#39;enableLinkTracking&#39;]);
  (function() {
    var u="//inkscapecommunity.com/stats/";
    _paq.push([&#39;setTrackerUrl&#39;, u+&#39;pi.php&#39;]);
    _paq.push([&#39;setSiteId&#39;, 1]);
    var d=document, g=d.createElement(&#39;script&#39;), s=d.getElementsByTagName(&#39;script&#39;)[0];
    g.type=&#39;text/javascript&#39;; g.async=true; g.defer=true; g.src=u+&#39;pi.js&#39;; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript><p><img src="//inkscapecommunity.com/stats/pi.php?idsite=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->

Your Javascript is invalid as all quotes have been replaced with &#39; and therefore didn’t do anything. All data you received was from the image tracker (that is only a fallback if JS is disabled and is very inaccurate).

<!-- Piwik Image Tracker-->
<img src="https://inkscapecommunity.com/stats/pi.php?idsite=1&rec=1" style="border:0" alt="" />
<!-- End Piwik -->

So to fix this, repair your Javascript and then kick out the Image Tracker block as it would send the data a second time to Matomo doubling your requests. (And you already have the image tracker above in a <noscript>.

Thanks for your comments :slightly_smiling_face:

Oh, someone showed me that trick, so that we don’t have to deal with allowing the script in NoScript (Firefox addon). But I don’t clearly understand how it works. I only vaguely understand it. But it’s been like that for years, and not a recent change.

For the SSL certificate, I’m not sure if I have any control over that. That comes from my host, but I can look into it. Is that something that would have recently changed? Or I should say “could have recently changed”.

Hhmm yeah, when did that forward secrecy thing happen?

Your Javascript is invalid as all quotes have been replaced with &#39; and therefore didn’t do anything.

Hhm, well I copied the tracking code right out of the Website > Tracking Code page. And I have not changed it recently. Is there some way it could have been changed without my input?

Well when I look at the code, in the mechanism which puts it on every page (which is a mod for the SMF forum (called Global Header/Footer) it’s correctly showing the single quote, and not &#39;. I wonder why you see the &#39; ?

Oh ok, when I go to View > Page Source, it’s also showing &#39; instead of single quotes. Maybe it’s somehow that…what program is that that’s displaying the source code? Maybe it can’t display single quotes for some reason? Is that a brower page…it looks like some kind of special browser page.

I can’t figure out how to look at the page source with another program, such as a text editor. Hmmm… Weird, when I locate the tracking code using the Firefox developer tools, it also shows the unicode, instead of the single quote.

There must be some explanation for that? Look at the code on your site. It looks to me like thist switch from single quote to unicode must be related to the browser??

Although…if the entire code had become invalid, then I would think my numbers would have dropped at least 75%. But it’s only dropped approx 20 to 25%. (75% of usual means a 25% drop) (yeah, I’m old - I guess the youngsters don’t use that kind of mathematical expression anymore…?)

Anyway, I guess if only the image tracking part had died, this might be an expected drop. (at least to my way of thinking) But if the js code wasn’t working, honestly I’d probably drop to nearly nothing.

While I am curious what causes the unicode switch, I’m not sure if that would explain this problem. What do you think about that unicode?

Thanks again!

Hi, one side effect would be avoiding ad-blockers that block *piwik.php. But that isn’t the issue here.

Hi, that would need to be changed by your host. Probably it was secure many years ago when it was configured but things changed since then.

I found someone who reported the exact same error with the plugin many years ago:

So I’d just install the latest version of the plugin as one of the updates afterwards will have fixed it: https://custom.simplemachines.org/mods/index.php?mod=351

It would have, but by chance you have accidentally posted the image tracking part a second time in the tracking code. Therefore every visit would have been reported twice, but as the normal tracking is broken, you still saw the less accurate image tracking data.

Wow, I’m impressed, and very much appreciate your research about this!

You’re right, I do have the image tracking code in there twice. I think that’s because the tracking code page, in earlier versions, gave the js and non-js code separately. I replaced the js code maybe a year or 2 ago, but I only just now realized that it now includes the non-js/image tracking code.

So it wasn’t that I added the image tracking a 2nd time. It’s that I didn’t realize it was attached to the js code, in later versions.

But that happened quite some time ago, and not coincidentally with my current problem.

Regarding the Global Headers/Footers mod, I do have the current version. So if the code really is broken, it’s been broken for the whole time I’ve been using Piwik/Matomo.

But how do we know that the single quote is getting changed to unicode (making the Matomo code malfunction), and that that special browser page which displays the source code just can’t display a single quote?

Because when I open the Global Header/Footers mod and display the place where I’ve entered the Matomo code, and then view the source, it shows the single quote changed to unicode there. So I think maybe it just can’t display a single quote for some reason. It seems like I’ve seen other programs show unicode if it can’t display a symbol, although as I said from the start, I’m not very tech-savvy.

Isn’t there some way to display the source code of a webpage without using the browser?

Because it’s hard to believe the js code has never been working! I guess there’s no way to look at the Visitor Log, and find out which entry was gathered via which code?

Since I don’t clearly understand those 3 or 4 messages in the SMF forum which you found, and since it’s not clear whether the suggested bug report was ever made, I’m going to make a new post about it, and try to learn more about it.

Thanks again for your time and attention!

Edit
I just realized – now that I’ve removed the extra non-js code. If my numbers drop exactly in half, then that would probably indicate that the js code is not working. Right?

Or, I could remove the non-js code entirely, and if it goes down to zero, that would be hard evidence as well. Right?

Hi,

The reason why I am pretty sure that it is not a display error, but the JS doesn’t get executed, is that the following error occurs in the JS console when it comes across the first &#39;:

grafik

So I’d recommend to look for another way to modify the header.

Maybe there is another plugin that does the same, but without the bug.

Or you do it yourself and modify the theme. If I understand it correctly it should be the
Themes/[your theme]/index.template.php file.

I’m probably not smart enough to put the code on every page, without the help of a mod. But maybe something will come of my post to SMF support (which I haven’t had a chance to make yet, but will do shortly).

Thinking of my previous “brainstorm” about visits getting cut in half after removing the extra non-js code, now I’m confused again.

Because if I was getting 2 visits recorded for every one visit, why do I so often show only one visit, in the Real Time Visitor Count widget. If I was always getting “2 for 1” then I would always have only even numbers in the Real Time widget. But I get 1s and 2s and 3s and 4s and 5s.

Anyway, I’ll let you know what happens with the SMF post.

Thanks again.

Edit
Just thought of a realistic answer for the non-even numbered visits, more later.

Ok, I don’t have an answer from SMF yet. But since I took out what I thought was a 2nd image tracking code, my visits did drop to nearly zero. So apparently I did only have it on there once.

The problem is that I can’t figure out how to put it back. It’s not displayed on my tracking code page. See the attached screenshot.

So how can I get back the old image tracking code?

Hi,

Just scroll a bit to the top :slightly_smiling_face:

When I scroll a bit to the top, I see the code which becomes broken later - only the js code. I don’t have any image tracking or non-js code. This is all I have:

<!-- 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="//inkscapecommunity.com/stats/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', '1']);
    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 -->

If I check the box that says “Track users with javascript disabled”, I have this code

<!-- 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="//inkscapecommunity.com/stats/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', '1']);
    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>
<noscript><p><img src="//inkscapecommunity.com/stats/piwik.php?idsite=1&amp;rec=1" style="border:0;" alt="" /></p></noscript>
<!-- End Matomo Code -->

When I only had that code applied to every page, that’s when my visit count went to almost zero. So I absolutely need the image tracking code, by itself, and not combined with the js code. At least for now, until I can figure out what’s causing the single quote not to show up properly.

Is that my proper image tracking code that you have at the bottom of your message?

Yes, I copied it from your website when I posted it (that’s what I meant with scroll to the top)

Oh, sorry about that. I missed it.

Meanwhile, I just checked on my SMF post, where there’s some cryptic comment about someone having fixed something, but with no link to any updated software. So now waiting for clarification.

Thanks again!

Oops, I was wrong there too. They just posted a new version, so I’ll try that.

Ok, good news!

They did fix that mod, just this weekend, and not when it was reported in the message you found…yikes, which was 5 years ago, just before I started my site.

I think I’m getting realistic analytics now, for the first time ever!

Anyway, the fixed mod is installed, and the source code is showing single quotes, as expected.

So while I still have not, and now probably will never figure out why my numbers dipped over the last month – at least now I’ll be getting correct numbers!

There’s just one question I still have…well, maybe 2.

Why is there image tracking code sort of tacked on to the js code, which does not seem to work? Or was it just not working because it’s connected with the bad code which didn’t show the single quotes? Because it doesn’t have single quotes itself, so it seems like it should have worked. Should I still keep the separate image tracking code? Or if I drop it now, will the image tracking code that’s connected to the js code work, now?

Also, would it be ok if I post a message (in whatever is the most appropriate place) in this forum, announcing this issue, so that other SMF users can find it? This seems a little too important to keep to myself. I mean, who knows – I started my site 5 years ago, and never had correct results. Who knows how many other SMF users have this problem but don’t know it?

Thanks again for all your help!

Edit
Holy crap! I just checked my dashboard, and see 10 real time visitors! I’ve never seen more than 4 before. And this is a Sunday, which typically Sat or Sun are my slowest days.

Hi,

Okay, one more thing until everything is fixed: You need to remove the separate image tracker and keep the one that is sort of tacked on to the js code. (This one is wrapped in a <noscript>, which means that the image will only load if JavaScript is completely disabled in the browser) Otherwise you will now get everything twice.

I am not sure how many people are having this specific combination of issues. But I have renamed this thead, so it can be found easier.

Funfact, the whole bug that caused the plugin to fail, was this one missing variable:

diff --git a/b/resources-2.0/smfhacks_templates/global-hf.template.php b/a/resources-2.0/smfhacks_templates/global-hf.template.php
index d330a62..ddc98e1 100644
--- a/b/resources-2.0/smfhacks_templates/global-hf.template.php
+++ b/a/resources-2.0/smfhacks_templates/global-hf.template.php
@@ -4,14 +4,14 @@
  *
  * @file ./smfhacks_templates/global-hf.template.php
  * @author SMFHacks <http://www.smfhacks.com/>
- * @copyright SMFHacks.com Team, 2012
+ * @copyright SMFHacks.com Team, 2018
  *
  * @version 2.0.1
  */
 
 function template_global_hf_admin()
 {
-       global $context, $settings, $scripturl, $txt, $global_hf, $modSettings;
+       global $context, $settings, $scripturl, $txt, $global_hf, $modSettings, $smcFunc;
        if (isset($_GET['success']) && $_GET['success'] == 'saved')
        {
                echo '

Oh, thanks for changing the title and moving to a different board. That should do the job of making the info available, if anyone wants it.

Ok, I will now delete the extra image tracking code, again. Yes, I do see the double entries already. So I’ll do that right away.

Now I got curious about my gallery, which is not really part of SMF. It has its own global footer mod. Here’s the source code for that, which appears to have replaced the single quotes with double quotes. Is that code broken as well? (I don’t understand coding enough to see what was wrong with the SMF Global Header/Footer mod, or have a clue about this CPG code.)

<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
  _paq.push(["setCookieDomain", "*.inkscapecommunity.com"]);
  _paq.push(["setDomains", ["*.inkscapecommunity.com"]]);
  _paq.push(["trackPageView"]);
  _paq.push(["enableLinkTracking"]);

  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "://inkscapecommunity.com/stats/";
    _paq.push(["setTrackerUrl", u+"pi.php"]);
    _paq.push(["setSiteId", "1"]);
    var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
    g.defer=true; g.async=true; g.src=u+"pi.js"; s.parentNode.insertBefore(g,s);
  })();
</script>
<img src="https://inkscapecommunity.com/stats/pi.php?idsite=1&rec=1" style="border:0" alt="" />

Should I report this to the CPG folks?

Thanks again.

Edit
Maybe that mod has an upgrade. I’ll check.

Hi,

In the gallery you should also remove the image tracker and then you should be finished.

Actually I can’t remember how I put the Piwik code in the gallery. There doesn’t seem to be a mod for global footers. I’ve just been trying to figure it out. (I should probably get out of the forum business, since my memory is getting so bad!)

From what I see in the source code though, it doesn’t look like the image tracking code is in there twice. But it’s the “old” image tracking code, which doesn’t default in case the visitor isn’t using js. It essentially doubles over the js tracking.

If I can remember how I did it, I’ll update it with the code which Matomo now provides.

Maybe I edited a theme file?

Well anyway, I’ll figure it out.

Thanks again!

Edit
I don’t know how to choose which message solved the problem. It was all drawn out with bits and pieces here and there. You’re welcome to choose, if that’s possible.

1 Like