Wildcards
You can also record visits to similar URLs under one event name. Use * to indicate wildcards.
Quick Reference
Patterns that work:
Detailed Example Reference Number | Pattern | Notes |
|---|---|---|
|
| Basic demonstration of wildcards |
|
| You can use one wildcard to match on more than one subsection of a URL |
|
| You can use two or more wildcards |
|
| This matches all subpages of |
|
| This matches all subpages of |
|
| This matches a URL that has any value for the “source” parameter |
|
| This matches a URL that has the query parameter |
Patterns that don't (exactly) work:
Detailed Example Reference Number | Pattern | Notes |
|---|---|---|
|
| This is actually reduced to |
|
| Two or more wildcards together do not work |
Detailed Examples
Wildcard Example #1
Pattern: example.com/en/*/view
URLs that will trigger an event with this pattern:
example.com/en/san-francisco/view/example.com/en/new-york/view/
This example demonstrates using one wildcard to match a URL that starts with example.com/en/ and ends with /view.
Wildcard Example 2
Pattern: example.com/*/view/contact
URLs that will trigger an event with this pattern:
example.com/en/san-francisco/view/contactexample.com/en/new-york/view/contactexample.com/es/barcelona/view/contactexample.com/es/madrid/view/contact
This example demonstrates that a single wildcard can match on more than just one subsection of the URL. This example finds “any URL that ends in /view/contact”.
Wildcard Example 3
Pattern: example.com/*/san-francisco/*/contact
URLs that will trigger an event with this pattern:
example.com/en/san-francisco/view/contact
This example demonstrates you can use two (or more) wildcards in a pattern.
Wildcard Example 4
Pattern: example.com/*/view/*
URLs that will trigger an event with this pattern:
example.com/en/san-francisco/viewexample.com/en/san-francisco/view/contactexample.com/en/san-francisco/view/submitexample.com/en/new-york/viewexample.com/en/new-york/view/contactexample.com/en/new-york/view/submitexample.com/es/barcelona/viewexample.com/es/barcelona/view/contactexample.com/es/barcelona/view/submitexample.com/es/madrid/viewexample.com/es/madrid/view/contactexample.com/es/madrid/view/submit
This example demonstrates using a wildcard at the end of a URL. The last / before the wildcard indicates to match on all pages that are sub-pages of “.../view/”. This pattern also matches on “.../view/” itself, since the wildcard matches to “nothing” in that case.
Wildcard Example 5
Pattern: example.com/*/view/*/*
URLs that will trigger an event with this pattern:
example.com/en/san-francisco/view/contactexample.com/en/san-francisco/view/submitexample.com/en/new-york/view/contactexample.com/en/new-york/view/submitexample.com/es/barcelona/view/contactexample.com/es/barcelona/view/submitexample.com/es/madrid/view/contactexample.com/es/madrid/view/submit
This example contrasts with Example 4. The first */ after .../view/ means that this wildcard has to match on something (not just an empty string, like in Example 4), and the final * in the pattern looks for any deeper sub-pages of .../view/.
Wildcard Example 6 - Query Example
Pattern:
example.com/en/san-francisco/view/?source=*orexample.com/en/san-francisco/view?source=*(equivalent to the above)- Likewise,
/*/?source=*or /*?source=*
URLs that will trigger an event with this pattern:
example.com/en/san-francisco/view/?source=googleexample.com/en/san-francisco/view/?source=fbexample.com/en/san-francisco/view/?source=fb&location=homeexample.com/en/san-francisco/view/?location=home&source=fb
This example demonstrates how to match for a URL that has any value for the source parameter. Also, notice you can match for a query parameter in the URL, even if it’s not the very first parameter listed (?source=fb&location=home vs. ?location=home&source=fb).
Wildcard Example 7 - Fixed Query Parameter
Pattern:
example.com/en/san-francisco/view/?source=fb
URLs that will trigger an event with this pattern:
example.com/en/san-francisco/view/?source=fbexample.com/en/san-francisco/view/?source=fb&location=home
This example demonstrates how to match for a URL that has the source parameter set to fb. Notice that the URL can have just one query parameter (?source=fb) or additional ones (?source=fb&location=home). In the case of matching for additional query parameters, you can consider the wildcard to be implied, and you should leave it out.
Wildcard Example 8 - One to Avoid
To contrast with Example 4, here’s a Pattern That Doesn’t Work As Expected: */view/*
This pattern does not match on any of the sample URLs above, and here’s why. Though this pattern appears to look for “any URL that contains /view/ in it, we start checking the URL starting from the first /”. That means, the above pattern is actually reduced to /view/* (and we treat it as a Partial URL).
The bottom line is, if you’re leaving off the domain name, then please be mindful of including the initial / in your URLs.
Wildcard Example 9 - Another to Avoid
Another Pattern That Doesn’t Work As Expected: /*/*/view
Including two wildcards adjacent to each other will not work. Unfortunately, you cannot use wildcards to specify the depth in which to find the /view portion of the URL. For advanced use cases like this, it's better to try our Events - Visits the URL (with a Regular Expression) option.
Updated 5 months ago
