NO ONE, not even the man himself, expected Donald Trump to triumph on election night. There was some disagreement about how much of an underdog he was: the forecasting models most bullish on his chances gave him slightly less than a 30% shot—the same number his campaign’s data wonks had—while the most sceptical ones estimated a mere 2%. Betting markets roughly split the difference, assigning him a 20% chance of victory. But given Hillary Clinton’s imposing leads in both national and state polls, no prediction based on public surveys could have considered Mr Trump a favourite. Some of Mrs Clinton’s campaign staffers were so certain of her victory that they began popping champagne hours before the votes were counted.

It is now clear that many of these polls, particularly at the state level, were gravely off the mark. The American Association for Public Opinion Research has promised an autopsy by May of next year. Until then at least, the cause—whether “shy Trumpers” ashamed to admit their allegiances, erroneous turnout projections or faulty sampling methods—will remain uncertain.

Given this disappointing performance, sheepish prognosticators have wondered whether any alternate source of information might have offset the off-target polling. Preliminary evidence suggests that one may have been sitting on their monitors all along: interest and enthusiasm on social media. In general, the projected vote shares in each state published by FiveThirtyEight, the most prominent electoral-forecasting site, were fairly accurate. However, their few misses—primarily concentrated in the Rust Belt—turned out to be decisive. And it was precisely in those states where Mr Trump enjoyed some of his greatest online advantages.

In order to help advertisers target their consumers, Facebook maintains a platform that estimates its users’ interest in a wide range of topics. Shortly before the election, Erin Pettigrew, a media consultant, obtained figures from Facebook gauging interest in both Mr Trump and Mrs Clinton in each state. The day after the election, she published an article demonstrating that these numbers broadly lined up with the two candidates’ ultimate vote totals. Although Mr Trump enjoyed the lion’s share of Facebook interest in every single state—his worst performance was in the District of Columbia, where he only carried two-thirds of the conversation—his advantages tended to be greater in states that wound up voting for him.

It is possible that these statistics could simply have reflected patterns that had already been observed in polls. However, it turns out that Mr Trump’s performance on Facebook provided tantalising clues as to where the public surveys were likely to misfire. For example, he scored an unexpected victory in Michigan, where he faced a four-percentage-point deficit and interest was 18th highest in the country. By contrast, Mrs Clinton enjoyed a similar polling lead in Colorado, but the state ranked 43rd in interest in her opponent. She went on to win it comfortably.

With the benefit of hindsight, a time-travelling statistician could have used the social-media numbers to produce deadly accurate forecasts. Combining data from polls, Facebook, and Google searches, he could have correctly predicted 49 of the 50 states, missing only Wisconsin. That would have been enough to foresee a defeat for Mrs Clinton. (For quantitatively-minded readers, polling averages and Facebook interest were both statistically significant, while Google searches were not.) Given that time travel is yet to be invented, there is no way to know whether this relationship will persist in future elections. Nonetheless, the strong association shows that forecasters would be well-advised to try to incorporate “digital enthusiasm”, however measured, into their models.

These data are silent on why Facebook interest seems to have provided such a valuable complement to polling. But one plausible explanation would be that superior social-media performance reflects higher enthusiasm for a candidate, which in turn correlates well with turnout. Forecasting turnout is notoriously difficult—just 60% of the electorate votes, but over 90% of poll respondents say they will definitely vote when asked. As a result, pollsters rely on estimates pegged to the previous election, making it hard to anticipate changes. As the pool of internet users expands beyond the young and cosmopolitan, the web is increasingly representative of the overall electorate. Paradoxically, pollsters may have to dive into seemingly chaotic streams of internet chatter to produce more reliable barometers in the future.