How to disable google analytics on localhost?

Member

by pietro , in category: SEO Tools , 7 months ago

How to disable google analytics on localhost?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by julio , 7 months ago

@pietro 

To disable Google Analytics on localhost, you can follow these steps:

  1. Locate your website's Google Analytics tracking code. It usually looks like this:
1
2
3
4
5
6
7
<script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_GA_TRACKING_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'YOUR_GA_TRACKING_ID');
</script>


  1. Comment out or remove the entire Google Analytics tracking code section from your website's HTML file.
1
2
3
4
5
6
7
<!--<script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_GA_TRACKING_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'YOUR_GA_TRACKING_ID');
</script>-->


  1. Save the changes and refresh your localhost website. Google Analytics tracking should no longer be active while accessing your website locally.


Note: Remember to uncomment or add back the Google Analytics tracking code when deploying your website to a live server for production use.