There's a few ways it's done.
example a) you search for an item on amazon, logged in as you. It creates a cookie on your machine that is available to ad trackers on sites. You go to twitter (or any other site) with an ad platform, it checks for your cookies, finds the relevant info, and advertises to you based on that cookie.
example b) a connection is made from your IP to amazon associated with searches with xyz product. Henceforth when you go to a site with amazon's hooks into it, the advertising platform reads your IP connecting to that site, and advertises to you. This is how you end up with ads on your (digital) tv for shit you googled, on a separate platform, even through incognito.
There's nuance behind all this, but suffice to say that you have a digital persona that is known to The Internet (tm) and is tracked far and wide, between sites, platforms, countries. Every time you touch the internet in a way it can cross-associate back to your digital persona, it will do so.