With the trend towards larger group housing systems in farm animals, it becomes increasingly important to be able to monitor the behaviour and welfare of individual animals housed in groups. Here we present TrackLab 2, a new software package and integrated system for the acquisition and analysis of location, activity and social behaviour of group-housed animals. It is the successor of TrackLab 1, which has been used in a wide variety of livestock research projects on cattle, pigs, poultry and sheep. TrackLab 2 offers several functional and technical innovations relative to its predecessor: the movement analysis and behaviour assessment routines are compatible with both indoor (ultra-wideband, UWB) as well as outdoor (GPS) tracking; the tracking hardware is customized for animals of different sizes; the accuracy achieved with UWB-based localization allows for analysis of behaviours that cannot be achieved with other positioning techniques (e.g. RFID, WiFi): social behaviour/network analysis, accurate activity classication and place-preference analysis; the analysis includes results per individual animal as well as statistics for experimental groups; it has a distributed and scalable client-server architecture, supporting multiple concurrent users and measurements at multiple locations (e.g. barns). Practical trials and validation studies with dairy cattle and poultry have demonstrated the performance of the system under demanding conditions, during prolonged tracking of large numbers of animals, both in barns and in the eld. We will discuss the ndings and their implications for practical application of the system. We hope that TrackLab 2 will contribute to livestock research (behavioural phenotyping, testing different diets, housing and management systems) as well as precision livestock farming (monitoring individual animal health and welfare).