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.