Problems with <link rel="preload"> tip from Matomo blog

Hi, on the following page there is advice on how to make the Matomo tracker load faster:

I want to implement the “Preload resource” tip there, by adding the following provided <link> element:

<link rel="preload" href="" onload="embedTracker()" type="script" crossorigin>

In my case, I’m using /js/index.php for my tracking code, but I don’t think that should be a problem.

However, when I added the above <link> element (obviously adjusted to use my own Matomo URL), the Chrome console gave me three different errors:

First error:

<link rel=preload> must have a valid ‘as’ value

This can be fixed by adding the value as="script".

Second error:

<link rel=preload> has an unsupported ‘type’ value

This can be fixed by removing the value type="script" as it isn’t needed at all.

Third error:

Uncaught ReferenceError: embedTracker is not defined at HTMLLinkElement.onload ((index):13)

I don’t know how to fix this. It looks like there is a problem with the onload="embedTracker()" value, but I don’t know what the problem is, or what it ought to say.

Can someone kindly update the info on the Matomo blog page for this tip, with regards to the ‘as’ and ‘type’ values in the example element there?

And can someone kindly tell me how to fix the third error with the embedTracker value? (That should probably be updated on the blog page too).


1 Like