Vlad
Vlad

Reputation: 55

How to set device information when passing an event to GA4 via Measurement Protocol?

I'm using the Measurement Protocol to push e-commerce events to GA4 and it works well. However, some time ago, I noticed that all transactions are marked as desktop (even those that were actually placed from a mobile device).

Is there a way to set device information (namely 'Device Category') when sending an event? In GA3 it was possible to achieve this via user-agent passing, but this does not seem to be relevant for the new analytics.

I tried experimenting with different GET parameters (like ua) when sending an HTTP request, but it didn't work. Example: https://www.google-analytics.com/mp/collect?measurement_id=GA_MEASUREMENT_ID&api_secret=GA_API_SECRET&ua=UserAgentString

Upvotes: 1

Views: 1659

Answers (2)

Trip
Trip

Reputation: 27114

Create a custom definition called "device" and pop that bad boy in your call like so :

{
        client_id:,
        events:    [
          {
            name:,
            params: {
              engagement_time_msec:,
              user_agent:,
              device:, # <---- Boom!
            },
          },
        ],
      }

Upvotes: 1

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117254

The measurement protocol for GA4 is extremally limited. You cant set Device Category nor does it let you set user agent.

This is still in beta we just need to wait and see if they open it up more.

Upvotes: 3

Related Questions