The condition the custom actions, on install and uninstall, is easy. Using a merge module is the correct solution.
So, to condition the custom actions correctly you need to do the following:
-- you add the custom actions in the merge module
-- create two searches in the merge module for the Product Code of the two MSI files in which it will be included, or some registry entry that only these applications create
-- lets call the searches PRODUCT_1 and PRODUCT_2
-- for the install custom action set this execution condition: NOT Installed AND (NOT PRODUCT_1) AND (NOT PRODUCT_2)
-- for the uninstall custom action set this execution condition: REMOVE="ALL" AND (PRODUCT_1 XOR PRODUCT_2)