How do I use Matomo tag manager to override page titles?

Hello!

We are using Matomo tag manager to collect information from our Moodle platform. There are some page titles I’d like to override with custom titles in place of the automatically collected page titles.

I know that I can override the page title using the javascript, but I’d prefer to do this in tag manager if possible.

Any advice on how to do this would be greatly appreciated.

Thanks.

You should be able to handle this in Matomo Tag Manager by creating a Custom HTML tag that runs before the pageview is tracked and sets the desired title.

If you only have a few specific Moodle pages, you could use triggers based on the URL or page path and assign a different title for each one. This keeps the changes inside Tag Manager rather than modifying Moodle directly.

Just make sure the custom title is applied before the Matomo pageview tag fires, otherwise the original title may already have been recorded.

Within the Matomo tag you can customize the page title with a variable.

You would still need some JavaScript potentially to set the title or maybe grab it from the data layer or a DOM element. For more about variables please see here: Variables User Guide - Analytics Platform - Matomo

Thanks so much both. Is there somewhere I can find step by step guidance on this? I’m very new to Matomo and am not confident with HTML or Javascript. Or is this something I can email the Matomo support team about?

Hi AlleB, happy to walk you through the variable approach Jason mentioned. Here is a beginner friendly sequence that works well:

  1. In Matomo, open Tag Manager from the top menu and select your container (work in the draft version).
  2. Go to Variables on the left and click Create new variable. Choose the JavaScript Function type and name it something like Custom Page Title.
  3. In the function box, write logic that returns the title you want. Keep it simple to start. A common pattern is: if the page URL contains a certain path, return a fixed label, otherwise return document.title. The function must return a string.
  4. Now open your Matomo Analytics tag (the one that sends the pageview). Find the page title field and replace the default value with your new variable, picked from the variable dropdown.
  5. Publish the container: click Publish at the top right and give the version a name. Nothing changes on the live site until you publish.
  6. Verify: visit one of the Moodle pages yourself, then check Visitors, Real time log in Matomo to confirm the new title shows up.

Two tips that save beginners a headache: the variable is evaluated when the tag fires, so you do not need a separate tag that sets document.title first. And title changes only apply to new visits, old data keeps the old titles.

One more Moodle specific note: Moodle often repeats the site name in titles, so keying your logic off the page URL usually works better than keying off the existing title, since URLs tend to be unique per activity.

If you tell me which pages need overriding and what you want them called, I can help sketch the actual function.

Scott Aerators team appreciates how useful accurate tracking can be when analyzing website performance. When overriding page titles in Matomo Tag Manager, it’s worth checking when the title variable is updated and making sure the tag fires after the correct value is available. Testing the setup with Matomo’s preview and debugging tools can help confirm whether the updated title is being captured as expected.