Google Analytics目标正则表达式需求:排除含/general/的URL
Regex Solution for Google Analytics Goal: Track Vehicle Detail Pages, Exclude /general/ Search Pages
I get it—you need a tailored regex for your GA destination goal that only counts vehicle detail pages (like /used-cars/citreon/ or /used-cars/TOYOTA/) while blocking any pages with /general/ in the path (such as /used-cars/general). Here’s the exact pattern you need:
^/used-cars/(?!general).*$
Breakdown of the Pattern:
^: Anchors the match to the start of the URL path (prevents partial matches on longer URLs that might include/used-cars/later on)/used-cars/: Matches the base path for all relevant used car pages(?!general): A negative lookahead assertion—this tells GA to exclude any URL where the segment right after/used-cars/starts with "general". It blocks both/used-cars/generaland/used-cars/general/(plus any variations with query parameters like/used-cars/general?search=sedan).*: Matches any remaining characters in the path, covering make names in any case (lowercase, uppercase, mixed), trailing slashes, and extra parameters$: Optional but recommended—anchors the match to the end of the URL path to avoid unintended partial matches
How to Apply This in Google Analytics:
- Navigate to Admin > Goals (under the View column)
- Create a new goal, select the Destination goal type
- Under "Destination", choose the Regular expression option
- Paste the regex pattern above into the destination field
- Save your goal, and it will start tracking only the vehicle detail pages you want, ignoring the
/general/search results.
Note: Google Analytics uses case-insensitive regex by default, so this pattern will match both /used-cars/citreon/ and /used-cars/TOYOTA/ without extra adjustments. Case sensitivity can be enabled if needed, but it’s not required here.
内容的提问来源于stack exchange,提问作者Jonathan
相关产品推荐
相关产品推荐

