Can Camera Tracking and Masking be done together?

As you can see in the image, I am using Cam Tracking to place a sticker on the wall.
But the subject moves in front on, and off, so I’ll need to animate a mask for the sticker.
Can this be done both at once? Or do I have to render the Cam Tracking first?

layout

It can be done at once, mask your render in compositor and combine with background video. But I’d suggest rendering first and doing masking in comp using rendered image sequence after, because this way you can refine your mask without need for re-rendering your 3d scene.