I heard that the Iga ninja clan were bodyguards for a portion of their history. What i'm asking is what did they do? they were ninja and i can only see the recon aspect of the ninjas job come in handy when protecting someone. Was there like a ninja following the emperor like the secret service or something?
The question is a bit broad, because "bodyguard" is a very vague title/occupation. Given you're asking about ninja in the historical context of "bodyguarding" and make reference to secret service, I'm going to answer you with information related to oniwaban (御庭番, aka niwaban 庭番), onmitsu (隠密, lit. hidden secret), and the transition of Iga no mono into government service.
To start, it's important to understand that those who would become these "bodyguards" were ninja of Iga and Koga that were in service to the Tokugawa family. They fell into this role as a result of persecution under Oda Nobunaga between 1579 and 1582- the Tensho Iga no Ran (天正伊賀の乱)- stories of which are recounted in the Iran-ki (伊乱記), chronicle of chaos/events in I(ga) written by Nyogen Kikuoka, who we believe to be a monk from Iga. A number of version of the Iran-ki existed over time, with the most well known being the Kosei Iran-ki (校正伊乱記) (I own a copy of the Sanko Iran-ki 参考伊乱記). Those events then led to the appearance of famous ninja, Hattori Hanzo, in the Mikawa Go Fudo-ki (三河後風土記), where assistance was offered to members of the Tokugawa-
From here to Shigaraki, there were only chasms and mountainous roads infested by bandits. Yamaoka and Hattori accompanied them, defying any bandit of the mountain through disguise as yamabushi... Hattori Sadanobu was thanked and offered a wakazashi forged by Kunitsugu [a swordsmith].
And then
Hattori Hanzo Masashige was Iga no Mono. Sent by Sadakatsu, he guided us on the roads of Iga. The previous year, when [Oda Nobunaga] invaded Iga, he ordered "The jizamurai of Iga must all be killed." Because of this they had fled towards the territory of Tokugawa, Mikawa, and Totomi, where it was decreed they be treated with consideration and kindness. Consequently, for this act of hospitality, [ninja families] were indebted...
The tale goes on to mention various ninja escorting members and troops of the Tokugawa family through bandit-infested and other dangerous areas. It was due to the help of the Hattori family, Tsuge family, Yamaoka, and others that Ieyasu could recover and regain his stronghold in Mikawa, according to the stories. He repaid his debt to the men of Iga and Koga by permanently taking 300 of them into service. Two hundred of them were organized into the Iga-gumi Doshin (伊賀組同心, the group/team of Iga as "police") and put under Hattori Hanzo's command. And thus we see the beginning "official" uses of ninja as a force within the government under what would become the Tokugawa shogunate.
Ninja of Iga Koga formed the basis of the new Edo police, each with varying roles and, as such, varying "names" being associated with them. Such names include doshin(同心, like referenced last paragraph) shihai kaikyu(支配階級), machi kata(町方), oniwaban(御庭番), onmitsu(隠密), metsuke(目付), and teppo tai(鉄砲隊). The machi kata, for example, lived on the outskirts of Edo where crime was rampant and where they were recognized as possessing a high degree of skill in nawajutsu (縄術, rope techniques/methods), which they used to subdue criminals. Teppo tai were mainly ninja from the Negoro region, specializing in firearms; they served as an armed protection unit for the shogun and family when they left the castle, usually being referred to as Okubo hyaku-nin shu (大久保百人衆, the hundred men from Okubo). Oniwaban and Onmitsu brought together all the qualities of a skilled fighter, spy, marksman, and strategist.
Oniwaban were charged with the duty of protecting the living quarters of the Tokugawa family in Edo castle, hence where the "bodyguard" idea comes from. Given that one was prohibited from drawing a sword or really any weapon in the confines of the castle, the martial skill with mutodori (無刀捕, unarmed against a weapon, lit. "no sword capture") exhibited by these men from Iga and Koga made them perfect for the job- not to mention their ability to operate discretely kept awareness of any "incidents" around the castle to a minimum. It's said the origin of the oniwaban lies with Tokugawa Yoshimune in 1716 when, as the 8th shogun, he brought 16 men from the Kii province to be his private guard, patroling the interior, and later receiving tasks from other spies/ninja in employment, such as from metsuke mentioned earlier, a kind of spy specializing in "unconventional operations" in addition to all the other intelligence-related activities one can find on wikipedia. Granted, most metsuke are like "inspectors" rather than "spies," but the intelligence gathering aspect shouldn't be ignored in favor of more "inspector"-like or assistant metsuke such as kachi matsuke (徒士目付). Note that while the oniwaban of Yoshimune are from 1716, ninja served in the role of castle guards for decades prior.
Last, the term onmitsu refers to people engaged in undercover investigation of the movements of daimyo, the behavior of the samurai under direct service of the shogun, and the performance of the various officials. The onmitsu could be ordinary members of the metsuke, but also oniwaban, Iga no mono, and, basically, ninja. They were not "bodyguards" in the traditional sense, but special agents of the shogun used to gather intelligence and spy on daimyo in provinces across the country. They were often skilled individuals, for their travels would be fraught with peril. And the information they relayed was of critical importance.
Hopefully this gives you some insight into how ninja transitioned into protection/policing/bodyguarding/intelligence roles in the Edo era!
Sources-