Skip to Content
Main Content

Hiker Looking Out Over Mountains

Fred Pike

Managing Director & GA/GTM Practice Lead

Fred is Google-certified in Google Analytics (GAIQ) and Google AdWords. He is also certified in Conversion Rate Optimization (CRO) through Conversion XL. Fred is passionate about finding the best ways to drive traffic to websites, making sure visitors find what they are looking for, and making sure Google Analytics and Google Tag Manager track everything correctly. 

Helping clients use data to make their website better? Man, that is a great gig!

GA4 Setup Tips

The (non-) Definitive Guide

December 20, 2020 | Fred Pike, Managing Director & GA/GTM Practice Lead

14 Minute Read

Updated: Dec. 20, 2020 
Originally Published: Oct. 21, 2020

Google Analytics 4 - GA4 - came out of beta on October 14, 2020 and has been on a tear ever since.  Every week brings new updates and improvements.  It's an incredibly fun time to be working with GA. 

GA4 is easy to set up and it offers great insights with even a plain-vanilla installation.  However, as with any tool, there are extra steps  you should take to ensure you’re maximizing the GA4 setup for *your* website.

This guide is what I’ve discovered so far. I’ll keep adding to this post as I find more must-have setup tips.

And as the Google blog will remind you: you’re an early adopter! Expect the tool to keep changing quickly.



Tip 1: Hostname Filter

A hostname filter has been an essential part of a good GA setup for years. 

The hostname filter verifies that a user is on your website when their visit is recorded. It will block both spam traffic and traffic from your test, staging, or development environments.

If you’ve already set up a hostname filter in your Universal Analytics (UA) account, you may think you can apply it to your GA4 property.  But no – none of the UA filters will work in GA4.

UA filters can't be applied to GA4.

GA4 does collect the hostname – it’s part of every event (page_view, scroll, etc.).  

Like many of the dimensions GA4 collects, it’s not easy to find the hostname in the GA4 UI, but if you search for “hostname”, you’ll find the “Top Hostname by Users” Insights card.


In my case, clicking on that Insight showed me:

  • the valid hostname (labeled 1 in the image –
  • invalid hostnames (labeled 2 – they’re all different test environments)

How to create a hostname filter in GA4

So far, there’s actually no way to create a valid hostname filter in GA4. But you can create one in Google Tag Manager (GTM). 

In my case, I created a variable in GTM – a super-simple Lookup Table which checks the hostname (1). If it’s (2), then I output the GA4 Measurement ID (3). 

This Lookup Table variable is then used in my GA4 configuration tag for the measurement ID:

Setting up a GA4 hostname filter with more than one hostname

It's not unusual to have more than one valid hostname.  You may have separate domains for your marketing-automation tool, your payment processor, your cross-domain sites, etc.  

You could still use a Lookup Table in GTM and add an additional row for each valid hostname.  Or you could us a RegEx table. 

I like RegEx tables, particularly if you have subdomains to work with.  Here's what a GTM RegEx table would look like:

And then, of course, you would change the GA4 Tag to use the RegEx table.

Note: GA4 can be configured either via gtag (the Global snippet) or GTM. I configure everything through GTM (and recommend it in almost every case). 

If you do use gtag, you won't be able to set up this type of hostname filter; it's only doable through GTM.

Other ways to see the hostname in the GA4 UI

At the beginning of this section, I talked about the Insights Card "Top Hostnames by User". 

By default, that's the only way to see your hostnames, and you can't change the date range on that card. 

If you wanted to see the hostnames that have been collected, you have two choices:

  1. Look at the GA4 data in BigQuery.  I'll talk about that in the BQ tip, below.
  2. Register "hostname" as a custom parameter.  If you do this, and wait 24 hours, you'll see the hostname available in the Analysis Hub.

Register "hostname" as a custom parameter

Go to "Events / All events" (A) and click on "Manage Custom Definitions".


 Click on "Create custom dimensions".


Enter "hostname" as the parameter name.  Change the custom dimension name, if you want. (Tip: leave it as hostname.)

Wait 24 hours.  (This is the worst part.  I hate waiting 24 hours.)

Go into the Analysis Hub, click on the "+" for dimensions (A), search for "hostname" (B) and click "Apply.

"Hostname" will then show in the list of dimensions.

You can drag the "hostname" dimension to a row, adjust the date range, and see the hostnames that have been collected.  This is where you can look to verify which hostnames should be allowed, and which blocked.


In Universal Analytics, the hostname filter is set up in the “Filters” section in Admin and applied to a view. GA4 doesn’t have the same construct, but with a fairly simple tweak to GTM, you can build your own hostname filter. Well worth doing.

A word of caution, though: make sure to *test* your hostname filter, otherwise you might inadvertently block valid traffic.  As we saw, a  valid hostname filter will include your main domain and may also include separate domains for your marketing, blogs, cross-domain sites, etc.

(back to index)

Tip 2: When You Create a New GA Property, set up both GA4 AND Universal Analytics (the "old" GA)

If you’re creating a new GA property (which you do in the GA / Admin section), it may seem like you can only create a GA 4 property (1).

But no! Click on “Show advanced options” (2).

In the advanced options, you’ll see you can toggle the switch for “Create a Universal Analytics property” (1). I recommend doing this.

I would create both a GA 4 and UA property (2).

(As another tip, go ahead and set up the UA property using my 10 GA Admin pro tips.)

I think you're well served to have both GA4 and UA running at the same time.  You can compare what you're getting between the two versions, to make sure your GA4 set up is done correctly.  Also, many of the third-party tools which can read and integrate GA information rely on using "views" (old GA), not "streams" (new GA).  Examples include Moz and Screaming Frog, but there are many more.  The tool vendors will catch up - probably quickly - but in the meantime you don't want to lose that integration.

(back to index)

Tip 3: Check Your Site-Search Settings

GA 4 will track several user interactions by default: page views, outbound links, downloaded files, scroll, video plays, and site-search terms. Those site-search terms are a great insight into your website visitors – they’re typing, into your website’s search box, exactly what they’re looking for.  You definitely want to capture those.

Different websites use different conventions to indicate a search term. Some use the word “query” to show that; other common examples are “s” or “keyword”.

To see what your website uses, go to the search bar and type in something, then look at the URL. You’ll see something like this:

If the word or letter your website uses to designate a search term is “q,” “s,” “search,” “query,” or “keyword,” you’re in luck. Those are all covered by the default GA4 setting.

If you have something different, like we do on the Northwoods website, you have to make an adjustment.  The phrase that designates a search term on our website is “Search_Keywords”.

If you don’t have one of the default search terms, let’s walk through how to make sure your search terms are being tracked.

To do these steps, you will need “Edit” rights in your GA4 account.

1. Go into the GA 4 Admin screen and click on the “Data Streams” option.

2. Click on the right arrow on your Web property.

3. In the “Enhanced measurement” window that opens up, click on “Show advanced settings” under Site search.

4. You can see the default search term parameters that already exist (in box 1). In box 2, type in the term or letter that your website uses to designate a search term. In Northwoods’ case, that’s “Search_Keywords." Then “SAVE” your work.

5. That's it! From this point forward, any search terms entered onto the site by your users will be captured.

(back to index)

Tip 4: Check your "Data Retention" Settings

While you’re in the GA 4 admin, go to “Data Retention” under the Data Settings Option.

By default (I think), the data retention is set to "2 months."

You probably want to set that to the other option, 14 months.

Also: Note the toggle for “Reset user data on new activity." By default, that’s on, which makes sense. It just means that regardless of which limit you choose (2 months or 14 months), each time a user comes to your website, the clock resets on when their data will be deleted.

Make sure to "Save" your changes!

(back to index)

Tip 5: Create Custom Insights

Here’s the best tip so far – not only because some day it’ll warn you about something catastrophic happening on your website, but because it’s kind-of hidden.

GA4 relies on machine-learning (ML) insights to supplement the stripped-down UI. Got something weird happening on your site? Ideally, an insight will report on that anomaly. But there are also some custom insights you'll want to enable.

The insights are available in a couple of places, including on the home page (1). Go ahead and click on “View all insights” (2).

In the next page (home / insights), click on "Create."

You’ll see a list of four “custom insights," all four of which could be important (depending on your website). But one of them will be important for all websites – the “Anomaly in daily views” (1). Here’s where you can set up a notification, which could be e-mailed to you, letting you know about anomalies in page views – e.g. you had zero page views today. I bet something’s broken!

Go ahead and click on the “Review and create” link (2).

Now you have a choice of specifying exactly what you want to be notified about. I can’t tell you how happy this makes me. It’s a wonderful practice to set up notifications when things are going wrong on your website. Most people don’t do this (it’s done through custom alerts in the older version of GA), but GA 4 makes it very easy to set up. So easy, in fact, that I would accept the default of “Has anomaly." I think GA 4’s ML will be able to figure this out just fine. I would for sure create the “daily views” custom insight; you can decide if it makes sense for your website to also enable the other custom insights.

Even better – you can create your own custom insights from scratch.

As small as these custom insights may seem, this is one of my favorite little features of GA 4. I love proactively setting up alerts and it’s so frickin’ easy to do here. Nicely done, GA 4 team!

Specify the e-mails of the people you want notified:

When you’re all done, go ahead and press the “Create” button.

When an anomaly happens, you'll get an e-mail like this one, which I got the day after I set up the hostname filters in tip 1:

At some point in the future, when that anomaly fires and you’re able to go in and resurrect your website tracking because something stupid broke – please send me an e-mail and thank me!

(back to index)

Tip 6: Create Filters for Internal Traffic (but don't make them live)

I know what you’re doing – you’re looking in the admin area to set up your filtered view, raw view, and test view.  Right? Right?

(How do I know? Because only well-trained GA nerds would be reading this far into this blog post.)

Well, stop looking – there are no views and there’s no way to set up those views. At least as of right now. (A Google webinar I  attended recently said they would be coming at some point - so don't lose hope.)

There are filters, though, which you can use for either internal traffic or dev/test environments. Let’s walk through setting up an “internal traffic” filter.

Start in the admin section of GA (1) and click on the “Data Streams” (2).

Click on the web stream for which you’ll create the filters:

Go to "Tagging Settings":

Click on "Define Internal Traffic":

Click on "Create":

You’ll now have your first opportunity to start adding an IP address (or multiple - up to 10 rows). Put in the name of the configuration (1), the match type (2), and the IP address (3).  

There are multiple match types, but no RegEx option(!!).  I can't tell you how painful that omission is.

Here’s a sample configuration filled out for my home IP address:

IMPORTANT: Even though GA 4 uses “Anonymize IP” (dropping off the last octet in the IP address), for the “IP Address equals” option, you have to use the full IP address.

Save your changes. You’ll now see that configuration show up in your list of “internal traffic” rules.

Next, go back to “GA Admin / Data Settings / Data Filters”.

Make sure the Data Filter for Internal Traffic is set up. (I think this happens by default; I don’t think you have to do anything. But check to be sure.)

Now What?

Now you wait patiently. You won’t see any results of this filter until the next day.

The next day, you can use the dimension “Test data filter name” to look for traffic that is labeled “internal” or “not set” (i.e. external). Here is an example of the filter:

And here's where you can use it in a report in the UI:

You could also use it in the Analysis Hub, as a dimension for any of the reports you build.  As a simple example:

  1. Specify a date range which includes the internal-traffic being set up.
  2. If the dimension is not there, click the + button and add the…
  3. “Test data filter name” dimension. 
  4. Choose an Exploration report.
  5. Drag or choose the “Test data filter name” to the “Rows” section.
  6. You’ll now see the internal traffic and the not-set traffic.

Expect changes with the internal traffic filter

The IP filtering is so limited in GA4 compared to UA that I have to believe it'll be updated soon.  The lack of RegEx in the match type is perhaps the biggest limitation right now - hard to see how to create an "internal traffic" channel for a large multi-site organization without having RegEx.  Plus, of course, not having views available is painful. My personal opinion is that we'll see changes here in the near-term future.

Make the Internal Traffic Filter Live?

I think it’s great to set up the internal traffic filter – but leave it in test mode. You can always do your analysis and exclude that segment, either in the GA4 interface or in Big Query. But since there is only one “view” in GA 4, I’m reluctant to start excluding traffic that you’ll never get back. Mess up that IP filter and the data is gone forever – there’s no raw view on which to fall back.

But if you *really* want to make the internal-traffic filter live

Here's how. 

  1. In the GA4 Admin screen, choose Data Settings / Data Filters
  2. Click on the three dots on the "Internal Traffic" line.
  3. Activate the Filter

You'll get a warning screen.  Pay attention to it.  Have you really tested the internal-traffic filter?  Are you sure?  if so, choose "Activate filter".

You'll now see that the internal-traffic filter is active.

Again, my strong recommendation is NOT to make it active.  Without a raw view to fall back on, it's too risky to start excluding traffic, particularly since you can easily filter out the internal traffic in the GA4 UI, in BigQuery, or  in Google Data Studio.

(back to index)

Tip 7: Label Your Analysis Hubs Reports

Here’s a simple idea – make sure that every report you create in the Analysis Hub has a name.

Otherwise, once you start creating reports, you’ll be hard pressed to remember what’s in the myriad “Untitled Analysis” reports.

(back to index)

Tip 8: Set up BigQuery Integration

Honestly one of the most impressive features of GA 4 is its built-in integration with BigQuery (part of the Google Cloud Platform). You can set up automatic export of GA 4 data directly into BigQuery and specify whether you want to do that once per day, or virtually instantaneous. The “once per day” option is, essentially, going to be free (depending on how much data you have). For the “instantaneous” exports, you’ll have to set up a billing account.

I won’t try to recreate the excellent blog post that Charles Farina wrote on setting up BigQuery – go ahead and follow his steps and in about a day you’ll start getting data like this, which clearly shows the event / parameters structure of GA 4:

Get Expert Tips