Social learning has been documented in a wide diversity of animals. In free-living animals, however, it has been difficult to discern whether animals learn socially by observing other group members or asocially by acquiring a new behaviour independently. We addressed this challenge by developing network-based diffusion analysis (NBDA), which analyses the spread of traits through animal groups and takes into account that social network structure directs social learning opportunities. NBDA fits agent-based models of social and asocial learning to the observed data using maximum-likelihood estimation. The underlying learning mechanism can then be identified using model selection based on the Akaike information criterion. We tested our method with artificially created learning data that are based on a real-world co-feeding network of macaques. NBDA is better able to discriminate between social and asocial learning in comparison with diffusion curve analysis, the main method that was previously applied in this context. NBDA thus offers a new, more reliable statistical test of learning mechanisms. In addition, it can be used to address a wide range of questions related to social learning, such as identifying behavioural strategies used by animals when deciding whom to copy.