The Network Requests - mask URLs template is designed to selectively anonymize URLs collected for API errors and network details whose paths may contain personal information.
How to use the template
This article should be used alongside the Contentsquare Tag Configurator article, which includes details on prerequisites, Snippet creation, and Template selection.
Step 1: Define the pattern
In the URL pattern field, specify the path segments you want to anonymize and their placeholders.
- For the fragment to be anonymized:
- Start with the colon character “:”
- Add your placeholder value (without a space)
- Make sure to add the preceding and/or next fragment for proper matching
This way, the following pattern
previous-segment/:my_placeholder_value/next-segment-optional
will be replaced with
previous-segment/:CS_ANONYMIZED_MY_PLACEHOLDER_VALUE/next-segment-optional
Note
Each CSTC snippet accepts a single URL pattern. To add more patterns, create several instances of this type of snippet in the CSTC.
Example: URL masking pattern
Let’s use a more concrete example. Imagine you have the following request URL:
https://example.com/api/clients/1234/users/john-doe
The URL includes the client ID (1234) and the username (john-doe) - both of which are sensitive information you would not want to collect in the API error or network details.
To achieve this, you would want to find and replace the path segments that contain the sensitive information, while retaining the ones that do not. Therefore, the correct URL pattern to be used in this particular case would be:
api/clients/:client_id/users/:user_name
Now, using the same URL pattern (above) let’s examine a few more examples of how this works (or doesn’t):
Evaluated URL | Converted URL | Was masking successfully applied? |
https://example.com/api/clients/1234/users/john-doe |
https://example.com/api/clients/CS_ANONYMIZED_CLIENT_ID/users/CS_ANONYMIZED_USER_NAME |
Yes |
https://example.com//api/clients/1234/ |
https://example.com/api/clients/1234/ |
No, because the URL pattern does not match |
https://example2.com/api/clients/1234/users/clarks-mitchell |
https://example2.com/api/clients/CS_ANONYMIZED_CLIENT_ID/users/CS_ANONYMIZED_USER_NAME |
Yes, because the URL pattern is domain agnostic |
https://example.com/api/clients/23534634634/user/jerome-stone/history/orders |
https://example.com/api/clients/CS_ANONYMIZED_CLIENT_ID/user/CS_ANONYMIZED_USER_NAME/history/orders |
Yes, because the URL pattern will be applied even if it matches only a part of the path. The masking pattern does not have to match the full path for it to work. |
Step 2: Select a Trigger
Select the only available trigger, Before Pageview, to define the conditions that will fire the Snippet.