I'm able to get this to work but is it possible to automatically add the free item Y to your cart when you add X?
The customer would have to add Y manually which is an issue
I think you need to add app bundle. Bundle app working like buy X and get Y free. please check this link.
If helpful then please Like and Accept Solution.Shopify theme and app developer.Skype: live:hardikradadiya355Thanks
I've not tried this method but How about set Y free (I mean set its price is $0) then when your customers buy X, they will get Y for free.
For details, you can read here.
Better to create a custom app