This mod contains code that defines a lua event that fires off when a unit is created. The event does not fire when a unit is upgraded. The lua event provides the information you need to get the owning player object and the unit object.
More info.
More info.