Al-Shabaab likes Twitter.

A few months ago, just hours after I had left the Somali capital, Mogadishu, the Islamist terrorist group sent taunting messages on the social networking site about a deadly strike it had launched against a United Nations humanitarian compound in the city.

Shortly before my departure I had passed the very spot where the group staged their brazen daylight attack on the heavily fortified compound. Little did I know then that within hours a seven-man suicide commando squad of al-Shabaab fighters would blast its way into the complex and wage a deadly gunbattle that left 11 UN personnel dead, endorsing once again Mogadishu's reputation as one of the most dangerous places in the world. That Mogadishu achieved this dubious distinction has in great part recently been because of the war al-Shabaab has waged in Somalia and its tie-up in 2012 with al-Qaeda.

Over the last week, al-Shabaab has once again been busy, blasting its way into another building - and boasting of it on Twitter.

Its target was the Westgate shopping centre in the Kenyan capital, Nairobi, where 67 people died and more than 175 others were wounded. Yesterday, the Foreign Office confirmed a sixth Briton had died in the attack.

Lately, such strikes seem to have become the group's modus operandi but are a far cry from its previous battlefield campaign, which was mainly restricted to its home turf of Somalia. Social-networking website Twitter gives us some of the best clues as to the group's fortunes and intentions of late. Enter Omar Hammami - nom de guerre, Abu Mansoor al-Amriki - a 28-year-old US-born ­jihadist who travelled to Somalia to join al-Shabaab in 2006.

It was some time last year when Hammami first issued an online video and began using his Twitter account to tell those willing to listen that he feared for his life. But it was not the Somali or American governments - both of which had branded him a terrorist - that Hammami felt threatened by, but figures within al-Shabaab itself.

So afraid was Hammami that he effectively went to ground - though he continued to use his @abumamerican Twitter account to keep in touch with journalists and terrorism analysts while criticising al-Shabaab's leadership. In a series of messages, Hammami claimed that there had been a string of attempts on his life and those of his allies within al-Shabaab.

At the root of this bad blood was a face-off between Hammami and al-Shabaab's emir, Ahmed Abdi Godane, aka Abu Zubayr. According to terrorism analysts at the respected US-based magazine Foreign Policy, the two had fallen out over a number of issues, among them the role of foreign fighters, taxation of local communities, and the trial procedures and punishment meted out to those who opposed al-Shabaab. Hammami's Twitter feed gave analysts a rare peek into the factional differences beginning to bedevil al-Shabaab.

This pursuit of Hammami by Godane over the course of many months created something of a civil war within al-Shabaab, driving a wedge between Godane and other leaders. Godane managed to reassert his leadership over the remaining structures of al-Shabaab following the defection of his key rival within the group, Sheikh Hassan Dahir Aweys, 78.

However, the defection of Aweys - now in the custody of the Somali government's security forces in Mogadishu - was just part of the fallout from this internal spat.

As-yet unconfirmed reports say that the power grab by Godane loyalists sent long-time al-Shabaab spokesman Mukhtar Robow into hiding. Yet another casualty was group veteran Ibrahim al-Afghani, who had fought alongside Osama bin Laden and is said to have been executed by Godane loyalists after a gun battle on June 19.

It appears Hammami fared little better. At the beginning of this month, Hammami logged into his @abumamerican Twitter account and messaged the US journalist and terrorism analyst, JM Berger. "Good news is I'm alive and free up until now," Hammami tweeted.

But according to Berger, by September 15 someone else logged into the @abumamerican account and sent this message: "We hereby confirm the martyrdom of Omar Hammami in the morning of Thurs 12 2013. Shafik's family please accept our condolences."

While this was not the first time Hammami's death had been reported, subsequent evidence from other sources among Hammami's al-Shabaab allies now suggests his demise is confirmed. With Godane seeking to consolidate his control following these bloody purges, we come back to the issue of the Nairobi attack.

Godane is known to be a proponent of the trans-nationalist faction, opposing the more Somali nationalist approach of his - now mainly purged - rivals in al-Shabaab.

While the nationalist factions see the fight in Somalia as the most important aspect of the group's activities, Godane and his cadre feel the group should emulate other al-Qaeda affiliates and organise international attacks to further the global Islamist struggle.

"The question now is whether, having marginalised rivals and turned al-Shabaab into more of a terrorist group and less of a Somali insurgency, Godane will transform it into a more regional threat," said J Peter Pham, who heads the Africa Centre at the Atlantic Council in Washington, DC.

So it seems that a weakened al-Shabaab is a greater threat outside Somalia than a stronger al-Shabaab. Intelligence analysts suggest last week's attack in Nairobi could bolster Godane's leadership of the trans-nationalist faction within al-Shabaab, demonstrating that the group has not been defeated and remains a potent guerrilla threat, despite losing significant territory.

During my time in Mogadishu in June, there were already signs that al-Shabaab's tactics were shifting. As the Somali government and African military forces, under the umbrella of the African Union Mission in Somalia (AMISOM), made gains by disrupting and degrading al-Shabaab militarily, Godane appears to have recognised the need to adopt more guerrilla-style tactics.

A year ago, Kenyan forces seized al-Shabaab's final stronghold, the Somali port of Kismayo, sending the group into the country's rural interior and cutting them off from the economic lifeline the port city provided. But the Kenyan military, Somali National Army and the Ethiopian Defence Forces were ultimately unable to wrestle control of Somalia's southern hinterlands from al-Shabaab's forces.

In July this year, the UN Monitoring Group reported an estimated 5000 fighters remained in al-Shabaab's ranks and said it continued to be the "principal threat to peace and security in Somalia".

As Clinton Watts, a senior fellow at the Homeland Security Policy Institute at George Washington University in Washington, DC, wrote in Foreign Policy magazine, al-Shabaab "transitioned from conventional fighting to asymmetric warfare using terror attacks to target the new Somali Federal Government in Mogadishu and now, tragically, in the heart of Kenya".

Attacks inside Kenya have occurred periodically in recent years, but they have been limited to the border area near Garissa or were the work of al-Shabaab sympathisers in Nairobi's predominately Somali-inhabited Eastleigh district.

Under Godane's strategy, the latest attack on Kenya provides a win-win scenario. On the one hand, it could provoke Kenya into even greater commitment to sustaining its forces in Somalia, allowing al-Shabaab the opportunity to engage them in a drawn-out, costly counter-insurgency campaign. On the other hand, it may politically destabilise Kenya, should there be a backlash against the Somali population of around one million living in the country. Kenya has a long history of heavy-handed military campaigns against "problem groups" within the country; fanning the flames of xenophobia would work well within the terrorist template al-Shabaab adheres to.

As ever, using its Twitter presence, al-Shabaab called the Westgate shopping centre attack "retributive justice for crimes committed" by Kenya's military. Witness accounts say that the terrorists reportedly targeted non-Muslims as they made their way through the mall.

As Declan Galvin, an Africa specialist and global human rights fellow at New York University highlighted last week, what the Kenyan government needs to keep in mind is that it can easily become its own worst enemy in its fight against al-Shabaab and terrorism.

In a Foreign Policy article, Galvin wrote: "Both the Somali and Muslim communities in Kenya feel perennially victimised. Further alienating these communities will not only hinder Kenya's War on Terror, but will provide fertile ground for al-Shabaab's recruitment efforts."

This brings us to the wider global threat al-Shabaab poses and any international response to it - no doubt we can expect renewed attempts to locate and kill Godane and other al-Shabaab leaders. And according to the US-based ­independent intelligence monitoring group Stratfor, Kenya is likely to step up its efforts to crack down on suspected supporters of al-Shabaab within its own borders and will probably do so through greater co-operation with US and British security agencies.

Last week's attack in Nairobi was yet another reminder that Islamist extremism has taken root across a broad swath of the African continent. It has also been suggested that what occurred in Nairobi may only have been the last lashing out of a terrorist group in its final death throes.

That will come as little consolation to the relatives of the Westgate victims. Most analysts - this one included - have the feeling that we will be hearing from al-Shabaab again all too soon, with or without its fixation with Twitter.