Is it ok to have brackets or parenthesis in URL?
Brackets and parentheses are perfectly valid characters within a standard Uniform Resource Locator (URL). The underlying protocol, defined by RFC 3986, explicitly lists them as "reserved" characters that require percent-encoding when they appear in specific contexts. However, the answer to whether it is okay to use them depends entirely on where you place them and how your infrastructure handles the resulting encoded strings.
In your specific case involving Google Ads (AdWords) campaign parameters, the URL provided demonstrates a common scenario: utm_content=google_ad(B) versus utm_medium=cpc containing [B+]. The critical distinction lies in whether these characters appear in the query string values or if they are used to delimit parts of the domain name.
If you look at the sample URL, the brackets appear inside the query parameter values (utm_content and a hypothetical utm_medium). This is technically permissible under the HTTP specification, provided they are percent-encoded. The character ( becomes %28, ) becomes %29, [ becomes %5B, and ] becomes %5D. Your encoded string google%5BB%2B%5D correctly represents google[B+].
The primary pitfall here is not the validity of the characters themselves, but rather how third-party systems interpret them. Search engines like Google generally handle percent-encoded brackets without issue in campaign tracking parameters. However, your internal analytics stack might be more fragile. Many analytics platforms (such as older versions of Adobe Analytics or specific implementations within WordPress) attempt to parse URL parameters before decoding. If an analytics script expects a simple string like utm_content=google_ad(B) and receives the raw encoded version without pre-decoding, it may fail to match the campaign correctly or truncate the data at the first percent sign.
Furthermore, consider the user agent string or browser history. While modern browsers decode URLs before rendering them in the address bar, some legacy systems or custom JavaScript logic might treat the %28 sequence as a literal string rather than a decoded parenthesis. This can lead to broken links if your application expects the raw character ( but receives the encoded version upon redirect.
A more significant trade-off arises when using brackets inside the path component of the URL rather than the query string. For example, http://www.website.com/product(B) is valid syntax, but frameworks like Laravel often use routing rules that might confuse regex patterns containing these characters unless escaped properly. If your application uses dynamic routes where the segment following the last slash is treated as a route parameter, you must ensure your router handles the encoded payload correctly to avoid 404 errors or incorrect model binding.
When generating these URLs programmatically, using raw string concatenation in languages like PHP or Python is prone to error. You risk double-encoding if a framework automatically encodes parameters that already contain encoded sequences. In a Laravel context, for instance, utilizing the url helper with query arrays ensures safe encoding:
$url = url('product?utm_content=google_ad(B)');
This approach relies on the underlying HTTP client to handle percent-encoding correctly. If you manually construct the string by appending &utm_content=google%5BB%2B%5D, you must be absolutely certain that no subsequent middleware or framework layer attempts to re-encode it.
Ultimately, the decision rests on your downstream consumers. If the only place this URL travels is to Google Ads and then back to a modern web browser, the encoded brackets are safe. However, if intermediate systemsâlike an API gateway, an older analytics server, or a mobile app with strict URL parsingâmight intercept the request, you should consider sanitizing the campaign names to use hyphens or underscores instead. While this sacrifices some character variety for naming flexibility, it eliminates the risk of encoding mismatches that can silently corrupt your tracking data.
If you need robust tools to manage complex URL structures and campaign tracking without worrying about encoding nuances, resources like those found at https://laravelcompany.com often provide practical insights into building stable routing and query parameter handling in modern stacks.