You are recording the full URL in your web analytics tool. You look through the pages report, and you realise that you are recording some potentially sensitive PII (such as an email address) in the query string. The answer is to strip this field from the query string in an extension before sending it to any tags. 

This article presents a couple of alternative ways to do that.

If you want to redact email addresses

This option is appropriate if you want to remove email addresses from the query string, and you don't necessarily which parameter they may appear in.

Step 1: create a Set Data Values extension. Make sure it is scoped to All Tags.

Step 2: in the "Set" field, click on the + button to create a new variable, and call it clean_url.

Step 3: set the value using this code:

b['dom.pathname']+"?"+b['dom.query_string'].replace(/=([^&]+@[^\.]+)\./g, '=xxx@xxx.')

This a regular expression that replaces any email address (in any field) with

If you want to strip out named parameters

If you have certain fields that you want to remove completely from the query string, then you can use an alternative approach.

Step 1: create a new variable from the Data Sources tab, called clean_url.

Step 2: Create a JavaScript Code extension in the Extensions tab. Make sure it is scoped to All Tags, so that the data is not sent to any of the tags that you have deployed on the page. Paste this code into the text box:

// Strip these selected fields from query string
var pii_data = ["card_number", "email"];

var query_params = b["dom.query_string"].split(/&|;/);
var clean_query = [];

function validate(field) {
  for (var i = 0; i < pii_data.length; i++) {
    var regexp = new RegExp("^" + pii_data[i] + "=");
    if (regexp.test(field)) {
      return false;
  return true;

for (var i = 0; i < query_params.length; i++) {
  var field = query_params[i];
  if (validate(field)) {

b.clean_url = b["dom.pathname"] + "?" + clean_query.join("&");

In the second line of code, you can add the names of the variables you want to remove from the query string.

Did this help? Need more functionality? Let me know in the comments.

Tags (1)