If a dead creature which does not have flowing blood falls into some water, it does not make the water impure. The scholars say this includes a gecko and anything smaller than it.
The gecko came to the fire in which Sayyiduna Ibrahim had been cast and blew upon it, trying to increase its ferocity. Obviously this had no effect on the fire but due to its bad intention it is recommended to kill geckos.
The frog on the other hand filled its mouth with water and put it on the fire, trying to extinguish it. Obviously this had no effect on the fire but due to its good intention and its respect for Ibrahim it is impermissible to kill frogs.
Likewise it is impermissible to kill spiders, since the spider weaved its web over the mouth of the cave in which the Prophet ﷺ was sheltering.
All these creatures boarded the Ark of Nuh. The scholars say that if someone is in a place where there are snakes, scorpions or other harmful creatures he should recite the following verse and they will not harm him:
سَلَامٌ عَلَى نُوحٍ فِي الْعَالَمِينَ
‘Peace be upon Nuh among all beings.’
This is because those animals took a covenant with Nuh not to harm anyone when they boarded the Ark.
Extracts from Sayyidi Habib Umar bin Hafiz ‘s classes on the rulings and etiquettes of purification from Habib Abdullah bin Husayn Balfaqih’s “Kifayat al-Raghib” in Shafi fiqh.