(Bloomberg) -- Facebook Inc. posted a better-than-projected gain in third-quarter revenue, indicating that a major advertiser boycott had a limited impact against the backdrop of a broader revival of spending on digital marketing.The Menlo Park, California-based company said sales rose 22% to $21.5 billion, compared with the $19.8 billion average analyst estimate in a Bloomberg survey. While Facebook reached 2.74 billion monthly active users in the quarter, exceeding predictions, it saw an unusual decline in users in the U.S. and Canada, its most lucrative ad markets, as a pandemic-fueled surge from earlier this year leveled off.In a movement spurred by civil rights leaders, hundreds of companies decided to halt advertising on Facebook in the month of July, asking the world’s largest social network to take greater responsibility for moderating hate speech and election misinformation that is often amplified on its sites. The robust sales gain underscores that, despite the criticism, Facebook is still the primary place for small and medium-sized business owners to reach customers.Because Covid-19 shutdowns have driven an increase in online shopping, Facebook has been introducing more products for advertisers to sell directly to customers through its flagship site and its Instagram photo-sharing app. Those businesses “otherwise would have a much harder time moving online and reaching customers during this pandemic,” Facebook Chief Executive Officer Mark Zuckerberg said on a call Thursday with investors. Revenue in the recent quarter benefited from that shift, as well as a boost in political advertising ahead of the U.S. election.Investors were looking for a quarter helped by “better than previously expected advertising market recovery, accelerating political ad spend and incremental contributions from a flurry of product announcements related to social commerce,” said Rohit Kulkarni, an analyst at MKM partners, in a research note.Shares fluctuated between gains and losses in extended trading, then slipped about 2% during the company’s conference call. In the statement, Facebook warned of “a significant amount of uncertainty” in 2021, citing unpredictable online spending trends during the pandemic, regulatory challenges and changes to ad rules on Apple Inc.’s devices.Facebook said ad targeting and measurement might become more difficult next year, not just because of regulations in Europe, but because of updates to privacy rules in Apple’s iOS 14 software. The social network will no longer collect unique device identifying information, known as IDFA, from iPhones, which Facebook and other companies have used to target ads to specific devices. In the new operating system, Apple users will have to agree to share the data with developers like Facebook.The company said 2021 total expenses will be $68 billion to $73 billion, as it hires technical employees and invests in new product development. Facebook is also factoring in higher spending on budget lines that had been reduced this year because of Covid, like managing offices and business travel, if the pandemic comes under control.Facebook shares closed at $280.83 in New York before the report. The stock has gained 37% this year, far outpacing the 2.5% gain in the Standard & Poor’s 500 Index. In a statement, the company also said third-quarter net income rose 29% to $7.85 billion, or $2.71 per share, compared with the $1.91 per share analysts projected.The third-quarter results offer evidence that the company’s business has so far been insulated from its mounting regulatory and political challenges. Zuckerberg testified in U.S. Congress again on Wednesday, facing questions about whether Facebook was fairly handling election-related content.Alongside other technology giants, the company has also been the target of multiple investigations into its power and influence. A congressional committee released a report during the quarter concluding that Facebook has an unfair market advantage, and the Federal Trade Commission may soon announce whether it will pursue an antitrust case.Amid the regulatory inquiries, Facebook has taken steps to further integrate its disparate social media and messaging products, making any potential breakup more difficult from a technical standpoint. Facebook recently combined the chat products on Instagram and Messenger, prompting users to merge their profiles. It also said users of its Oculus virtual reality headsets would be required to have Facebook accounts.A bigger test for Facebook will come on Nov. 3. During the U.S. election, all of the work Facebook has done to prevent foreign interference and violence, reduce the spread of misinformation, and connect voters with accurate information will be on display, Zuckerberg said on the call. Despite Facebook’s efforts, he warned of possible civic unrest, especially in the days or weeks it takes to count all the mailed votes.“Election integrity is and will be an ongoing challenge, and I’m proud of the work we’ve done here,” Zuckerberg said.(Updates with comments on election preparedness in the final paragraph.)For more articles like this, please visit us at bloomberg.comSubscribe now to stay ahead with the most trusted business news source.©2020 Bloomberg L.P.