I would assume you could look for the active class, and get the child anchors href attribute:
$('#primarynavbar').on('activate.bs.scrollspy', function () {
var hash = $(this).find("li.active a").attr("href");
window.history.pushstate('http://abcd.com' + hash);
});