大网数据广告活动
网站运营与故障问答

Looking for advice on how to log redirects in Google Analytics

· 52CE 我爱测

We have a number of redirecting pages in our CMS. These do not redirect across domains (such as vanity URLs), they are just to catch visits to old URLs that have changed. The redirects are not always landing pages, some of these …

问题原文

原帖链接 · Peter · CC BY-SA 4.0

We have a number of redirecting pages in our CMS. These do not redirect across domains (such as vanity URLs), they are just to catch visits to old URLs that have changed. The redirects are not always landing pages, some of these redirects are visited in the middle of a session.

Technically, these pages return HTTP 301 without content. There is no possibility to use JavaScript code on the redirecting page, and not any custom server side code either.

Using Google Analytics, I wish to log both which redirects have been used, and where visitors came from. I don't want the redirect to trigger a new session start. And I don't want to pollute the list of visited pages with custom URL parameters.

Solutions we have tried:

  1. Plain redirects (/old-url -> /new-url) -- Source and Previous page path information is maintained, but it is impossible to see which pageviews came from redirects.
  2. Custom parameter (/old-url -> /new-url?redirect=/old-url) -- This makes all redirects identifiable and keeps all information, but pageviews are logged under a different URL.
  3. Campaign parameters (/old-url -> /new-url?utm_campaign=redirect&utm_medium=web&utm_source=/old-url) -- This logs pageviews under the correct url, and makes it possible to identify all redirects, but all source information is lost and the redirect triggers a new session.

There are two other solutions that I am considering, but I do not know exactly how to do this, and if it will even work for me.

  • Run some custom JavaScript on the new URLs, that identifies a redirect and logs some measurable statistic in Google Analytics.
  • Create a custom filter in Google Analytics that identifies a redirect (probably by a URL parameter?) and transforms this into some measurable statistic.

已采纳解答

原帖链接 · Peter · CC BY-SA 4.0

In the end, I managed to do this in GA, but it is clear as some already highlighted that GA is not the best tool for this.

My approach requires editing the redirect URLs, setting up a Custom Dimension and two Filters, and preferably also a Custom Report.

The first step is to make sure all redirects contain a query parameter that contains a URL or name to identify the redirecting page. For example /old-url redirects to /new-url?redirect=/old-url or /new-url?redirect=name-for-old-page.

Then in GA create a Custom Dimension through Admin > Property > Custom Definitions > Custom Dimensions. Name it something like "Redirect from" and give it hit scope.

Then find the Filters in the View administration and create an Advanced Filter that extracts from Request URI with the code redirect=([^&]*)&? and outputs to the custom dimension with $A1.

Finally create another filter to remove the query parameter, this is a search-and-replace filter that replaces ([\?&]redirect=[^&]*$|redirect=[^&]*&) with nothing.

Wait a day, and then page reports will have a Secondary Dimension available that will show the redirects, while reporting the correct URL (without query parameter) and maintaining visit and path information.

For digging deeper it is required to set up a Custom Report with for example Pageviews as Metric and Page, Redirect From, Previous Page Path and Source as Dimensions. I'm not sure this is 100% valid, because my report shows pages for Previous Page Path that actually don't contain links to redirect pages...

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。