Most people cover the glass with some cling film and punch a few holes through, but it will work fine without. The main advantage of the film is that the liquid won't evaporate away, and the trap will be good for a couple of weeks.
To be slightly more specific, the soap changes the surface-tension of the liquid, causing it to, er, schlorp onto the insect in a way it does not expect.
That reminds me of JBS Haldane's classic essay "On Being The Right Size":
> An insect, therefore, is not afraid of gravity [...] But there is a force which is as formidable to an insect as gravitation to a mammal. This is surface tension. [...]
> An insect going for a drink is in a great danger as man leaning out over a precipice in search of food. If it once falls into the grip of the surface tension of the water -that is to say, gets wet - it is likely to remain so until it downs. A few insects, such as water-beetles, contrive to be unwettable; the majority keep well away from their drink by means of a long proboscis.
I saw the other day on Thingiverse a fruit fly trap. Example: [1] (it wasn't this one, and there are many other ones, but this one resembles the looks of the paper version). But I think its OK to make such a trap a few times a year during summer (when they're abundant here). You also wanna get rid of them ASAP, as they attract bigger flies.
Place that on the kitchen counter near where the flies congregate. They will follow the scent down the hole where they will be mostly trapped and if they touch the liquid, they will sink and drown as the soap removed the surface tension.