azure-application-insights - 无法获取 `data-*-id` 属性以通过 ClickAnalytics 插件正确记录自定义事件名称

标签 azure-application-insights

我有一个客户端 React 应用程序,正在 appinsights 中进行检测,并且我正在使用 React 插件和新的 ClickAnalytics插入。一切正常,遥测工作正常,但是我无法使 data-*-id 自定义事件功能正常工作。

文档说:

The id provided in the data-*-id will be used as the customEvent name. For example, if the clicked HTML element has the attribute "data-sample-id"="button1", then "button1" will be the customEvent name.

我按如下方式检测元素(使用 Semantic UI React ):

<Button
  data-custom-id="AddDealButton"
  as={Link}
  color="blue"
  icon
  labelPosition="right"
  size="huge"
>

单击该按钮会导致记录自定义事件,但名称“AddDealButton”不会流过。我总是将 not_specified 作为事件名称:

Appinsights screenshot showing not_specified event name

阅读文档,有关于插件配置的警告:

If useDefaultContentNameOrId is false, then the customEvent name will be "not_specified".

所以我用这种方式初始化插件:

...
extensions: [reactPlugin, clickPlugin],
extensionConfig: {
  [reactPlugin.identifier]: { history: browserHistory },
  [clickPlugin.identifier]: { autoCapture: true, useDefaultContentNameOrId: true }
}

...但是这个名字没有通过。我配置错误吗?知道我做错了什么吗?

最佳答案

事实证明问题出在我上面显示的初始化配置中。应按如下方式设置:

...
extensions: [reactPlugin, clickPlugin],
extensionConfig: {
 [reactPlugin.identifier]: { history: browserHistory },
 [clickPlugin.identifier]: { autoCapture: true, dataTags: { useDefaultContentNameOrId: true } }
}

生成的事件名称不是从我的 data-custom-id 中提取,而是从 Button 组件的 Icon 元素的内容中提取,因此事件名称变为“Create new deal” ,但我能弄清楚。

Microsoft 的文档显示了 npm 安装方法与“snippet”方法的不同示例,因此我错过了 dataTags 示例。

关于azure-application-insights - 无法获取 `data-*-id` 属性以通过 ClickAnalytics 插件正确记录自定义事件名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68549201/

相关文章:

.net - 如何在 Application Insights 中隐藏客户端 IP 地址?

azure - 如何检查我的 azure 网站实例计数是否被利用?

c# - 来自 Azure Application Insights Analytics API 的页面结果

java - 如何在 Azure 中聚合 Java 应用程序生成的日志?

azure - 从应用程序洞察中删除跟踪

azure - 使用 Azure Function V2 Durable 函数时,ILogger 不会记录到 Application Insights

java - 无法将应用程序见解裸 API 添加到 Java Web 应用程序

Azure 批量应用程序洞察

azure - 无法使简单的 AppInsights Hello World 工作

azure - 从 Azure 门户删除未使用的 Application Insights 资源是否安全?