microsoft / microsoft/ApplicationInsights-JS

[BUG] ClickAnalyticsPlugin: Result of callback.contentName is ignored when element contains id or data-id attribute

Open
#2,346 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
685
Forks
261
Avg merge
21h 33m
Merged PRs (30d)
5

Description

Description/Screenshot

If element contains id or data-id attribute, result of contentName callback is ignored

Example:

const clickPluginConfig = {
  autoCapture: true,
  callback: {
      contentName: (element: HTMLElement) => {
        return 'this-is-test'
      },
  },
  dataTags: {
    useDefaultContentNameOrId: false,
  }
};

<button data-id="test6id">Test6</button>

will send name: "test6id"

Steps to Reproduce

Environment

  • OS/Browser: Edge
  • SDK Version [e.g. 22]: @microsoft/applicationinsights-clickanalytics-js: 3.2.0
  • How you initialized the SDK: npm

Expected behavior

I expect that the result of contentName callback will be used.

Additional context

This issue can be overcome by changing the data-id or id attribute inside the contentName callback, but it is not always feasible

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ClickAnalyticsPlugin in @microsoft/applicationinsights-clickanalytics-js and reproduce the behavior using the linked CodePen. Trace how the contentName callback result is handled when the element has id or data-id attributes. Done means the callback result is sent as the content name in this case, with a regression test covering the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
analytics, observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.