2

I'm trying to migrate from Google Analytics 3 to Google Analytics 4 in an Electron application. As the gtag method don't seem to work when the application is built (probably due to the app:// URL), I'm using the measurement protocol (we used the same approach for Google Analytics 3).

For now, sending events work, however I can't find a way to attach the application name and version to the events.

const gaEndpoint = `https://www.google-analytics.com/mp/collect?measurement_id=${measurementId}&api_secret=${apiSecret}`;

const body = {
  client_id: clientId,
  events: [event],
  user_properties: {
    app_version: { value: "1.0.8-test" },
    app_name: { value: "Test" },
  },
};

const response = await externalHttpClient.post(gaEndpoint, {
  json: body,
});

I tried several naming variants for the user properties (e.g: application_version or applicationVersion) but nothing seems to work.

In fact I'm not sure it is even possible to send an application version through the Measurement Protocol API as it is mainly design to enrich events sent through gtag or the Firebase library.

Tushar Gupta
  • 15,504
  • 1
  • 29
  • 47
clemp6r
  • 3,665
  • 2
  • 26
  • 31

2 Answers2

1

Application Name and App version parameters are a part of automatically collected events in GA4. You can't populate the existing parameters using measurement protocol yet. I say yet, as GA4 is evolving and there may be updates in the future.

For now, you can send your custom parameters for app_name and app_version (you can choose any name), then map the same parameters with custom Dimensions in GA4 UI. It is the only option available for GA4.

Tushar Gupta
  • 15,504
  • 1
  • 29
  • 47
  • Thanks. Do you have a source (official or not) that describes this limitation? – clemp6r Jun 12 '23 at 11:44
  • There is no official doc yet, but it's been tested with various clients. This is validated by 1. The official doc says these params are default: https://support.google.com/analytics/answer/9268042. 2. These parameters(app name and app version) are not listed by default when you go to GA4 UI and map a dimension. – Tushar Gupta Jun 12 '23 at 12:27
0

No.Device information is only available via automatic collection from gtag, Google Tag Manager, or Google Analytics for Firebase.

https://developers.google.com/analytics/devguides/collection/protocol/ga4

leohxj
  • 957
  • 9
  • 9