Link rewriting/tracking email clicks and pixel/cookies

What specifically does the link rewriting do?

Looking at options for setting retargetting pixels to mirror functionality of or

When are the circumstances of setting a cookie against a contact?
Is it on mtc javascript of the final destination url load?

Or is their a mautic loading page/browser script between click and final redirect?
Thus 1st domain tracking

If we have relevant content to pages not hosted by ourselves, can we still set scripts/pixels against the contact?
Ie send from send traffic to
Trigger scripts on browser session on before redirect to

Objective is set fb/google retargeting pixels/scripts on all traffic leaving whilst being careful not to trigger spam.

My alternative is add middleware on all outbound links