How to add a free gift to the cart using a LineItem Script?

The script editor is primarily used for discounting the existing items in your users cart. It does not have the ability to add new products to cart on its own. You’d need to use JavaScript in your theme to add the product to cart and then use some sort of identifier (maybe a line item property) that when seen by your script will change it to a $0 product. Not the safest thing in the world, but it’ll get the job done.

*“not the safest” meaning someone who understands Shopify themes might be able to figure out the line item property and they can use JS in the console to add the product to cart and get it free. So you’ll have to setup some strict logic rules in your script to only apply the discount in very specific circumstances if you don’t want people to potentially abuse the free product logic.