We received this question recently from Kevin Churchill, who manages an AYSO chapter website:
New to Google Analytics and I was wondering if there is an easy way to rename a title page to make it easier to understand the metrics. How can I change a code url string into a simple name?
What seems like a simple question can be complex depending on the actual URL. URL rewriting needs to be handled with care and caution. There are a few preliminaries you should cover before jumping into rewriting your URLs.
Step 1: What’ll be Affected? The first thing you need to do before jumping in to rewrite your URLs is to make note of what this might affect. Two must do’s:
- Protect your data – Make sure you do all rewriting first in a separate test profile. Why? If you make a mistake on your live data, it’s a permanent mistake. There is no ‘undo’ or ‘revert’.
- Goals, Advanced Segments, Filters… – If the original URLs are used in any Google Analytics goals, remember to modify these. If you don’t modify these, your goals will be inaccurate. Ditto for Advanced Segments, Filters, etc.
- Learn how Profiles work. Create a profile in which you’ll test your rewritten URL. An easy way to create your test profile, is by using the feature that allows you to copy a Google Analytics profile into a new one.
- Learn how Profile Data Filters work and determine which type(s) of filters to use. Search and Replace and Advanced Filters are the most common types used to accomplish this task. Here’s an example using the Search and Replace filter type:
Step 3: Put your knowledge to work and rewrite those URLs:
- Create and test your filter. Did you get the results you expected?
- If you are using URLs as goals, set these up to use your new URLs.
Be aware that there will be some tradeoffs, mainly inconveniences. Goal management is more complicated, for one. And the rather handy ability to launch the page being analyzed from the All Pages report will no longer work. Clicking on the ‘view’ icon (in the image below) will result in a 404/page-not-found error.
Depending on your specific situation, there may be additional complexities or inconveniences. Weigh the pros and cons. Choose what best fits your situation.
Hi there thanks for your nice post. I was just looking for some help with the following topics and i am not sure wheter the suggested way would help for rewriting URIs. Here is the background. We changed our URL structure from /product/ to category/product. My target ist to analyze i.e landingpages & visits. Therefore i need to tell GA that i would like to match the former Url structure to the new structur. Would this then look like the following: search string /product/$ to ^/category/
Looking forward to your help
Alexander
Hi Alexander – If you are trying to make the URL structure the same so that you can compare the old and the new landing pages, you will have to edit the new structure and make it match the old. You cannot change old data to have it match the new URL structure.
If the new URL structure is “/category/product” and the old structure was “/product/”, then the rewrite would be to select “^/category/” and change it to “^/”.
Make sure you test this in a new, separate profile, not your live data profile.
This will work if you have just a few categories and products. Do you have many categories and products?
Thank you for visiting and asking this question. You may want to consider Advanced Filters, so we’ve written a post about this.
Thanks for this great post! I’m having trouble getting my rewrites to work, and I think it has to do with the usage of “\” versus “/”.
I want to rewrite example.com/index.php?option=com_content&view=article&id=439&Itemid=617&ibp-adgroup=sump_pump to be just /sumppump
So in the first I have /index.php?option=com_content&view=article&id=439&Itemid=617&ibp-adgroup=sump_pump and in the second bar I have /sumppump. I’m unclear what exactly the “\” signifies. Any help you could offer would be greatly appreciated. Thank you so much!
Hi Alex,
For a really great explanation about Regex in GA, check out this Google Support article: https://support.google.com/analytics/answer/1034324?hl=en. Click on the blue hyperlinks in the table to take you to more detailed explanations on the various characters that have special meaning, such as “\”.
The “/” doesn’t have any special meaning and is just a slash.
The “\” does have meaning. The “\” signals that the next character after “\” should be take literally or at face value.
For example, the “?” means “match to zero or 1 of the previous item”. But if you actually are trying to match “?” as just a question mark, you need to add a “\” in front. Therefore, “\?” means the “?” is just a “?” and is not to be used to match to zero or 1 of the previous item.
About your example, if you are trying to rewrite the URL in Google Analytics so that you extract the value for “ibp-adgroup” and make it the page name, rather the search and replace option, I would used the advanced filter, as follows:
Input and output fields will be “Request URI”.
Expression in the A Input field: ^(.*)(ibp-adgroup=)(.*)$
Expression in the Output field: /$A3
What the above says is:
1) Group the Request URI in the A field into 3 parts.
2) Take the 3rd field (A3), which is everything after “ibp-adgroup=”, and put it after a “\”.
Using your example, the 3 parts of Input field A will be:
A1: example.com/index.php?option=com_content&view=article&id=439&Itemid=617&
A2: ibp-adgroup=
A3: sump_pump
The output field, or your new Request URI value, will be \sump_pump.
If you want to remove the “_” from “sump_pump”, you’ll need an additional filter to take that out.
Hope this helps!
Thank you so much for the quick response! I really appreciate the help. the “\” meaning makes complete sense now. However, can I not just use the search and replace filter? I’m unclear why I can’t search for the original url and simply type in the replace as “/sump_pump”
Okay perhaps this is a clearer example of my confusion. If I take /index.php?option=com_content&view=article&id=439&Itemid=609 can I use the search an replace to simply replace that entire thing with /sump_pump
Hi Alex,
Yes, you can just use search and replace.
For search and replace filters, the input is a regex but the output is just the replacement copy.
Input: /index\.php\?option=com_content&view=article&id=439&Itemid=609
Output: /sump_pump
Here’s the support doc for future reference: https://support.google.com/analytics/answer/1034834?hl=en
Thank you again for all your help. I feel like I have a much better understanding of all of this now.
Glad you found the discussion useful. Regex is definitely like learning any new language. The more you use it, the more comfortable you’ll be with it.
Hi, I have seen some Urls in Google search results which are like “example.com > file1 > file2”. Google itself show Urls for their own for any Google related search like “example.com > file1 > file2”. While for my website urls in Google results are like “example.com/file1/file2”.
How i can replace / to > in Google search results urls for my website.
Thanks in advance……
Hi Ashish,
Thanks for your question. Unfortunately we cannot help you.
What you are describing appears to be text in a breadcrumb trail, not a URL, as URLs cannot contain “>”. As we do not build websites, we cannot help you with breadcrumb trails. We suggest that you contact a local web developer/design company and describe to them what you want.
Good luck!
Sir received following message from google analytics..
Property infinetsoft is receiving data from redundant hostnames. Some of the redundant hostnames are:
infinetsoft.com
http://www.infinetsoft.com
Redundant hostnames are counted as separate rows in reports, so hits that are going to the same page on your site from different hostnames will be split into multiple rows. With data split across multiple rows, traffic to specific pages will appear lower than it actually is.
To avoid this problem, consider setting up a 301 redirect from one of your redundant hostnames to the other, or create a search-and-replace filter that strips “www.” from hostnames.
for example my url:
1.infinetsoft.com/Post/How-to-create-autocomplete-textbox-with-database-in-asp-net-c/1254#.V-_R8Ih97cs
2.http://www.infinetsoft.com/post/How-to-create-autocomplete-textbox-with-database-in-asp-net-c/1254#.V-_SA4h97cs
How to rewrite it?
Hi Mohamed,
I recommend two actions:
(1) Search and replace hostname “www.infinetsoft.com” to “infinetsoft.com”, or vice versa, so that you aggregate for hostname.
(2) Search and replace “/1254#(.*)$” with just blank
Item (2) assumes that you URLs always include “/1254#”. If that is not the case, and the numbers also change, you will have to use a custom Advanced filter instead of the simpler Search and Replace Filter.
We received the following question from Jeremey via our “Contact Us” form. As others may be interested in the answer, here’s the question, followed by my answer:
Hey, I found your post on rewriting URLs informative, but I am still missing something and wondering if you could help me. We just redesigned our site and changed our URLs.
I am trying to figure out how to combine the two URLs
The old urls use to be
mycompany.com/publications/wp/
and the new URL is
mycompany.com/publications/working-papers/
Do you know how I would do that? But in thinking about this more, does it actually matter since we changed the URL with the new site and this won’t apply to historical data?
Thanks!
Hi Jeremey,
For your situation, I suggest that to avoid future confusion, don’t rewrite the URL because:
(1) the old data is associated with the old URL and you can’t change it
(2) if you rewrite the new URL to the old URL, unless you have an offline cross reference, folks who need to look up data for the new page won’t know what page to look up.
Two suggestions:
(1) If the “Page Title” of the new page and old page, are the same, use that to aggregate old and new data. The “Page Title” is automatically populated from the TITLE metatag in the head area of your page.
(2) Create a new custom dimension (you have 20) to hold the old URL and upload the pages using data import. See these Google support articles for:
– Custom Dimensions: https://support.google.com/analytics/answer/2709828?hl=en
– Data import: https://support.google.com/analytics/topic/6066740
Hope this helps!