The Scottish campaign for independence from the UK recently gained a slim lead over the pro-union campaign in the battle for public opinion online, according to Facebook.

The social network, which is used by about half the Scottish population, analysed more than 8.5m posts, comments and likes related to the referendum over the five weeks to September 8.

It found that the pro-independence Yes campaign had a slight advantage, with 2.05m interactions in Scotland, compared with 1.96m interactions for the pro-union No campaign.

The Yes campaign’s lead materialised in the final week of the five week period, suggesting that “momentum in the campaign is starting to shift”. But Facebook hedged its bets, saying that the vote “could still go either way”.

The social network also said it hoped to boost voter turnout at the referendum this Thursday by adding a special “I’m a Voter” button to the newsfeeds of those eligible to vote.

By clicking the button, users can highlight their status as a voter to their Facebook friends. It will not say whether they have voted Yes or No.

Elizabeth Linder, a politics and government specialist at Facebook, said: “Studies show that when people see their Facebook friends talking about voting, they are more likely to vote themselves.”

Facebook has previously used the “I’m a Voter” button during the last three US elections. During the 2010 US congressional elections, a Facebook message was shown to have boosted turnout by about 340,000 extra people.

Political analysts say social media has played an important role in shaping popular opinion about Scottish independence.

Conor Magowan, director of public affairs for Scotland at Weber Shandwick, the public relations company, said digital platforms have been particularly influential because the minimum voting age for the referendum is 16, and young people are most active on social media.

Yes Scotland has had a “more consistent and strategic approach” to spreading its message via social media than Better Together, said Mr Magowan. “The digital generation looks more inclined to vote Yes,” he added.

Twitter, which has fewer users than Facebook, has also been a forum for heated debate. Harry Potter author and Better Together donor J.K. Rowling has tweeted repeatedly to her 3.6m followers, while other celebrities such as the musician Billy Bragg have tweeted in favour of independence.

An analysis by Crimson Hexagon, a social media analytics company, found that over the past month the Yes vote has accounted for almost 90 per cent of referendum conversation on Twitter.