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

#1

/en/*/view

Basic demonstration of wildcards

#2

/*/view/contact

You can use one wildcard to match on more than one subsection of a URL

#3

/*/san-francisco/*/contact

You can use two or more wildcards

#4

/*/view/*

This matches all subpages of /*/view/, including the page /*/view itself

#5

/*/view/*/*

This matches all subpages of /*/view/, excluding the page /*/view/ itself

#6

/*/?source=* or /*?source=*

This matches a URL that has any value for the “source” parameter

#7

/*/?source=fb

This matches a URL that has the query parameter source=fb. You don’t need a wildcard to match a URL with additional query parameters.

Patterns that don't (exactly) work:

Detailed Example Reference Number

Pattern

Notes

#8

*/view/*

This is actually reduced to /view/*

#9

/*/*/view

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/contact
  • example.com/en/new-york/view/contact
  • example.com/es/barcelona/view/contact
  • example.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/view
  • example.com/en/san-francisco/view/contact
  • example.com/en/san-francisco/view/submit
  • example.com/en/new-york/view
  • example.com/en/new-york/view/contact
  • example.com/en/new-york/view/submit
  • example.com/es/barcelona/view
  • example.com/es/barcelona/view/contact
  • example.com/es/barcelona/view/submit
  • example.com/es/madrid/view
  • example.com/es/madrid/view/contact
  • example.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/contact
  • example.com/en/san-francisco/view/submit
  • example.com/en/new-york/view/contact
  • example.com/en/new-york/view/submit
  • example.com/es/barcelona/view/contact
  • example.com/es/barcelona/view/submit
  • example.com/es/madrid/view/contact
  • example.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=*or
  • example.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=google
  • example.com/en/san-francisco/view/?source=fb
  • example.com/en/san-francisco/view/?source=fb&location=home
  • example.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=fb
  • example.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.