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 pixelme.me or replug.io

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 domain1.com send traffic to domain2.com
Trigger scripts on browser session on domain1.com before redirect to domain2.com

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

My alternative is add middleware on all outbound links