Understand Cross-Site Traffic in Google Analytics with Document Referrer


If you have multiple domains or subdomains, the best practice for attribution in Google Analytics is to ensure that sessions don’t restart when users cross from one domain or subdomain to another. Consolidated sessions – and good campaign tagging – give credit where credit is due to your marketing efforts, and make it easier to optimize your marketing dollars.

Unfortunately, consolidated sessions and campaign tagging can sometimes obscure what really happened while a user interacted with your website. Sometimes you want a closer look at page-to-page details, and you discover that the best practice (necessarily) wiped them out.

Our prescription: Document Referrer!

The document referrer – the page a user saw immediately before clicking to come to the current page – is easy to capture and super useful. You’ll reach for it again and again when you need to answer page-specific questions like:

  • How often did micro.mysite.com drive traffic to store.mysite.com?
  • What pages on (or not on) mysite.com have broken links that lead to 404 pages?
  • What pages are sending campaign-tagged traffic to mysite.com/special-page?

If you are not intentionally capturing the document referrer – and our favorite way is in a dedicated custom dimension – then answering these questions with your Google Analytics data will be more difficult or, in some cases, impossible.

By default, Google Analytics will capture and store the document referrer for sessions that come from a referring source – that is a session that is not from a campaign, advertisement, or search engine. This will be stored for the session however, and doesn’t give us information about traffic that moves around between our own domains and subdomains.

Our solution is to make this available for every page. Follow our three simple steps to get started!

Step 1: Create the Custom Dimension

In your Google Analytics property settings, create a new custom dimension. Name it Document Referrer and select Hit scope. Make a note of the index number.

Create hit-scoped custom dimensions in your GA property settings

In the screen shot, these custom dimensions have index numbers 1 & 2. Yours may be different.

Step 2: Populate the Custom Dimension Values

Choose Option A or Option B to populate the values of your custom dimension.

Option A: Google Tag Manager

If you have Google Tag Manager, add custom dimension 1 (use the index number of the custom dimension you created) to your Pageview tag under More Settings. For the value, enter the built-in Referrer variable, as shown below. If you have more than one Pageview tag, use the new GA Settings variable to add it to every tag at once!

For the referrer hostname, you’ll need to create a new user-defined variable. The URL Variable makes it easy to grab this piece of information.

Referrer Hostname Google Tag Manager

Option B: View Filters

If you don’t have Google Tag Manager, use a filter to grab the Referral field and write it to the custom dimension named Document Referrer.

Use an advanced filter to write the Referral field value into your custom dimension

Referral is one of those secret fields in Google Analytics, like IP Address, that Google uses to process your data, but doesn’t reveal in your reports. It contains the same info as the built-in Referrer variable in Google Tag Manager, i.e. the page someone saw right before clicking to come to the current page.

For the Referral Hostname, we can capture just the first part of the Referral using a regular expression.

Google Analytics Filter Referrer Hostname

This method is great and doesn’t require any changes to the tracking on your website! However – keep it in mind that it will only populate Custom Dimensions for the Views that have the new filters applied. Make sure you apply the filters to all Views where you might need this information.

Step 3: Add the Custom Dimension to Reports

And now the best part: Reveal the data that was previously hidden!

Decide what page or set of pages you want to analyze, and search for those in the All Pages report in Google Analytics. Then add a secondary dimension of Document Referrer.

In this example, I’ve revealed which pages are driving traffic to a page on another subdomain, by filtering both columns of the report. Here I can see how prospective students may be finding my new page – learn.mystate.edu/find-your-degree-program – from other university pages.

Add a secondary dimension to the All Pages report

It’s easy to change the above example to do even more! Filter the report to show your 404 pages, or your campaign landing pages, or any page of interest – and you’ll see all the referrers that sent your users there.

Take a look at how many times a subdomain sends traffic to your main domain, or vice versa.Google Analytics Hostname and Referrer Hostname

Other fields in Google Analytics seem promising, but do not deliver the same info as Document Referrer. Previous Page Path gives you the previous page only when your tracking code was on that page, and only when you’re looking at a view that includes both the previous and current page. Referral Path gives you referrers from other sites (not your own), only for the first page of a session, and only when medium=referral.

Document Referrer and Document Referrer Hostname always give you the previous page, no matter how your code or views are configured, regardless of whether it’s your site or not.

If you’re not capturing document referrer, add it today – before someone asks you a question and you wish you already had it!

Dorcas Alexander is a Manager for the Analytics & Insight department. Her path to LunaMetrics followed stints in ad agency creative, math, and computer science. Dorcas has a master's degree in language and information technologies from Carnegie Mellon University, where she helped build precursors to a Universal Translator. One of the top-rated tournament Scrabble players in Pennsylvania, Dorcas has an insatiable drive to compete and win.

  • app localization

    well explained in detail.

    thanks for sharing.

    app localization

  • Jared Peacock

    Thanks for sharing – throughout the post I was wondering why we need this piece of data when Previous Page Path exists but you answered it toward the end. However, couldn’t you avoid taking up a custom dimension slot (limited by standard GA users) by using a clean implementation with cross-domain tracking? Where cookieDomain=auto and allowLinker=true along with properly configured views and filters, in theory you should capture the Previous Page Path regardless of the property (as long as it carries your tracking code), right?

    • Dorcas Alexander

      Hi Jared, I used to think so! And it’s true for certain GA setups. But I have had more than one client now, where we have cross-domain tracking implemented, who want individual owners of subsections of the overall site to have an individual view just for their subsection. The second part of my caveat – “only when you’re looking at a view that includes both the previous and current page” – doesn’t apply for these types of GA views. The owner of SectionA.mysite.com wants to see how many times SectionB.mysite.com sent them traffic, and Previous Page Path in the Section A view will only have URLs for Section A, never URLs for SectionB. Where SectionB would have been the Previous Page Path, GA will show (entrance).

    • Tyler Miller

      The problem I’ve run into with using Previous Page Path with cross domain tracking is that you can’t see the hostname. So, if you want to see how people go to “sectionA.mysite.com/pageA” you can see the previous page path was “/pageB” but you can’t tell if that’s “sectionB.mysite.com/pageB” or if it’s “secionC.mysite.com/pageB”.

  • Vishal Pindoriya

    Great post! I need the original domains UTM values also.

    Does this solution capture the document referrer (&dr) ‘s UTM parameter values?


    Currently GA states no source:
    A person heads to xxxx.co.uk/?utm_source=apples and lands on this domain > yyy.com/

    Google debug states the full URL including the UTM paratmers is in the document referrer

    Will this also pass through?

    • Dorcas Alexander

      Hi Vishal, Yes! We are literally capturing the contents of the global JS document.referrer, which includes the utm parameters. GA only strips utm parameters out of the Request URI field to produce a cleaner GA Pages report. When utm parameters are in the Referral field (document.referrer), they are not stripped out.

  • SEO Courses in Lahore
    SEO Courses in Lahore Become certified SEO expert with our SEO training in Lahore.SEO courses in Lahore and Pakistan with practical projects.

  • Thanks for this post! Is there a way to save that custom dimension to persist for the length of the session? If a user comes to the site, I’d like to save the referral information, then as the user wanders around, and eventually converts (by clicking a button), I’d like to be able to trigger an event based on only conversions from referrals by a specific external site.

    • Dorcas Alexander

      You can write the value of the custom dimension into a cookie and control when it expires using LunaMetrics GTM cookie recipe. If you’re not using GTM, you can use the Javascript in the cookie recipe directly in your page source code – but you’ll need a little extra Javascript to handle what GTM does on its own. See our GTM cookie recipe here: https://www.lunametrics.com/labs/recipes/cookie-management/

Contact Us.

Follow Us




We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203


4115 N. Ravenswood
Suite 101
Chicago, IL 60613


2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187