Apple uses their own SSD blade drive interface which is not the industry standard M2 blade SSD drives.
As such you can get a replacement Apple original SSD or one of the few direct plug in SSD’s which was designed to be a match. The last option is using an an adapter to force fit an M2 SSD into the system.
There have been issues with these adapters and as the adapter is not 100% complaint to what Apple setup there are features of the interface that are missing which interferes with the systems ability to manage the house cleaning chores SSD’s require.
So while day one and maybe a fair amount of time you won’t notice a problem lurking it can be a sizable issue when it happens!
Now with in a MacBook Pro system access to the SSD is quite easy in an iMac it is not! I strongly recommend sticking with a direct replacement SSD be it Apple or OWC given the amount of work and the reliability issues I’ve seen with M2 drives with these adapters.
You also asked about using the newer Gen 4 PCIe/NVMe drives in this older Mac system. Sadly, it doesn’t make sense to use these Gen 4 drives as they are not able to offer the higher performance in older Gen 3 systems.