How to let visitors opt in to third party tracking separately from Matomo?

The Tag Manager automatically loads Meta/Facebook’s Pixel tracking scripts when ‘Facebook Pixel’ tags are triggered. I’ve set up Matomo to not collect any PII. As such it’s not necessary to ask users to opt in to analytics, only for third party tracking, AFAIK. So I want to:

  1. Load Matomo immediately on page load
  2. Only allow Facebook Pixel tags in tag manager to be triggered when the visitor has opted in.

I’m thinking of setting up custom JavaScript to achieve this, but it seems a bit convoluted for what appears to be rather common behavior. After all, almost every website now has a cookie banner! Am I missing something in Matomo/Tag Manager?

I found a German blog post outlining how to base triggers on cookies. I don’t want to base a trigger on a cookie though, because the cookie should change once the visitor opts in to the third party tracking and cookies are only read upon page load, so the tracking would only start on subsequent page views.

What if you just add the pixel tag in case of opt-in (i.e. when the user accepts or its cookie tells the user accepted previously)?

I’m using local storage to track if users have opted in or not. Depending on the value I store there, I show or hide the consent dialog. I guess I will have to push a custom event to Tag Manager in that same script? I was hoping I could do it without custom code. The whole reason I’m using Tag Manager is to avoid that :smiley:

Actually, I’m still not sure how to do it even with custom events!

Tags can be set up conditionally, but only by setting ‘Don’t execute this tag when any of these triggers have been triggered.’ If I want to trigger my Facebook Pixel tags only after a user has opted in, I should send an event for a custom ‘Disable third party tracking’ trigger upon page load, to avoid that the third party tracking is loaded by a tag. But once such a trigger has fired, I can’t undo that. Which means I wouldn’t be able to do any third party tracking until a next page view.

A workaround would be to create triggers specifically for Facebook Pixel. But IMO that defeats the purpose of having a Tag Manager in the first place—it’d be easier to set the Facebook-specific tracking in with Facebook’s business manager. I was hoping to set up my triggers once and use it for Facebook, Google and Matomo Analytics!

  1. You can create a Variable of type Custom JavaScript that could read he value of local storage…
  2. Then you create a trigger of type Window Loaded only triggered when your variable created at step 1 is at the value you want
  3. A second trigger when the user opt-in (e.g. when Trigger-step-2 did not trigger because the user previously opted-out or in case of first visit)
  4. At last your Pixel tag triggered either on Trigger-step-2 or Trigger-step-3.

I don’t think that solves the problem! Because I want triggers that each can be used for both matomo analytics tags and a third party tag. Otherwise I end up with separate sets of triggers for Matomo, Google Ads and Facebook Pixel. Then I may just as well set up those triggers in Facebook’s Event Manager and Google Tag Manager. Having multiple triggers tracking the same events in MTM gets really messy.