简体   繁体   English

如何在 Google Analytics 4 [GA4] vs v3 中跟踪自定义事件?

[英]How to track custom events in Google Analytics 4 [GA4] vs v3?

In Google Analytics v3 it was possible to send custom events right from the frontend of the application, like:在 Google Analytics v3 中,可以直接从应用程序的前端发送自定义事件,例如:

gtag('event', 'my_custom_search', {
  'event_category': 'custom_text',
  'event_label': 'custom_label',
  'value': 'custom_value',
});

In GA4 it's still possible to send predefined events, like search for example:在 GA4 中仍然可以发送预定义的事件,例如search

gtag('event', 'search', {
  search_term: '1234'
});

Now we want to send our custom events again.现在我们想再次发送我们的自定义事件。 So I simply tried this:所以我只是尝试了这个:

gtag('event', 'my_custom_search', {
  search_term: '1234'
});

Unfortunately the custom event doesn't show up in the realtime view.不幸的是,自定义事件没有显示在实时视图中。 I found this article to create custom events in the backend: [GA4] Modify and create events via the user interface .我发现这篇文章在后端创建自定义事件: [GA4] 通过用户界面修改和创建事件

My questions are:我的问题是:

  • Is it still possible to send custom events "on the fly"?是否仍然可以“即时”发送自定义事件?
  • Must we really create all events beforehand in the Google Tag Manager?我们真的必须事先在 Google 跟踪代码管理器中创建所有事件吗?

If the anser to the second question is yes , then this is a lot of extra work, because we have to define the events in the Google Tag Manager and also in our frontend.如果第二个问题的答案是yes ,那么这是很多额外的工作,因为我们必须在 Google 跟踪代码管理器和前端定义事件。

Current state, you'll have to name/configure them in GA4.当前的 state,您必须在 GA4 中命名/配置它们。 Be careful of the limits , as you can't delete them.请注意限制,因为您无法删除它们。 So no, you can't name them on the fly.所以不,你不能即时命名它们。

For your example, you'll want to keep it to the default "view_search_results" event, but augment via additional parameters , "type=custom"对于您的示例,您需要将其保留为默认的“view_search_results”事件,但通过附加参数“type=custom”进行扩充

As for your GTM question.至于你的 GTM 问题。 This depends on how complex your GTM setup is currently and how well your events fit into the GA4 default list of events.这取决于您的 GTM 设置当前的复杂程度以及您的事件与 GA4 默认事件列表的匹配程度。 Again you'll want to review and fit your existing events into the default events where possible and add new ones only after you've done the full review.同样,您需要查看现有事件并将其调整到可能的默认事件中,并仅在完成完整审查后添加新事件。

Implementation-wise, you might be able to reduce the number of tags by using a lookup table for existing events to map them to GA4 event parameters.在实现方面,您可以通过使用现有事件的查找表将它们 map 到 GA4 事件参数来减少标签的数量。

Edit: also you're referencing "gtag" a lot, it is different from Google Tag Manager.编辑:您也经常引用“gtag”,它与 Google 跟踪代码管理器不同。 If your current custom events implementation is done through gtag then the migration will be more manual.如果您当前的自定义事件实现是通过 gtag 完成的,那么迁移将更加手动。

The my_custom_search should be able to fire, however, you'll need to install gtag before running your custom code, which is to set up the measurement id with gtag . my_custom_search应该能够触发,但是,您需要在运行自定义代码之前安装gtag ,即使用gtag设置测量 ID。 You can reference google's document at here .您可以在此处参考 google 的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM