It's not a magnetic type thing.
since you pulled it out. I recomend that you add a bit of grease to the cylinder. The cylinder is what holds your water.
Since you say that it doesn't stay in the tub, the solution is simple.
Turn that little cylinder counter-clock wise, and you will see it that the rod that it's on gets longer. well, experiment. Increase the bar's length, and put it back in, and see if it will hold. Keep increasing the length of the bar until you see that the water holds.
Now wasn't that simple? Generally I charge $45 for something like this

But since this is to help peeps out. Go spend that cash on your family
btw, I'm also a master plumber, been at it for years