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] New Fetch keepAlive support can cause duplicate events to be sent during unload processing #1736

Closed
MSNev opened this issue Dec 10, 2021 · 4 comments
Assignees
Milestone

Comments

@MSNev
Copy link
Collaborator

MSNev commented Dec 10, 2021

When a browser supports fetch with keepAlive and this is used during page unload, if the page completes page navigation before the response can be processed any sent events will be sent on the next page load.

As a workaround you can disable the fetch keepalive support with the following config

onunloadDisableFetch: true

@MSNev
Copy link
Collaborator Author

MSNev commented Dec 10, 2021

This fix for this will be that when sending a fetch (with keepalive) enabled the code will need to "assume" this as a fire and forget operation (like it does for sendBeacon()) -- this does mean however, that if a partial response is received (generally unlikely) that events may be lost vs the current situation which causes event duplication.

@MSNev MSNev self-assigned this Dec 10, 2021
@MSNev MSNev added this to the 2.x.x (Next Release) milestone Dec 10, 2021
@harleyz
Copy link

harleyz commented Dec 23, 2021

Recently I noticed the duplicate event issue for myself with using the unload event from JS. I set onunloadDisableFetch flag to true and it is resolved the duplicate events. I didn't see this on our angular apps, even though we use a similar approach.

Putting a comment here to follow the issue

\\ code without the flag set that was creating dups

cfg: { // Application Insights Configuration
                    instrumentationKey: '@System.Configuration.ConfigurationManager.AppSettings["ApplicationInsightsInstrumentationKey"]',
                    disableFetchTracking: false,
                    disableCorrelationHeaders: false,
                    enableCorsCorrelation: true,
                    correlationHeaderExcludedDomains: ['google-analytics.com','stats.g.doubleclick.net'],
                }
// unload handler
    var handleUnload = function () {
        $(window).on("beforeunload", function () {
            if (!isSessionComplete) {
                var _properties;
                if (IdleTimeout.getIdleCount() > 0) {
                    var _properties = { "idleCount": IdleTimeout.getIdleCount() };
                }
                stopTrackEvent("quoteTimeToRun", _properties);
            }
            return undefined;
        });
    };   

MSNev added a commit that referenced this issue Jan 11, 2022
MSNev added a commit that referenced this issue Jan 12, 2022
MSNev added a commit that referenced this issue Jan 12, 2022
MSNev added a commit that referenced this issue Jan 13, 2022
@MSNev MSNev added the fixed - waiting release PR Committed and waiting deployment label Jan 13, 2022
@MSNev
Copy link
Collaborator Author

MSNev commented Feb 3, 2022

Deploying to final CDN endpoint

@MSNev MSNev closed this as completed Feb 3, 2022
@github-actions
Copy link

github-actions bot commented Feb 4, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants