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

Tracking fails if a page is leaved #371

Open
ghost opened this issue Mar 14, 2021 · 4 comments
Open

Tracking fails if a page is leaved #371

ghost opened this issue Mar 14, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Mar 14, 2021

Looks like amplitude.logEvent crashes if it's followed by window.location.raplace, consider example:

...
amplitude.getInstance().init(amplitudeApiKey);
Vue.prototype.$amplitude = amplitude;
...
navigateAfterLogin() {
    this.$amplitude.getInstance().logEvent('Login passed');
    setTimeout(() => {
        this.$amplitude.getInstance().logEvent('test tracking crash');
        window.location.replace(this.nextPage);
     }, 1000);
},

I have tried to call this.$amplitude.getInstance().sendEvents() on page startup but nothing happens, so I guess LocalStorage contains no events.

Expected Behavior

Both events are successfully uploaded

Current Behavior

Second logEvent crashed.
image

Environment

"amplitude-js": "^7.4.4"
Chrome Version 89.0.4389.82 (Official Build) (x86_64)

@ghost ghost added the bug Something isn't working label Mar 14, 2021
@ghost ghost changed the title Tracking fails if page is leaved Tracking fails if a page is leaved Mar 15, 2021
@ghost
Copy link
Author

ghost commented Mar 15, 2021

Seems to be related to #136

@kelvin-lu
Copy link
Contributor

Thanks @ViktorDanyliuk for reporting this, we'll take a look!

@kelvin-lu
Copy link
Contributor

@ViktorDanyliuk I think your issue looks pretty related to page changes. We'll discuss more internally about how to build the sendBeacon API into our SDK.

For the second issue (sendEvents not working after page load) - potential culprits might be the JS SDK not loading fully w/events before trying to send, or an issue with our logic using sendEvents publicly - we can investigate this separately.

@POD666
Copy link

POD666 commented Mar 22, 2021

I followed https://github.com/amplitude/GTM-Web-Demo, with GTM in the middle it sends events when the next page is loaded.

I would like to avoid canceled requests but it's not critical anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants