Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Click analytics plug in sends same click event multiple times to Application Insight #2354

Open
abdjyg opened this issue May 27, 2024 · 5 comments

Comments

@abdjyg
Copy link

abdjyg commented May 27, 2024

Description/Screenshot
We have deployed App insight JS SDK to our Intranet application. It's a SharePoint hub site and multiple sites are associated to this hub site. We have added click analytics plug in to the SDK to track all click events especially to track if a user likes or comments a SharePoint page. But sometimes if we open a site page from news/announcement webparts and click like or comment button, it sends this data multiple times. So that it creates duplicate rows in App Insight customevents logs.

Steps to Reproduce

OS/Browser: Windows/ edge or Chrome
SDK Version [e.g. 22]:
How you initialized the SDK:
Expected behavior

Additional context
Add any other context about the problem here.

@MSNev
Copy link
Collaborator

MSNev commented May 28, 2024

This normally occurs because there are multiple SDK instances that have been loaded / initialized, each time the SDK is initialized it registers the event handles (the click, mouse down event for the click analytics) in this case.

Can you please check that this sequence is not occurring, as I suspect this is the root cause.

@abdjyg
Copy link
Author

abdjyg commented May 29, 2024

The issue occurs when another site page is opened from a site's news web part. Does this mean that the SDK in both sites gets initialized multiple times? If so, how can we resolve this issue?

@MSNev
Copy link
Collaborator

MSNev commented May 29, 2024

The issue occurs when another site page is opened from a site's news web part. Does this mean that the SDK in both sites gets initialized multiple times? If so, how can we resolve this issue?

That does sounds like both are loading their own instance. I've not done any sharepoint development / configuration, but the high level options as I see it would be either (and I may be misrepresenting the sharepoint names because I don't know the environment)

  • If one webpart is always a child, then it shouldn't be loading the click analytics -- maybe it doesn't even need to include the AI SDK at all.
  • If you can run a script on the page before dropping on the SDK Loader / initializing the SDK then you could check some "global" value for the presence of your SDK instance (ie. don't necessarily rely on the window.appInsights (just in case someone else has loaded it).
    • I believe that SharePoint is also using our internal extension (called oneDs) which extends the ApplicationInsights code , so checking for the global presence of the "classes" would also not be recommended.
  • If there is some master "layout" template (thingy) then only add the SDK to that (assumes that it's used for everything).

@abdjyg
Copy link
Author

abdjyg commented May 30, 2024

The issue occurs when another site page is opened from a site's news web part. Does this mean that the SDK in both sites gets initialized multiple times? If so, how can we resolve this issue?

That does sounds like both are loading their own instance. I've not done any sharepoint development / configuration, but the high level options as I see it would be either (and I may be misrepresenting the sharepoint names because I don't know the environment)

  • If one webpart is always a child, then it shouldn't be loading the click analytics -- maybe it doesn't even need to include the AI SDK at all.

  • If you can run a script on the page before dropping on the SDK Loader / initializing the SDK then you could check some "global" value for the presence of your SDK instance (ie. don't necessarily rely on the window.appInsights (just in case someone else has loaded it).

    • I believe that SharePoint is also using our internal extension (called oneDs) which extends the ApplicationInsights code , so checking for the global presence of the "classes" would also not be recommended.
  • If there is some master "layout" template (thingy) then only add the SDK to that (assumes that it's used for everything).

This is an SPFx extension which is deployed to the hub site and all associated sites.

@mrequenes
Copy link

mrequenes commented Jul 2, 2024

I'm seeing something similar. Not with click analytics, but with custom events (trackEvent). Not ALL events are getting duplicated, just an event that gets tracked immediately before opening a new tab. I'm 99% sure we're not calling trackEvent twice.

The events are perfect dupes-- no difference in any fields.

A workaround that works so far is to use window.setTimeout to call trackEvent after a short delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants