Generate mattes for displaced blended materials?

I have a blend material with displacement. Only two materials, with the overlaid material corresponding to the displaced area. I would like to generate a matte for this material so I can color correct in post if needed, but cannot figure out how to do this with my current shader network. Since displacement is calculated at shading group level, adding a material ID and using a multimatte doesn’t work as this is upstream from the displacement. Obviously adding an ID to the final SG will generate a matte for the entire shader and won’t differentiate between the displaced and base materials.

What would be the correct workflow for generating such a matte? Do I have to do this on another render layer?

This works for me, or maybe I have misunderstood the issue. Check this scene.

No, you understood correctly and indeed it does work. So either I didn’t set up my test properly or didn’t see what I thought I was seeing in the results. User error as always. Thanks!