Cookie consent works with Matomo Analytics, but adding _paq.push(['requireConsent']); to the matamo a/b script does not prevent it from adding local storage

According to http dot dot slash slash eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=CELEX:32002L0058:en:HTML, I can add my consent management code to my site, which will defer cookies until user consent. This can be done by adding: _paq.push([‘requireConsent’]); before the Matomo scripts.

This works fine for Matomo Analytics which is integrated to my site via MTM.

However, if I add the line _paq.push([‘requireConsent’]); to my Matomo a/b testing code, like this:

<!-- Matomo A/B Test -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['requireConsent']);
_paq.push(['AbTesting::create', {
    name: 'NameOfMyABTest',
    percentage: 100,
...

I would expect this to prevent Matomo A/B testing from storing a local storage element (according to my understanding of privacy laws, local storage elements should be treated as cookies when it comes to consent) called MatomoAbTesting until the user accepts cookies. However this is not the case: when I quit and restart Chrome, open my site in a new incognito window,

    1. I see my cookie popup as expected
    1. There are no Matomo Analytics cookies
    1. Matomo A/B adds a local storate element called MatomoAbTesting
    1. I accept my cookies in the popup
    1. Matomo Analytics adds cookies such as _pk_id.31.0ddf

My problem here is number 3. I would expect that, because I added _paq.push([‘requireConsent’]); to my matomo a/b code, point 3 above would happen after, not before, point 4.

My question is: Consent management works fine with Matomo Analytics; how to get it to work with Matomo A/B testing.

Related issue: https dot dot slash slash forum dot matomo dot org/t/a-b-testing-and-dsgvo/45063