How to use setUserId GDPR compliant

Hi,

I would like to use setUserId to merge matomo with a user base that I have. However, I would like to do that GDPR compliant.

Thus, I would like to link both data sets only if rememberConsentGiven or rememberCookieConsentGiven (preferably both) was executed.

How would I do/check that?

Kind regards

EDIT: Related/additionally: How can I let the tag manager create a container only if consent was given? I checked Require Cookie Consent in the Matomo Configuration container configuration variable.

You can check the status of consent like below.

var consent;
var coookies;
    _paq.push([ function() {
    consent = this.hasConsent();
    cookies = this.hasCookies();
    console.log(consent);
    console.log(cookies);
}])

Then you could use a conditional statement whether to set the user ID or not. For the tag manager did you mean trigger or container?

Thanks to @Joshua123 for the tip.

Thanks for your reply. This is very helpful!

I meant a trigger that I can use to control whether to inject a tag or not. Sorry for the confusion.