animal friend perk works by using the setally function.
generic quest stage 20
; Triggered by the Animal Friend perk, rank 1; make the player friends with everybody in the AnimalFriendFactionSetAlly AnimalFriendFaction PlayerFaction 1 1
becareful thought, that using "RemovePerk" does not revert the effect, player has to manually type in the setally function to revert.
you could set your own quest and have a stage with
if you want a trait that starts with rank 1 of animal friend
you will have make a new quest with stage that has
"Player.Addperk AnimalFriend"
and instead of creating a rank 3 , create another separate perk that relates to animal friend, this is to avoid conflict later on with other mods.