Reputation: 801
In Google Analytics, I have a view for a web site in which I'm trying to use Advanced filters to codify a transformation on the "Request URI" field:
When I view the traffic in the Site Content..All Pages report, I don't want to see any values of "/[productid]" in the URIs in the "Page" column - I'd like all visits to a particular product page to roll up under a URI like "/product/warranty" or "/product/description".
Unfortunately I find it difficult to try figuring this out on my own because of the lag in seeing results in Google Analytics after making a change combined with my shaky grasp of how regular expressions are utilized in Advanced Filters.
Upvotes: 1
Views: 1187
Reputation: 307
Assuming your [product id]
was 3 or more consecutive digits, ie: /product/123456789/someproductscreen
then this would work:
Field A
: Request URI
: ^/product/\d{3,}(.*)
Field B
: Request URI
: /product/{id}$A1
Field A Required
and Override Output Field
The above configuration will rewrite the Request URI
from:
/product/123456789/someproductscreen
/product/12345
/some/other/url
to:
/product/{id}/someproductscreen
/product/{id}
/some/other/url
You mention you'd want to see /product/warranty
. This would obscure the edit. My suggestion is to leave a placeholder with the edit. I use {id}
but it could be any string, ie. <product id>
Regular Expressions are used by GA Filters, in the above example we used regex to match a product ID that is all digits. We did this using the regular expression:
^(/.*/)(\d{3,})(.*)
This is true when Request URI has root folder (/.*/)
followed by three or more digits: (\d{3,})
Finally, we capture the remainder of the URI using (.*)
. We used groups so we can access the values in a later step.
GA Advanced Filters can persist groups extractions from Field A
and Field B
. We use this feature to rebuild a Request URI
using the Output To -> Constructor
. Below is an example of condensing dynamic Ids to a static string:
$A1{id}$A3
$A1
will extract 1st group from Field A
. $A3
would extract the third group from Field A
if it were to exist. {id}
is a static string that is a placeholder for the dynamic value.
If your product id was a mix of alphanumeric, then we'd simply need to find a pattern that matched. You didn't provide any examples of ID, so here are a few examples of common ID patterns found in URLs:
[A-Z]-\d+ // matches Z-764537389
\d{4}-\d{3}-\d{2} // matches 1234-123-12
Easy mode right? What about if you have a RFC4122 compliant UUID in the URL you need match? No problem:
[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}
// matches 0df98a02-c438-4c57-8d1c-2f6041804e2c
Note: GA Advanced Filter Regex is case insensitive by default, this can be overridden in the filter settings.
Upvotes: 1
Reputation: 1172
Here https://regex101.com/r/kRUJnU/1
Start playing with this tool it ll become really helpful on the future since personalized filters with regex matching and capturing groups are REALLY important in GA.
EDIT: How to go from regex101 to GA.
In the image below you can see how i deleted the last part of URLs when they are something like:
www.mysite.com/vuelos/carrito/checkout/46787654567898765
Or something like:
www.mysite.com/vuelos/carrito/46787654567898765
Upvotes: 0