I need to know if the goal was ever registered on the contact in its any visit on any interaction. How can I do that?
You could load all previous visits using this code:
IEnumerable<IInteractionData> visits = Tracker.Current.Contact.LoadHistorycalData(visitsToLoad);
Then you could check every page of every visit and see if the goal was triggered. This would not perform well though.
You should use the Key Behavior Cache which contains (a configurable amount of) goals, events, campaigns etc. that have been triggered by contacts, even in previous visits.
Guid goalId = // your goal ID KeyBehaviorCache cache = Sitecore.Analytics.Tracker.Current.Contact.GetKeyBehaviorCache(); bool goalTriggered = cache.Goals.Any(_ => _.Id == goalId);
Keep in mind that the Key Behavior Cache contains a limited number of entries. So you should make sure it's tuned for your needs. See this documentation page for more information: