Prevent PII being tracked in Google Analytics
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Prevent PII from being tracking in Google Analytics

Google don't allow PII (Personally Identifiable Information) to be tracked in Google Analytics. You can have your Google Analytics account suspended if you don't abide by the rules.

Google provide some helpful Best Practises information, but their suggestions often rely on rewriting your web application so that PPI aren't displayed in the URL.

This work-around script works by only including Google Analytics tracking snippet if the URL does not include email, username or password strings. The exact strings could easily be modified to suit your needs.

<script>{ga.q.push(arguments)};ga.q=[];ga.l=+new Date;
  if(location.href.match(/(?:\b|_)(?:username|email|password)(?:\b|_)/i) > -1){
  document.write('<script src="" aysnc defer><\/script>');

Demo - this page loads Google Analytics as normal

If you include params with PII (email, username or password) the URL though, Google Analytics will not load:

Note; the optimized Google Analytics snippet is from HTML5Boilerplate