2

I want to know if Google Analytics is tracking my localhost activity.

We have the below GA tracking script on each page and are developing new features on our local machines. Is Google tracking our visits, sessions, and goal conversions?

Tracking Script

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-12345678-9', 'auto');
  ga('send', 'pageview');
</script>

Goal Conversion Script

<script>
  window.addEventListener('load',function(){
      jQuery('.happy-form')
          .submit(function(){
              ga('send', 'event','subscribe','clickSubmit','happyPlace');
          });
  });
</script>
  • Have you looked in your real time stats? – Howard E May 13 '16 at 0:12
  • Thanks for the suggestion! I will have to test this out with Goals.. (that is my main concern) – Rastalamm May 14 '16 at 18:31
  • Real time data is unfiltered, so it's good for testing goals and events – Howard E May 14 '16 at 18:36
  • @HowardE, wanted to mention that filters ARE indeed applied in RT reports. The only time RT data is unfiltered is if you don't have filters for that particular view. – nyuen May 14 '16 at 19:02
  • Check if any of browser plugins is blocking. Open the browser in incognito mode. – Lukasz Madon May 24 at 12:58
3

Go to Admin in Google Analytics, in the third column click on Filters.

Add a filter that only includes the hostname you do want to track, that way anything else, include localhost, will be excluded from your data going forward.

It's not possible to correct data that has already been gathered.

1

I believe that to track on localhost, you could also set your trackers cookie domain to none (auto works, too, cf. https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#automatic_cookie_domain_configuration). Install GA Debugger for Chrome to make sure the hits are sent and also to see valuable debugging info.

Edit (based on comment): I'm not sure how to prevent tracking in localhost, but if you do the converse of the above, and set your cookie domain to your top level domain (ie. example.com), then that shouldn't track your localhost.

  • I am trying to avoid being tracked in localhost – Rastalamm May 14 '16 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.