Combining Tag Manager and JavaScript tracker

I feel absolutely stupid, but I’ve read the documentation, watched the video course, searched the forums, and I can not find this out:

Is the Matomo Tag Manager a replacement for the JavaScript tracker, or are they both included on the page?

1 Like

Matomo Tag is a container, typically you can use it for JavaScript tracker but also much more.

If you use Matomo On Primise, when you create a website, normally Matomo generate also a container with:

  • variable for Matomo Configuration
  • trigger (Pageview)
  • tag for Matomo Analytics

You just need to publish the container.

At this point you can choose whether to use in your page normal script or tag script. Only one fo this. In this case they both do the same thing.

I know the tag manager is a container for scripts (“tags”). However, the documentation does not mention one word about if you should create a tag for measuring pageviews, or if you should continue using the JavaScript tracker to do that. As creating a tag for measuring pageviews would be the first thing anybody does with tag manager, and that is not discussed at all in the documentation, I’m wondering if Matomo is using a different convention.

We are using Matomo on-premise, but creating a site in Matomo did not create any variable, trigger or tag. When I enabled Tag Manager, is was completely empty.

Hi @pbb72

With MTM, it is better to track the most with MTM tags…
If you don’t need the Page view event, at least initialize the tracking with Initialize tag:

Then if in some case you can not tag with MTM, you can use _paq and standard JavaScript tracking for some events… (but be sure initialization has been made previously via Page View or Initialize tag)

Yes, you have to configure the Tag Manager, as it can’t guess what you wants to do: you can use the MTM to track into another Matomo, or even several Matomo at the same time!

Thanks for the reply Philippe. It’s sad this basic information is not included in the documentation.

For documentation issues (if you think doc is incomplete), you can create a documentation issue there, with the list of documentation you read that did not helped you to achieve your needs…

Thanks, I was actually looking for a way to report documentation requests!

Surprise! I now see Matomo does auromatically create a container. It just does NOT do this for your first site. Any additional sites do get an automatic container!

1 Like

Github ticket on this subject:

Thanks @pbb72 for the report :+1:

The matomo slang is not really referenced to the web standards, but a little bit. Its like a newspeak.

A HTML “tag” is a HTML element reference. Whit a “tag” you can find a element. This needs a little bit JavaScript understanding.

Here a list of all HTML tags:

A HTML element is in the most cases a (JavaScript) object. You can detect it via: document.getElementsByTagName("script")

script” is a HTML element tag name.

Matomo use the script tag multiple. First, for putting the tracking “code” in your website. Second, this tracking “code” load the matomo JavaScript script (matomo.js or [Tag Manager] example: keieemhjehbeemejeenjdkdhnebemb.js) in the website.

In this tracking code there is a createElement('script') and further a getElementsByTagName('script'), to load the created element as “parentNode” of this, also above of this.

The difference between default JavaScript tracking with the matomo.js and the Matomo Tag Manager is, that the Tag Manager load not the matomo.js, but a individual (example) keieemhjehbeemejeenjdkdhnebemb.js, that is individual generated in the reference of the settings in the matomo backend.

Let me join with another novice question related to this:

If I insert a Matomo Analytics snippet to my website, it tracks things fine - actually brilliant!.
And if I add a MTM snippet, I can also use triggers and stuff.

If I then disable the Analytics snippet, the tracking stops.

So what is the right things to do: Do I need both snippets or can I combine MTM and Analytics in one?

So you’re saying that you have both the Matomo JS code and the Matomo tagmanager code installed, and everything works fine. Then when you remove the Matomo JS code it doesn’t track anything?

Are you sure there is a pageview tag in your tagmanager setup?

Well, I have now: Added a pageview tag. Didn’t think about that and it didn’t came obvioud out of the documentation.