Transform Rule to remove tracking click identifiers

Yes, the goal is to remove any query parameter that is only relevant to the front end. This would be at least fbclid, gclid and gclsrc. They could indeed be accompanied by other query parameters that do cause content to change and so need to be retained.

It’s similar to custom cache keys, when you want to exclude some query parameters but not others.

If it helps, here is a worker that does the same thing:

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

/**
 * Respond to the request
 * @param {Request} request
 */
async function handleRequest(request) {
  const TRACKING_PARAMS = ['gclid', 'gclsrc', 'fbclid'];
  const url = new URL(request.url)

  TRACKING_PARAMS.forEach(param => {
      if (url.searchParams.has(param)) url.searchParams.delete(param)
  })

  return fetch(url, request)
}