[opt-out] How to make opt-out work in Grav CMS?

The recommendations I got say to place the Matomo opt-out code directly under the relevant section in the GDPR web page.
In a webpage running under the Grav CMS I tried that, both with the new Matomo Tracker Code for the opt-out and the “own” code using the proposed one without any modifications.
In both cases, I get the error: “TypeError - Unsupported operand types: null / string”.
Matomo is v4.14.2, Grav is v1.7.41.2.
Any tips, what I could do to overcome this problem?