4

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.
  • 4
    Google Analytics isn't the right tool for this job. You should analyze your server logs for this. GA just doesn't do a good job with tracking redirects. – Stephen Ostermiller Oct 8 '18 at 10:52
  • @StephenOstermiller regrettably there are no server logs that I can access. – Peter Oct 16 '18 at 15:01
1

Google is only interested in tracking your page views, as this is what they are focused on providing to their search customers.

If your CMS doesn't provide for redirect link tracking, or there isn't already a plugin/extensin that someone has built to assist your CMS to do this, then use something else to track them.

There are sites you can sign up to that will provide you with redirect tracking.

Or you can source, or build, a simple javascript or PHP script which redirects the link and records redirects to a database table.

Both options allow for additional meta to be included in the tracking link.

1

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.