4

When I view the page source of my website, I can see my Google Analytics snippet:

 <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12367889-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-12367889-1');
 gtag('config', 'AW-608708765');
</script>

I tried pasting this code into a local file and opening that file in a browser. Google Analytics counted the hit that wasn't from my website.

That means everyone can copy my code and use for fake traffic. How can I prevent that?

  • 2
    GA has had issues in the last few years with fake traffic, especially spam injected into GA reports. See our tag google-analytics-spam for bunch of questions folks have asked about it. – Stephen Ostermiller May 14 '18 at 11:51
1

One solution is to set up a 'Custom Filter' to only include data from your domain. This filter should then prevent your data from being corrupted if someone copies and uses your tracking snippet on another domain.

So, it would be something like this:

  1. Admin
  2. Filters
  3. Add Filter
  4. Pic a name
  5. Choose 'Custom'
  6. Choose 'Include'
  7. Choose 'Hostname' in the dropdown
  8. Write your hostname with a \ before the dot, like this \.com
  9. Click Save

Here's two blog post describing the solution:

https://www.wetpaintwebtools.com/blog/how-to-protect-your-google-analytics-data-from-spam/

https://neilpatel.com/blog/protect-analytics-from-hacking/

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.