Code Monkey home page Code Monkey logo

url-cleaner's Introduction

URL Cleaner

Custom Variable Template for Google Tag Manager

URL cleanup with black- or whitelisting for parameters and optional value redaction with regexes

Template Status Repo Size License


Note: this template does not need any permissions.

Usage

  • define any URL as input value. Select "Whitelist" and define a set of allowed variables. All other parameters and their values will be eliminated from the URL query string. Alternatively a "Blacklist" can be defined in the same way. In this case, only blacklisted parameters are removed.

Update: Redact Path

In June 2023 a third option "Redact Path" was added. You can use it to remove certain paths from URLs if they match any of the patterns or search terms privided in the redaction list.

Tip: If picked, there will be no additional adjustment of parameters. If you need to change both path and parameters, use result of a first URL Cleaner as input for a second one.

  • The remaining parameter values can optionally be checked and redacted by using one or more regex expressions.

  • if you want to lowercase the result, check the option in the variable settings (default is "off")

The return value will be a clean URL, path with parameters or parameter string only.

"Partial Match And RegEx" Option

when comparing parameter keys with white- or blacklist entries, you can optionally enter only a common part of a set of parameters (like utm_) or use regular expressions.

When active, the template uses a JavaScript "match" (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) to determine if a parameter is to be white- or blacklisted. If not, a parameter must be equal to an entry on the list to be handled by the code.

using a blacklist on https://www.domain.com/?foo=1&bar=0&find=PII+here&find2=keep with find on the list results in

https://www.domain.com/?foo=1&bar=0

if you use ^find$ instead, the result will only delete the first parameter and keeps find2

https://www.test.com/?foo=1&bar=0&find2=keep

Special Functions

Radacting Parameters Without Removing

If you want to redact parameters without removing them (for controlling purposes or other reasons), you can use the "Redact Parameters" option and define a parameter name instead of a regex. In this case, the template does not match the list entry as RegEx against the values but compares any list entry with parameter names, when a special format is used.

In order to use this, add parameter names in the following format to the list:

%%parametername%%

By surrounding a parameter name with double "%" signs, any matching parametername in the URL will be kept in the result, but the value gets replaced with the defined text just as if a normal RegEx had matched the parameter value. Note: this option works case insensitive, so %%something%% would catch "Something" as well as "something", "someThing" or any other format. There must be a complete match (no RegEx or partial match here).

Using Comma-separated List Items

You can define multiple comma-separated values like param1, param2, param3 in one list entry instead of creating three separate list items for black- and whitelists. This allows dynamic definition of blacklists in a separate variable that uses different sets of list items for different consent conditions.

url-cleaner's People

Contributors

mbaersch avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

url-cleaner's Issues

caps not working in parameter list

In my url some parameters use caps, but they do not get cleaned up when I add them to the list how they are used in the URL. After I typed them in lower case it works, but probably not everyone will figure it out.

issues with the "partial matching and regex"

Hi there and thanks for your excellent template!

I tried using the checkbox which enables "partial match & regex" and can't really get that to work the way I thought it was intended. After enabling the checkbox, I've tried typing in:
^action$
/^action$/

as potentail formatting choices for regex, but both of those ideas seem to match very loosely (it does not take the ^$ assertions into account and/or I've typed the patterns incorrectly. Could you shed some light on how that box is intended?

Is it possible to make two checkboxes instead - one which is simply a loose match and another more advanced box which supports full regex patterns, including a formatting guide?

support for arrays and/or csv-formatted strings for batch-add of params

Hi again, and once again thanks for your great tool, making great use of it!

I've been working away at a collection of clickid parameters that I've scoured from the web over a few years of running campaigns and filtering params from GA reports accordingly. This is what led me to your tool, which I found to be one of the best ones of the lot! I was wondering if there was a way to add support for providing an array and/or csv-string of multiple parameters, rather than having to create and manage individual lines for every parameter within your template.

Idea: a checkbox to select whether the user wants to

  1. input parameters into individual lines as it's currently being presented
  2. input all parameters as a csv-string or array into an empty text-field
  3. reference another GTM variable as input for params.
  4. fetch from github repo or other URL - fetch a list of params dynamically from github (via jsdelivr or similar)?

Again thanks for your great tool, feel free to provide any thoughts on my list there too should you have any!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.