Search code examples
google-analyticselectronfirebase-analyticsgoogle-analytics-4measurement-protocol

Is there a way to specify the application version with the Google Analytics 4 Measurement Protocol?


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.


Solution

  • 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.