In retrospect, I believe the primary reason that many analysts thought Hillary Clinton was a clear favorite to win the presidency actually had little to do with her or her opponent. Based on the states that Democrats won in 2008 and 2012, the party believed it had a sort of "blue firewall" that secure nearly 270 electoral votes. The Democratic party spent their ad budget accordingly, and suffered a stunning loss. Ultimately, the Clinton campaign's advertising spending in Michigan and Wisconsin seems to have been a major factor in that defeat.
Democrats did not allocate much of their advertising budget to perceived blue states, in spite of projections from FiveThirtyEight estimating that Trump had, roughly, a 40 percent chance of winning either state. Trump's campaign, on the other hand, realized that it had fewer paths to victory than Clinton did, and that by extension, it needed to bring non-traditional swing states into play. Its late push for Michigan and Wisconsin arose from a belief that a Trump victory would most likely come from high turnout amongst Trump's core demographic — non-college-educated white voters — and low turnout amongst Clinton's.
Both Michigan and Wisconsin were among the states with the highest proportion of that demographic in a year when turnout amongst Democrats was low, as reported by the Washington Post. It was a perfect storm for Trump.
I've written in the past about why I believe traditional concepts of red and blue states are reductive: by dividing states only into those groups, we ignore the very different demographics that make up each state and blind ourselves to divisions among those states. Michigan and Wisconsin (and Minnesota, which ultimately went to Clinton) were all states with a substantive population of the voters that often went for Trump; as a result, they were always less secure for Clinton than her campaign seemed to realize.
Furthermore, the immense number of major news stories in the final weeks of the campaign made planning difficult. As Jim Tankersley at the Washington Post argued, in the last two weeks of October, the Clinton campaign was planning for a blowout — prioritizing states she didn't need like Iowa and Arizona over states that she couldn't win without. The mistake was understandable considering how favorable the outlook was for Clinton after the leaked Access Hollywood tape showed Trump bragging about grabbing women without their consent. The subsequent announcement from James Comey that the FBI would review additional Clinton-related emails (and the extent to which that announcement was overblown in the media) stopped that momentum in its tracks and jeopardized Clinton's standing even in "safe" states. Finally, the Clinton campaign amped up its spending in critical "blue" states — but apparently, it was too late.
Clinton ultimately lost Michigan by a mere 10,000 votes, a margin so close that many outlets still have not definitively called it for Trump. I believe that rarlier spending could likely have increased turnout enough to turn the state blue. Of course, ad spending in the Upper Midwest is only one of many reasons why Donald Trump won the Electoral College, but it illustrates a lesson that Democratic campaign staffers must learn before 2020.