Google Analytics 4 Measurement Protocol 中是否有指定应用程序版本的方法?

huangapple go评论67阅读模式
英文:

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 doesn'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 designed to enrich events sent through gtag or the Firebase library.

英文:

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.

答案1

得分: 1

应用程序名称和应用程序版本参数是GA4中自动收集的事件的一部分。 您还不能使用测量协议填充现有的参数。 我说“还不能”是因为GA4正在不断发展,将来可能会有更新。

目前,您可以发送自定义参数app_nameapp_version(您可以选择任何名称),然后在GA4界面中将相同参数映射到自定义维度中。这是GA4目前唯一可用的选项。

英文:

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.

答案2

得分: 0

设备信息仅可通过从gtag、Google Tag Manager或Google Analytics for Firebase进行自动收集而获得。

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

英文:

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

huangapple
  • 本文由 发表于 2023年6月12日 17:40:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455368.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定