Let Matomo recognise traffic from Mastodon as coming from Mastodon instead of 'Direct entry'

I am currently involved in launching a new site that uses Matomo for its analytics and that will have an accompanying Twitter and Mastodon feed. At the moment all traffic coming from posts on Twitter is recognised as coming from Twitter and classified under ‘Social network’ but traffic coming from Mastodon is considered a ‘Direct entry’ and not classified under ‘Social network’.

I understand that Twitter traffic comes from twitter.com or t.co whereas Mastodon traffic can come from any domain that runs a Mastodon server. That makes Twitter traffic much easier to identify.

Would it be possible to make Matomo correctly identify Mastodon traffic?

Hi,

There are two issues with detecting Mastodon traffic in Matomo:

On one hand there is no one canonical URL as there is an endless amount of Mastodon domains. Of course one could circumvent this by listing a bunch of the most popular instance domains
(which is in fact what Matomo does)

But the other issue is that Mastodon is intentionally not setting the referrer URL to protect the users privacy.

You can see e.g. that on https://mastodon.social/@LeonardoDiOttio/108765723092232754 the link to this forum post has a rel="noopener noreferrer" attribute. And it is the same for the links from the Mastodon UI.

1 Like

OK, thanks. There was some discussion over on Mastodon already about how the referer is disabled.

Is that the reason that the list you pointed at is actually not consulted as Matomo never gets to know the URL? In our situation I see traffic not being recognised that I know is coming from one of those domains.

If a HTTP referer would be passed on, perhaps with the URL stripped but with a header such as “source=mastodon” added, would that help?

P.S. For what it’s worth, there are a number of global top 15 Mastodon servers (https://mastodon.fediverse.observer/list) missing in that list, probably because it was last updated two years ago. The following are all fairly big now:
baraag.net
mastodon.online
mstdn.social
brighteon.social
mas.to
alive.bar
mastodon.top

1 Like

Does anyone know this? If a custom HTTP Request Header were to passed on by the Mastodon servers, web clients or apps, for example “Source: Mastodon”, could Matomo easily be extended to look for those headers and classify that traffic as such?

We are also interested in this feature and struggling to track Fediverse traffic. We are not running our own instance but have company accounts that post content, and would like to measure interactions from that content.

Hi, same question, of course. I tried to use UTM values, but after a while, they might have been killed somewhere as they don’t work anymore, although I know I get some traffic…
I found this info (on jort[.]link which has nothing to do with the problem here) but that might be an approach although I have no idea 1 - if it works 2 - where/how to manage this in Matomo:
=> testing the User Agent with Apache:

BrowserMatch "^(http\.rb/\S+\s\(Mastodon|Pleroma\s|Akkoma\s|Misskey/|gotosocial)" fediverse_instance

#<LocationMatch ^/whatever>
<If "reqenv('fediverse_instance')">
xxxx
</If>
#</LocationMatch>

I’m no dev and not smart enough to be sure this would fit the purpose, just asking if detecting the UserAgent might be a solution…
Sincerely
DJM

Hi @cybeardjm, @nils, @LeoNeo
I suggest you use the campaign parameters:

Or else the Marketing Campaigns Reporting plugin for more details:

Hi, thx. But as explained above, the tracking of MTM/UTM parameters has stopped working from Mastodon links… Are URLs fully “cleaned” now? I can’t say.
But they’ve worked for a few months and then didn’t get this info anymore…
Sincerely
DJM

When you have the posibillity to set a HTTP Header in your mastodon instance, and you know to match this HTTP Header with PHP or JavaScript, you can use this information to set the referrer manually with:

_paq.push(['setReferrerUrl', ReferrerUrl]);

More infos here:
https://developer.matomo.org/guides/spa-tracking

I’m not sure if ReferrerUrl has to be a string or an object.
When a Object, then use:

var ReferrerUrl = new URL(ReferrerUrl);

or similar.

Consider: When you set a HTTP Header in your mastodon instance and match this as a Referrer, then you break the idea of mastodons rel="noopener noreferrer" and the mastodons idea of users privacy. It is only for you, then use a really own HTTP Header.

Piuktpa: xgHu873Ujez63

I don’t think this could ever work. It’s not the Mastodon server that the visit to your site is coming from (perhaps just once, to generate a link preview), the Mastodon server generates a post that tells a visitor’s browser the link to your site. It’s then the visitor’s browser that goes to your site with the user agent of their browser, not that of a Fediverse server.

There’s no way of knowing that the visitor using Safari X.Y.Z. that’s visiting your site got that link from Mastodon because, for privacy reasons, Mastodon servers strip out anything that’s not strictly necessary. They also don’t pass on referer URLs for the same reason.

This could work, if you run your own Mastodon server or the service that hosts it for you allows you to tweak to such an extent.

Generally I hope that one day the developers of Mastodon can be persuaded to push out a generic HTTP header with every link that doesn’t perhaps give the full referring URL but at least says source=mastodon or something so developers of analytics packages can at least use that to get a basic idea where all the traffic came from. It would be in Mastodon’s interest too as currently a site owner would have no idea that their Mastodon posts generate such traction.

Perhaps it’s even a good strategy to not only try this with Mastodon but also with Calckey, Lemmy, KBin, Pixelfed and other Fediverse networks. If one of them implements a ‘source’ HTTP header and it works well than others might follow.

2 Likes

thx, I understand and agree fully. I’m experimenting with Mastodon + Calckey + Pixelfed (besides being a heavy user) and indeed, I know some of the “direct access” posts are in fact from these test posts, which is “frustrating”… On Mastodon, Gargron is a fierce opponent to such “openings” (as others). But if (and I said IF) Meta’s Threads joins the Fediverse, users might start requestinq some (more) data… who knows.
Thx for your comment.
Sincerely
DJM

PS: my sites are indeed “fedified”, WP+ActivityPub blogs… but it doesn’t help here…

1 Like

If you also use Calckey and Pixelfed then it’s worth a shot working with them to see if they can find a way to at least provide some extra data to analytics tools. Even if it’s just a fairly anonymous source=pixelfed or something.

It would be great for the visibility of platforms such as Pixelfed or Calckey if site owners everywhere started seeing Pixelfed or Calckey traffic in their analytics.

OK, will do.
I tested by adding Calckey in System/Manage Social Networks with at least calckey.social (there are more than 500 instances now) and it works.
Will try with Pixelfed…
And then there are many others: Pleroma, Akkoma, Peertube…
Sincerely
DJM

That suggests that Calckey doesn’t strip the referer. Can you see that in the server logs too?

Ideally Matomo wouldn’t have to rely on the referer header because it would require Matomo to come with a constantly updated list of known Calckey servers. I believe PixelFed even has a requirement of no more than 1000 users per server to more or less force the PixelFed network to spread across many servers, which in the long run would require pretty big lists to be maintained in Matomo.

In an ideal world Mastodon, PixelFed, PeerTube, Calckey, Lemmy, KBin, Akkoma, Owncast, GoToSocial, Pleroma, HomeTown and other Fediverse servers would be able to at least send a source identifier (source=calckey) with their referer headers. That has little to no privacy implications for users but would greatly help analytics and the visibility of those social networks.