My Preview Problem
Whilst playing around with some theme switching (having one theme do some stuff, then trigger activating a new theme), I noticed that my Google page visits were going up on a site that is not public. That’s when I realised I had the analytics code for that site in my header and that previewing it was triggering a page hit.
Often it is easier to exclude logged in (or just admin) user page hits, but not always.
The Disabling Solution
The answer is easy, just wrap your code in a logical block using the is_preview() WordPress function.
Sometimes it is the little things that help!