This sort of problem might be quite hard to spot as all you will notice is that people start finding your sites for strange keywords, or pages that you know are not there seem to be appearing in the visited pages list. I once had a site that appeared to get over 1,000 visits per day for the keyword "corvette", which clearly wasn't the case!
So how do you stop this sort of thing? You can just detect the current URL that the user is looking at and see if it contains your domain name. If it does then you can run the code needed to register a hit with the analytics software.
I have always said that the best thing a bout the Internet is that anyone can do it, but the worst thing about the Internet is that anyone can do it. There are lots of coding blogs out there that use analytics so I present this code here to help out anyone with the same issue.