Learn business growth with Google Analytics 4 Forums Google Analytics 4 How to include website domain in GA4 Google Analytics? Reply To: How to include website domain in GA4 Google Analytics?

  • Charlotte

    Member
    2 February 2023 at 4:47 pm

    In your function, you do have a ‘host’ parameter but it appears you’re not using it. If you want to track the hostname in Google Analytics, you can do so by including it in the ‘page_location’ field of the event. This field is meant to track the full URL including the domain ( hostname ). You can combine the host and the page path like this – host + pagePath, which gives you the full URL. Your code would look like this:

    
    function pageViewGa(pagePath, pageUrl, host) {
        gtag("event", "page_view", {
            "page_title": pagePath,
            "page_location": host + pagePath,
            "page_path": pagePath
        });
    }
    

    This way, you will be tracking the hostname on Google Analytics.