Actually, this way the unit wold gain mana everytime it deals damage with anything: hit, ability, etc, which wouldn't actually work as a "Mana steal" thing or something.
You have to detect the damage source actually hit the target unit.
What I would do?
On event "A unit is attacked" save "True" on the attacked unit index or id. That works for detecting the unit began the attack animation of a unit. To add the mana only when the unit hits, you need this boolean to be "True". If the unit is given any order (target, no target, point), and boolean is "True" you set the boolean to False, just in case a player tries to spam the small time gap between the "Attack" and the Damage. When damage is received the boolean is also set to false.
It's a pain in the ass tough for ranged unit, which could receive an order while the missile is still on the air, or could have more than 1 missile in the air.
You could also do the ooposite: Set "True" when the unit is casting to prevent attack bonuses apply, and set to false when the unit is not casting anymore.