First, check the strike and magnet face to see if something is interfering with a flat fit.
Second, the strike must be allowed to float around the rubber washer stack which must be on the strike center mounting screw. The magnet then pulls it into flat alignment. If the strike is mounted too rigidly, proper alignment can't occur and the lock won't hold. To correct the problem, try loosening the strike mounting screw to see if the lock then holds properly.
Third, if you are operating the lock on AC instead of DC or on half wave rectified DC (transformer + single diode) the lock won't hold. Half wave rectified DC is unacceptable; you must, at a minimum, employ full wave rectified DC (transformer + bridge).