Typically animals will spot invisibles that get within one square of them, unpredictably invisibles will be spotted from further away. Rarely, an invisible may successfully pass unseen even within 1 square of an animal or other friendly unit.
So maybe don't use just one animal.
I most commonly use a few 1x1 pastures each with an animal I don't mind losing right in the middle of a 3x wide path, so dwarves and other friendlies pass to either side of the beast. This ensures that any invisibles must pass within 1 square of the beast and thus have the best chance of being spotted; with a few beasts spread out this way the odds stack nicely in favor of discovery.
I typically use a beast pastured by a single fortification overlooking the entrance of the path, with a good shielded flight region and a fairly long distance between the pasture and where most of my dwarves usually are. This one's there as bait, to be shot at by any invisible archers that might be heading in. The enemy reveals itself to fire; the game pauses; the beast attempts to auto-flee and especially if the entrance to its pasture requires a change of z level, the beast almost always is out of way by the time the arrow reaches that pasture. A dwarf starts the long (and thus safe) walk to return the critter to its pasture; the beast continues to run back towards the fortress (and probably towards the dwarf trying to catch it), and my defenses of the day go into play. Another archer-bait beastie or two may be a little further in, just in case there were several archer ambush squads and another's heading in as the bait beast is being lead back to position.
Grates/bars/fortifications, they do not stop arrows, so if your critter is trapped inside an area that can be seen through them, it's not going to survive meeting an archer.