Search code examples
google-analyticsgoogle-analytics-apigoogle-analytics-4

Is it possible to pass `host_name` via Measurement Protocol for GA4?


I'm using the Measurement Protocol to push e-commerce events to GA4 and it works well. The screenshot shows an example of the data I'm passing from the backend.

Additionally, I'd like to pass host_name parameter, however, looking through the official documentation I didn't find any information on support for it. Is there a way to pass this as well?

In the case of the Measurement Protocol for Universal Analytics, hostname can be passed by declaring it as dh (eg: 'dh' => 'www.domain.com'), but this does not work with GA4.

Appreciate any help, thanks.


Solution

  • Please have a look at this document API Dimensions & Metrics, Depending on your requirements you may use fullPageUrl which is a dimension that returns the host-name, page path, and query string for web pages visited.

    Or you can use page_location Automatically collected events. Just remember that if you want to use page_location you should create customised dimension named exactly page_location.

    In order to create custom dimension (Creating Custom Dimension and Metric), log into your analytics.google account and then

    • Access the “Configure” menu in GA4 and click into “Custom definitions”.
    • Click to create a new dimensions.
    • Choose the scope of the custom dimension (user or event), which in this case is Event.
    • Name your custom dimension, which in this case in page_location.
    • Define the Event parameter of your custom dimension, which in this case in page_location.
    • Save your custom dimension. It takes 48 hours for Google to effect the modifications. enter image description here

    This tutorial also explains about how to See Full Page URLs in Google Analytics 4.

    GA Full Page URL